• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tosca_translator.TOSCATranslator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中translator.hot.tosca_translator.TOSCATranslator的典型用法代码示例。如果您正苦于以下问题:Python TOSCATranslator类的具体用法?Python TOSCATranslator怎么用?Python TOSCATranslator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TOSCATranslator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_translate_storage_notation1

    def test_translate_storage_notation1(self):
        '''TOSCA template with single BlockStorage and Attachment.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/storage/"
            "tosca_blockstorage_with_attachment_notation1.yaml")

        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        expected_resource_1 = {'type': 'OS::Cinder::VolumeAttachment',
                               'properties':
                               {'instance_uuid': 'my_web_app_tier_1',
                                'location': '/default_location',
                                'volume_id': 'my_storage'}}
        expected_resource_2 = {'type': 'OS::Cinder::VolumeAttachment',
                               'properties':
                               {'instance_uuid': 'my_web_app_tier_2',
                                'location': '/some_other_data_location',
                                'volume_id': 'my_storage'}}

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)

        resources = output_dict.get('resources')
        self.assertIn('myattachto_1', resources.keys())
        self.assertIn('myattachto_2', resources.keys())
        self.assertIn(expected_resource_1, resources.values())
        self.assertIn(expected_resource_2, resources.values())
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:29,代码来源:test_blockstorage.py


示例2: test_translate_server_existing_network

    def test_translate_server_existing_network(self):
        '''TOSCA template with 1 server attached to existing network.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/network/"
            "tosca_server_on_existing_network.yaml")

        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        expected_resource_1 = {'type': 'OS::Neutron::Port',
                               'properties':
                               {'network': {'get_param': 'network_name'}
                                }}

        expected_resource_2 = [{'port': {'get_resource': 'my_port'}}]

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)

        resources = output_dict.get('resources')

        self.assertItemsEqual(resources.keys(), ['my_server', 'my_port'])

        self.assertEqual(resources.get('my_port'), expected_resource_1)

        self.assertIn('properties', resources.get('my_server'))
        self.assertIn('networks', resources.get('my_server').get('properties'))
        translated_resource = resources.get('my_server').\
            get('properties').get('networks')
        self.assertEqual(translated_resource, expected_resource_2)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:31,代码来源:test_network.py


示例3: compare_tosca_translation_with_hot

    def compare_tosca_translation_with_hot(tosca_file, hot_file, params):
        """Verify tosca translation against the given hot specification.

        inputs:
        tosca_file: relative local path or URL to the tosca input file
        hot_file: relative path to expected hot output
        params: dictionary of parameter name value pairs

        Returns as a dictionary the difference between the HOT translation
        of the given tosca_file and the given hot_file.
        """

        from toscaparser.tosca_template import ToscaTemplate
        from translator.hot.tosca_translator import TOSCATranslator

        tosca_tpl = os.path.join(os.path.dirname(os.path.abspath(__file__)), tosca_file)
        a_file = os.path.isfile(tosca_tpl)
        if not a_file:
            tosca_tpl = tosca_file

        expected_hot_tpl = os.path.join(os.path.dirname(os.path.abspath(__file__)), hot_file)

        tosca = ToscaTemplate(tosca_tpl, params, a_file)
        translate = TOSCATranslator(tosca, params)

        output = translate.translate()
        output_dict = toscaparser.utils.yamlparser.simple_parse(output)
        expected_output_dict = YamlUtils.get_dict(expected_hot_tpl)
        return CompareUtils.diff_dicts(output_dict, expected_output_dict)
开发者ID:obulpathi,项目名称:cloud-translator,代码行数:29,代码来源:utils.py


