X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=common%2Fpython%2Frift%2Fmano%2Ftosca_translator%2Frwmano%2Ftosca%2Ftosca_compute.py;h=190a5b453c3fc56c108a77a3880d557926503c9d;hb=c2fe40c38153248d1a9f436241c65d5f43e5a900;hp=7bc0bf3b12060a00368de7040705e4f31207b196;hpb=bc183dcd09255cbe61afe64f8543824f2270634c;p=osm%2FSO.git diff --git a/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_compute.py b/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_compute.py index 7bc0bf3b..190a5b45 100755 --- a/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_compute.py +++ b/common/python/rift/mano/tosca_translator/rwmano/tosca/tosca_compute.py @@ -47,6 +47,16 @@ class ToscaCompute(ManoResource): 'float':'DECIMAL' } + + TOSCA_MEM_SIZE = { + 'huge': 'LARGE', + 'normal': 'SMALL', + 'size_2MB': 'SIZE_2MB', + 'size_1GB': 'SIZE_1GB', + 'prefer_huge': 'PREFER_LARGE' + + } + def __init__(self, log, nodetemplate, metadata=None): super(ToscaCompute, self).__init__(log, nodetemplate, @@ -62,6 +72,7 @@ class ToscaCompute(ManoResource): self._id = self.name self._monitor_param = [] self._mgmt_interface = {} + self._http_endpoint = None @property def image(self): @@ -90,12 +101,7 @@ class ToscaCompute(ManoResource): format(self.name, tosca_props)) vdu_props = {} for key, value in tosca_props.items(): - if key == 'cloud_init': - vdu_props['cloud-init'] = value - elif key == 'cloud-init-file': - self._cloud_init = "../cloud_init/{}".format(value) - else: - vdu_props[key] = value + vdu_props[key] = value if 'name' not in vdu_props: vdu_props['name'] = self.name @@ -207,11 +213,11 @@ class ToscaCompute(ManoResource): if 'type' in specs: hypervisor_epa['type'] = specs['type'].upper() if 'version' in specs: - hypervisor_epa['version'] = specs['version'] + hypervisor_epa['version'] = str(specs['version']) return hypervisor_epa - def get_guest_epa(specs): + def get_guest_epa(specs, nfv_comput_specs): guest_epa = {} guest_epa['numa-node-policy'] = {} guest_epa['numa-node-policy']['node'] = [] @@ -230,6 +236,11 @@ class ToscaCompute(ManoResource): else: err_msg = "Specify mem_size of NUMA extension should be in MB" raise ValidationError(message=err_msg) + if 'vcpus' in node: + vcpu_lis =[] + for vcpu in node['vcpus']: + vcpu_lis.append({'id': vcpu}) + node_prop['vcpu'] = vcpu_lis if 'om_numa_type' in node: numa_type = node['om_numa_type'] if 'paired-threads' == numa_type: @@ -245,6 +256,16 @@ class ToscaCompute(ManoResource): err_msg = "om_numa_type should be among cores, paired-threads or threads" raise ValidationError(message=err_msg) guest_epa['numa-node-policy']['node'].append(node_prop) + + if 'mem_page_size' in nfv_comput_specs: + guest_epa['mempage-size'] = self.TOSCA_MEM_SIZE[nfv_comput_specs['mem_page_size']] + if 'cpu_allocation' in nfv_comput_specs: + if 'cpu_affinity' in nfv_comput_specs['cpu_allocation']: + guest_epa['cpu-pinning-policy'] = nfv_comput_specs['cpu_allocation']['cpu_affinity'].upper() + guest_epa['trusted-execution'] = False + if 'thread_allocation' in nfv_comput_specs['cpu_allocation']: + guest_epa['cpu-thread-pinning-policy'] = nfv_comput_specs['cpu_allocation']['thread_allocation'].upper() + return guest_epa tosca_caps = self.get_tosca_caps() @@ -261,13 +282,34 @@ class ToscaCompute(ManoResource): if 'vswitch_epa' in tosca_caps: self.properties['vswitch-epa'] = get_vswitch_epa(tosca_caps['vswitch_epa']) if 'numa_extension' in tosca_caps: - self.properties['guest-epa'] = get_guest_epa(tosca_caps['numa_extension']) + self.properties['guest-epa'] = get_guest_epa(tosca_caps['numa_extension'], tosca_caps['nfv_compute']) if 'monitoring_param' in tosca_caps: self._monitor_param.append(get_monitor_param(tosca_caps['monitoring_param'], '1')) - if 'monitoring_param_1' in tosca_caps: - self._monitor_param.append(get_monitor_param(tosca_caps['monitoring_param_1'], '2')) if 'mgmt_interface' in tosca_caps: self._mgmt_interface = get_mgmt_interface(tosca_caps['mgmt_interface']) + if len(self._mgmt_interface) > 0: + prop = {} + if 'dashboard-params' in self._mgmt_interface: + if 'path' in self._mgmt_interface['dashboard-params']: + prop['path'] = self._mgmt_interface['dashboard-params']['path'] + if 'port' in self._mgmt_interface['dashboard-params']: + prop['port'] = self._mgmt_interface['dashboard-params']['port'] + self._http_endpoint = prop + + mon_idx = 2 + monitoring_param_name = 'monitoring_param_1' + while True: + if monitoring_param_name in tosca_caps: + self._monitor_param.append(get_monitor_param(tosca_caps[monitoring_param_name], str(mon_idx))) + mon_idx += 1 + monitoring_param_name = 'monitoring_param_{}'.format(mon_idx) + else: + break + + # THis is a quick hack to remove monitor params without name + for mon_param in list(self._monitor_param): + if 'name' not in mon_param: + self._monitor_param.remove(mon_param) def handle_artifacts(self): if self.artifacts is None: @@ -284,9 +326,11 @@ class ToscaCompute(ManoResource): prefix, type_ = value.rsplit('.', 1) if type_ == 'QCOW2': details['type'] = 'qcow2' + self._image = props['file'] self.properties['image'] = os.path.basename(props['file']) elif name == 'type' and value == 'tosca.artifacts.Deployment.riftio.cloud_init_file': details['cloud_init_file'] = os.path.basename(props['file']) + self._cloud_init = props['file'] self.properties['cloud_init_file'] = os.path.basename(props['file']) elif name == 'file': details['file'] = value @@ -305,8 +349,8 @@ class ToscaCompute(ManoResource): self.artifacts = arts def handle_interfaces(self): - # Currently, we support only create operation - operations_deploy_sequence = ['create'] + # Currently, we support the following: + operations_deploy_sequence = ['create', 'configure'] operations = ManoResource._get_all_operations(self.nodetemplate) @@ -319,12 +363,17 @@ class ToscaCompute(ManoResource): self.operations[operation.name] = operation.implementation for name, details in self.artifacts.items(): if name == operation.implementation: - self._image = details['file'] + if operation.name == 'create': + self._image = details['file'] + elif operation.name == 'configure': + self._cloud_init = details['file'] + break except KeyError as e: self.log.exception(e) return None def update_image_checksum(self, in_file): + # Create image checksum # in_file is the TOSCA yaml file location if self._image is None: @@ -373,6 +422,9 @@ class ToscaCompute(ManoResource): if self._image_cksum: self.properties['image-checksum'] = self._image_cksum + if self._cloud_init: + self.properties['cloud-init-file'] = os.path.basename(self._cloud_init) + for key in ToscaCompute.IGNORE_PROPS: if key in self.properties: self.properties.pop(key) @@ -389,6 +441,8 @@ class ToscaCompute(ManoResource): try: if len(self._mgmt_interface) > 0: vnfd.mgmt_interface.from_dict(convert_keys_to_python(self._mgmt_interface)) + if self._http_endpoint: + vnfd.http_endpoint.add().from_dict(convert_keys_to_python(self._http_endpoint)) vnfd.vdu.add().from_dict(props) except Exception as e: err_msg = _("{0} Exception vdu from dict {1}: {2}"). \