示例4: take_action

    def take_action(self, parsed_args):
        log.debug(_('Translating the template with input parameters'
                    '(%s).'), parsed_args)
        output = None

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                validate = parsed_args.validate_only
                if validate and validate.lower() == "true":
                    ToscaTemplate(path, parsed_params, a_file)
                else:
                    tosca = ToscaTemplate(path, parsed_params, a_file)
                    translator = TOSCATranslator(tosca, parsed_params)
                    output = translator.translate()
            else:
                msg = _('Could not find template file.')
                log.error(msg)
                sys.stdout.write(msg)
                raise SystemExit

        if output:
            if parsed_args.output_file:
                with open(parsed_args.output_file, 'w+') as f:
                    f.write(output)
            else:
                print(output)
开发者ID:neogoku,项目名称:nfv_api,代码行数:34,代码来源:translate.py


示例5: test_translate_multi_storage

    def test_translate_multi_storage(self):
        '''TOSCA template with multiple BlockStorage and Attachment.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/storage/"
            "tosca_multiple_blockstorage_with_attachment.yaml")
        tosca = ToscaTemplate(tosca_tpl)
        translated_volume_attachment = []
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        expected_resource_1 = {'type': 'OS::Cinder::VolumeAttachment',
                               'properties':
                               {'instance_uuid': 'my_server',
                                'location': {'get_param': 'storage_location'},
                                'volume_id': 'my_storage'}}

        expected_resource_2 = {'type': 'OS::Cinder::VolumeAttachment',
                               'properties':
                               {'instance_uuid': 'my_server2',
                                'location': {'get_param': 'storage_location'},
                                'volume_id': 'my_storage2'}}

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
        resources = output_dict.get('resources')
        translated_volume_attachment.append(resources.get('attachesto_1'))
        translated_volume_attachment.append(resources.get('attachesto_2'))
        self.assertIn(expected_resource_1, translated_volume_attachment)
        self.assertIn(expected_resource_2, translated_volume_attachment)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:29,代码来源:test_blockstorage.py


示例6: _translate

 def _translate(self, sourcetype, path, parsed_params, a_file):
     output = None
     if sourcetype == "tosca":
         tosca = ToscaTemplate(path, parsed_params, a_file)
         translator = TOSCATranslator(tosca, parsed_params)
         output = translator.translate()
     return output
开发者ID:AleptNamrata,项目名称:murano,代码行数:7,代码来源:csar_package.py


示例7: test_translate_single_storage

    def test_translate_single_storage(self):
        '''TOSCA template with single BlockStorage and Attachment.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/storage/"
            "tosca_blockstorage_with_attachment.yaml")
        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        expected_resouce = {'attachesto_1':
                            {'type': 'OS::Cinder::VolumeAttachment',
                             'properties':
                             {'instance_uuid': 'my_server',
                              'location': {'get_param': 'storage_location'},
                              'volume_id': 'my_storage'}}}

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)
        resources = output_dict.get('resources')
        translated_value = resources.get('attachesto_1')
        expected_value = expected_resouce.get('attachesto_1')
        self.assertEqual(translated_value, expected_value)

        outputs = output_dict['outputs']
        self.assertIn('private_ip', outputs)
        self.assertEqual(
            'Private IP address of the newly created compute instance.',
            outputs['private_ip']['description'])
        self.assertEqual({'get_attr': ['my_server', 'networks', 'private', 0]},
                         outputs['private_ip']['value'])
        self.assertIn('volume_id', outputs)
        self.assertEqual('The volume id of the block storage instance.',
                         outputs['volume_id']['description'])
        self.assertEqual({'get_resource': 'my_storage'},
                         outputs['volume_id']['value'])
开发者ID:hurf,项目名称:heat-translator,代码行数:35,代码来源:test_blockstorage.py


示例8: test_translate_output

    def test_translate_output(self):
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../../toscalib/tests/data/"
            "tosca_nodejs_mongodb_two_instances.yaml")
        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, [])
        hot_translation = translate.translate()

        expected_output = {'nodejs_url':
                           {'description': 'URL for the nodejs '
                            'server, http://<IP>:3000',
                            'value':
                            {'get_attr':
                             ['app_server', 'networks', 'private', 0]}},
                           'mongodb_url':
                           {'description': 'URL for the mongodb server.',
                            'value':
                            {'get_attr':
                             ['mongo_server', 'networks', 'private', 0]}}}

        hot_translation_dict = \
            translator.toscalib.utils.yamlparser.simple_parse(hot_translation)

        outputs = hot_translation_dict.get('outputs')
        for resource_name in outputs:
            translated_value = outputs.get(resource_name)
            expected_value = expected_output.get(resource_name)
            self.assertEqual(translated_value, expected_value)
开发者ID:hurf,项目名称:heat-translator,代码行数:29,代码来源:test_translate_outputs.py


示例9: generate_hot_from_tosca

        def generate_hot_from_tosca(vnfd_dict):
            parsed_params = dev_attrs.pop('param_values', {})

            toscautils.updateimports(vnfd_dict)

            try:
                tosca = ToscaTemplate(parsed_params=parsed_params,
                                      a_file=False,
                                      yaml_dict_tpl=vnfd_dict)

            except Exception as e:
                LOG.debug("tosca-parser error: %s", str(e))
                raise vnfm.ToscaParserFailed(error_msg_details=str(e))

            monitoring_dict = toscautils.get_vdu_monitoring(tosca)
            mgmt_ports = toscautils.get_mgmt_ports(tosca)
            res_tpl = toscautils.get_resources_dict(tosca,
                                                    STACK_FLAVOR_EXTRA)
            toscautils.post_process_template(tosca)
            try:
                translator = TOSCATranslator(tosca, parsed_params)
                heat_template_yaml = translator.translate()
            except Exception as e:
                LOG.debug("heat-translator error: %s", str(e))
                raise vnfm.HeatTranslatorFailed(error_msg_details=str(e))
            heat_template_yaml = toscautils.post_process_heat_template(
                heat_template_yaml, mgmt_ports, res_tpl,
                unsupported_res_prop)

            return heat_template_yaml, monitoring_dict
开发者ID:s3wong,项目名称:tacker,代码行数:30,代码来源:heat.py


示例10: take_action

    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                tosca = ToscaTemplate(path, parsed_params, a_file)
                translator = TOSCATranslator(tosca, parsed_params)
                output = translator.translate()
            else:
                sys.stdout.write('Could not find template file.')
                raise SystemExit

        if parsed_args.output_file:
            with open(parsed_args.output_file, 'w+') as f:
                f.write(output)
        else:
            print(output)
开发者ID:obulpathi,项目名称:cloud-translator,代码行数:25,代码来源:translate.py


示例11: _translate

 def _translate(self, sourcetype, path, parsed_params, a_file):
     output = None
     if sourcetype == "tosca":
         log.debug(_('Loading the tosca template.'))
         tosca = ToscaTemplate(path, parsed_params, a_file)
         translator = TOSCATranslator(tosca, parsed_params, self.deploy)
         log.debug(_('Translating the tosca template.'))
         output = translator.translate()
     return output
开发者ID:chthong,项目名称:heat-translator,代码行数:9,代码来源:shell.py


示例12: test_translate_three_networks_single_server

    def test_translate_three_networks_single_server(self):
        '''TOSCA template with three Networks and single Compute.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/network/"
            "tosca_one_server_three_networks.yaml")

        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)

        resources = output_dict.get('resources')

        for net_num in range(1, 4):
            net_name = 'my_network%d' % (net_num)
            subnet_name = '%s_subnet' % (net_name)
            port_name = 'my_port%d' % (net_num)

            expected_resource_net = {'type': 'OS::Neutron::Net',
                                     'properties':
                                     {'name': 'net%d' % (net_num)
                                      }}

            expected_resource_subnet = {'type': 'OS::Neutron::Subnet',
                                        'properties':
                                       {'cidr': '192.168.%d.0/24' % (net_num),
                                        'ip_version': 4,
                                        'network': {'get_resource': net_name}
                                        }}

            expected_resource_port = {'type': 'OS::Neutron::Port',
                                      'depends_on': [net_name],
                                      'properties':
                                      {'network': {'get_resource': net_name}
                                       }}
            self.assertIn(net_name, resources.keys())
            self.assertIn(subnet_name, resources.keys())
            self.assertIn(port_name, resources.keys())

            self.assertEqual(resources.get(net_name), expected_resource_net)
            self.assertEqual(resources.get(subnet_name),
                             expected_resource_subnet)
            self.assertEqual(resources.get(port_name), expected_resource_port)

        self.assertIn('properties', resources.get('my_server'))
        self.assertIn('networks', resources.get('my_server').get('properties'))
        translated_resource = resources.get('my_server').\
            get('properties').get('networks')

        expected_srv_networks = [{'port': {'get_resource': 'my_port1'}},
                                 {'port': {'get_resource': 'my_port2'}},
                                 {'port': {'get_resource': 'my_port3'}}]
        self.assertEqual(translated_resource, expected_srv_networks)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:55,代码来源:test_network.py


示例13: test_post_process_heat_template

    def test_post_process_heat_template(self):
        tosca1 = ToscaTemplate(parsed_params={}, a_file=False, yaml_dict_tpl=self.vnfd_dict)
        toscautils.post_process_template(tosca1)
        translator = TOSCATranslator(tosca1, {})
        heat_template_yaml = translator.translate()
        expected_heat_tpl = _get_template("hot_tosca_openwrt.yaml")
        mgmt_ports = toscautils.get_mgmt_ports(self.tosca)
        heat_tpl = toscautils.post_process_heat_template(heat_template_yaml, mgmt_ports, {}, {})

        heatdict = yaml.load(heat_tpl)
        expecteddict = yaml.load(expected_heat_tpl)
        self.assertEqual(heatdict, expecteddict)
开发者ID:trozet,项目名称:tacker,代码行数:12,代码来源:test_toscautils.py


示例14: test_translate_single_network_single_server

    def test_translate_single_network_single_server(self):
        '''TOSCA template with single Network and single Compute.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/network/"
            "tosca_one_server_one_network.yaml")

        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        expected_resource_1 = {'type': 'OS::Neutron::Net',
                               'properties':
                               {'name': {'get_param': 'network_name'}
                                }}

        expected_resource_2 = {'type': 'OS::Neutron::Subnet',
                               'properties':
                               {'cidr': '192.168.0.0/24',
                                'ip_version': 4,
                                'allocation_pools': [{'start': '192.168.0.50',
                                                     'end': '192.168.0.200'}],
                                'gateway_ip': '192.168.0.1',
                                'network': {'get_resource': 'my_network'}
                                }}

        expected_resource_3 = {'type': 'OS::Neutron::Port',
                               'depends_on': ['my_network'],
                               'properties':
                               {'network': {'get_resource': 'my_network'}
                                }}

        expected_resource_4 = [{'port': {'get_resource': 'my_port'}}]

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)

        resources = output_dict.get('resources')

        self.assertIn('my_network', resources.keys())
        self.assertIn('my_network_subnet', resources.keys())
        self.assertIn('my_port', resources.keys())
        self.assertIn('my_server', resources.keys())

        self.assertEqual(resources.get('my_network'), expected_resource_1)
        self.assertEqual(resources.get('my_network_subnet'),
                         expected_resource_2)
        self.assertEqual(resources.get('my_port'), expected_resource_3)

        self.assertIn('properties', resources.get('my_server'))
        self.assertIn('networks', resources.get('my_server').get('properties'))
        translated_resource = resources.get('my_server').\
            get('properties').get('networks')
        self.assertEqual(translated_resource, expected_resource_4)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:53,代码来源:test_network.py


示例15: take_action

    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        if not os.path.isfile(parsed_args.template_file):
            sys.stdout.write('Could not find template file.')
            raise SystemExit

        # TODO(stevemar): parsed_params doesn't default nicely
        parsed_params = {}
        if parsed_args.template_type == "tosca":
            tosca = ToscaTemplate(parsed_args.template_file)
            translator = TOSCATranslator(tosca, parsed_params)
            output = translator.translate()

        if parsed_args.output_file:
            with open(parsed_args.output_file, 'w+') as f:
                f.write(output)
        else:
            print(output)
开发者ID:ckauf,项目名称:heat-translator,代码行数:19,代码来源:translate.py


示例16: take_action

    def take_action(self, parsed_args):
        LOG.debug(_('Translating the template with input parameters'
                    '(%s).'), parsed_args)
        output = None

        session = self.app.cloud.get_session()
        flavors.SESSION = session
        images.SESSION = session

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                validate = parsed_args.validate_only
                if validate and validate.lower() == "true":
                    ToscaTemplate(path, parsed_params, a_file)
                    msg = (_('The input "%(path)s" successfully passed '
                             'validation.') % {'path': path})
                    print(msg)
                else:
                    tosca = ToscaTemplate(path, parsed_params, a_file)
                    translator = TOSCATranslator(tosca, parsed_params)
                    output = translator.translate()
            else:
                msg = _('Could not find template file.\n')
                LOG.error(msg)
                sys.stdout.write(msg)
                raise SystemExit

        if output:
            if parsed_args.output_file:
                with open(parsed_args.output_file, 'w+') as f:
                    f.write(output)
            else:
                print(output)
开发者ID:openstack,项目名称:heat-translator,代码行数:41,代码来源:translate.py


示例17: test_translate_output_order

    def test_translate_output_order(self):
        tosca_yaml_file = "data/tosca_single_server.yaml"
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            tosca_yaml_file)
        parsed_params = {'cpus': 2}
        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, parsed_params)
        hot_translated_output = translate.translate()

        #load expected hot yaml file
        hot_yaml_file = "data/hot_output/hot_single_server.yaml"
        hot_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            hot_yaml_file)
        with open(hot_tpl) as f:
            hot_expected_output = f.read()

        #compare generated and expected hot templates
        status = CompareUtils.compare_hot_yamls(hot_translated_output,
                                                hot_expected_output)
        self.assertEqual(status, True)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:22,代码来源:test_translated_output_order.py


示例18: test_single_template_objectstore

    def test_single_template_objectstore(self):
        tosca_yaml_file = "../toscalib/tests/data/storage/" + \
            "tosca_single_object_store.yaml"
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            tosca_yaml_file)
        parsed_params = {'objectstore_name': 'test_obj_store'}
        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, parsed_params)
        hot_translated_output = translate.translate()

        #load expected hot yaml file
        hot_yaml_file = "../toscalib/tests/data/hot_output/" + \
            "hot_single_object_store.yaml"
        hot_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            hot_yaml_file)
        with open(hot_tpl) as f:
            hot_expected_output = f.read()

        #compare generated and expected hot templates
        status = CompareUtils.compare_hot_yamls(hot_translated_output,
                                                hot_expected_output)
        self.assertEqual(status, True)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:24,代码来源:test_objectstore_template.py


示例19: test_translate_storage_notation2

    def test_translate_storage_notation2(self):
        '''TOSCA template with single BlockStorage and Attachment.'''
        tosca_tpl = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            "../toscalib/tests/data/storage/"
            "tosca_blockstorage_with_attachment_notation2.yaml")

        tosca = ToscaTemplate(tosca_tpl)
        translate = TOSCATranslator(tosca, self.parsed_params)
        output = translate.translate()

        expected_resource_1 = {'type': 'OS::Cinder::VolumeAttachment',
                               'properties':
                               {'instance_uuid': 'my_web_app_tier_1',
                                'location': '/my_data_location',
                                'volume_id': 'my_storage'}}
        expected_resource_2 = {'type': 'OS::Cinder::VolumeAttachment',
                               'properties':
                               {'instance_uuid': 'my_web_app_tier_2',
                                'location': '/some_other_data_location',
                                'volume_id': 'my_storage'}}

        output_dict = translator.toscalib.utils.yamlparser.simple_parse(output)

        resources = output_dict.get('resources')
        # Resource name suffix depends on nodetemplates order in dict, which is
        # not certain. So we have two possibilities of resources name.
        if resources.get('storage_attachesto_1_1'):
            self.assertIn('storage_attachesto_1_1', resources.keys())
            self.assertIn('storage_attachesto_2_2', resources.keys())
        else:
            self.assertIn('storage_attachesto_1_2', resources.keys())
            self.assertIn('storage_attachesto_2_1', resources.keys())

        self.assertIn(expected_resource_1, resources.values())
        self.assertIn(expected_resource_2, resources.values())
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:36,代码来源:test_blockstorage.py


示例20: translate

def translate():
    try:
        status_msg = None
        hot_output_string = None
        temp_dir = None
        full_filename = None
        params = ''

        # TODO: look at moving to a decorator
        trace(REQUEST_SEPARATOR)
        trace("request.method: " + request.method)
        trace("request.headers['Content-Type']:" +
              request.headers[HTTP_REQUEST_KEY_CONTENT_TYPE])

        # debug the request object
        # debug.dump(request.__dict__, 1, "Request")

        if request.method == 'POST':

            # Retrieve reference to the file to transcode
            fileinfo = request.files[FLASK_KEY_REQUEST_FILE]
            # debug.dump(fileinfo.__dict__, 1, "File Info")

            # create request-unique subdirectory to store YAML template / CSAR
            temp_dir = create_dir(app.config[FLASK_KEY_UPLOAD_FOLDER])
            full_filename = save_tosca_file(fileinfo, temp_dir)

            if full_filename and is_tosca_filetype(full_filename):
                # TODO: See if we can return a ZIP with HOT and artifacts
                # IF CSAR package unzip it for processing
                # if(is_csar(full_filename)):
                #     trace("Unzipping TOSCA CSAR archive file...")
                #     csar.unzip_csar(request, full_filename, temp_dir)
                # else:
                #     trace("Standalone TOSCA template file detected...")

                # TODO: "sniff" for TOSCA header in template file (for
                # standalone YAML) or the "entry-defintion" template
                # identified in tbe manifest of the CSAR

                # retrieve and validate form data
                form = request.form
                # debug.dump_form(request, 1):

                # Get --parameters from FORM data
                trace("retrieving parameters...")
                if 'parameters' in form:
                    params = form['parameters']
                    # trace("request.form['parameters']: [" + params + "]")
                params = parse_parameters(params)

                try:
                    # Parse the TOSCA template
                    trace("Parsing TOSCA template... [" + full_filename + "]")
                    tosca_template = ToscaTemplate(full_filename, params)

                    # Translate the TOSCA template/package to HOT
                    trace("Translating to Heat template...")
                    translator = TOSCATranslator(tosca_template, params)
                    hot_output_string = translator.translate()
                except Exception, e:
                    raise e

            else:
                # TODO: Show error message to indicate valid file types
                status_msg = "Invalid file ot filetype: file type not saved"

            # Optionally, save translated output
            if not PRODUCTION and OUTPUT_TO_FILE:
                trace("Saving translated output...")
                save_translated_file(fileinfo, "hot", "outputs",
                                     hot_output_string)

            # Add HOT output to the response and set its content type
            # to text/plain to avoid it being intpreted as HTML
            trace("Returning Heat template...")
            debug.dumpif(DEBUG, hot_output_string, 0, "HOT")
            response = app.make_response(hot_output_string)
            response.headers[HTTP_REQUEST_KEY_CONTENT_TYPE] = \
                RESPONSE_CONTENT_TYPE
            return response

        else:
开发者ID:MFALHI,项目名称:tosca-translator,代码行数:83,代码来源:server.py



注:本文中的translator.hot.tosca_translator.TOSCATranslator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gettextutils._函数代码示例发布时间:2022-05-27
下一篇:
Python utils.TranslationUtils类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap