X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwnsm%2Frift%2Ftasklets%2Frwnsmtasklet%2Fopenmano_nsm.py;h=bdd5b321058d1681165c9739b3521afb583e9772;hb=4e6cebcf2f15e9c9370d5af6b725629a70ac9b1a;hp=17a13a390dfa1f417972b4468603c315dd1a6303;hpb=699e14141627d8f8fd30abc07c87c1e081215762;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py index 17a13a39..bdd5b321 100644 --- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py +++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/openmano_nsm.py @@ -1,5 +1,5 @@ -# +# # Copyright 2016 RIFT.IO Inc # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -129,7 +129,7 @@ class VnfrConsoleOperdataDtsHandler(object): vdur_console = RwVnfrYang.YangData_RwVnfr_VnfrConsole_Vnfr_Vdur() vdur_console.id = self._vdur_id vdur_console.console_url = 'none' - + xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK, xpath=self.vnfr_vdu_console_xpath, msg=vdur_console) @@ -137,7 +137,7 @@ class VnfrConsoleOperdataDtsHandler(object): #raise VnfRecordError("Not supported operation %s" % action) self._log.error("Not supported operation %s" % action) xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK) - return + return self._log.debug("Registering for VNFR VDU using xpath: %s", self.vnfr_vdu_console_xpath) @@ -239,9 +239,9 @@ class OpenmanoVnfr(object): class OpenmanoNsr(object): - TIMEOUT_SECS = 120 + TIMEOUT_SECS = 300 - def __init__(self, dts, log, loop, publisher, cli_api, http_api, nsd_msg, nsr_config_msg): + def __init__(self, dts, log, loop, publisher, cli_api, http_api, nsd_msg, nsr_config_msg,key_pairs): self._dts = dts self._log = log self._loop = loop @@ -255,6 +255,7 @@ class OpenmanoNsr(object): self._vlrs = [] self._vnfrs = [] self._vdur_console_handler = {} + self._key_pairs = key_pairs self._nsd_uuid = None self._nsr_uuid = None @@ -287,6 +288,46 @@ class OpenmanoNsr(object): openmano_nsd = rift2openmano.rift2openmano_nsd(self.nsd, self.vnfds,self.vnfr_ids) return yaml.safe_dump(openmano_nsd, default_flow_style=False) + def get_ssh_key_pairs(self): + cloud_config = {} + key_pairs = list() + for authorized_key in self._nsr_config_msg.ssh_authorized_key: + self._log.debug("Key pair ref present is %s",authorized_key.key_pair_ref) + if authorized_key.key_pair_ref in self._key_pairs: + key_pairs.append(self._key_pairs[authorized_key.key_pair_ref].key) + + for authorized_key in self._nsd_msg.key_pair: + self._log.debug("Key pair NSD is %s",authorized_key) + key_pairs.append(authorized_key.key) + + if key_pairs: + cloud_config["key-pairs"] = key_pairs + + users = list() + for user_entry in self._nsr_config_msg.user: + self._log.debug("User present is %s",user_entry) + user = {} + user["name"] = user_entry.name + user["key-pairs"] = list() + for ssh_key in user_entry.key_pair: + user["key-pairs"].append(ssh_key.key) + users.append(user) + + for user_entry in self._nsd_msg.user: + self._log.debug("User present in NSD is %s",user_entry) + user = {} + user["name"] = user_entry.name + user["key-pairs"] = list() + for ssh_key in user_entry.key_pair: + user["key-pairs"].append(ssh_key.key) + users.append(user) + + if users: + cloud_config["users"] = users + + self._log.debug("Cloud config formed is %s",cloud_config) + return cloud_config + @property def openmano_instance_create_yaml(self): @@ -295,13 +336,17 @@ class OpenmanoNsr(object): openmano_instance_create["name"] = self._nsr_config_msg.name openmano_instance_create["description"] = self._nsr_config_msg.description openmano_instance_create["scenario"] = self._nsd_uuid + + cloud_config = self.get_ssh_key_pairs() + if cloud_config: + openmano_instance_create["cloud-config"] = cloud_config if self._nsr_config_msg.has_field("om_datacenter"): openmano_instance_create["datacenter"] = self._nsr_config_msg.om_datacenter openmano_instance_create["vnfs"] = {} for vnfr in self._vnfrs: if "om_datacenter" in vnfr.vnfr.vnfr_msg: vnfr_name = vnfr.vnfr.vnfd.name + "__" + str(vnfr.vnfr.vnfr_msg.member_vnf_index_ref) - openmano_instance_create["vnfs"][vnfr_name] = {"datacenter": vnfr.vnfr.vnfr_msg.om_datacenter} + openmano_instance_create["vnfs"][vnfr_name] = {"datacenter": vnfr.vnfr.vnfr_msg.om_datacenter} openmano_instance_create["networks"] = {} for vld_msg in self._nsd_msg.vld: openmano_instance_create["networks"][vld_msg.name] = {} @@ -326,7 +371,7 @@ class OpenmanoNsr(object): if ip_profile_params.has_field('gateway_address'): ip_profile['gateway-address'] = ip_profile_params.gateway_address if ip_profile_params.has_field('dns_server') and len(ip_profile_params.dns_server) > 0: - ip_profile['dns-address'] = ip_profile_params.dns_server[0] + ip_profile['dns-address'] = ip_profile_params.dns_server[0].address if ip_profile_params.has_field('dhcp_params'): ip_profile['dhcp'] = {} ip_profile['dhcp']['enabled'] = ip_profile_params.dhcp_params.enabled @@ -341,10 +386,11 @@ class OpenmanoNsr(object): elif "datacenter" in openmano_instance_create: network["datacenter"] = openmano_instance_create["datacenter"] if network: - openmano_instance_create["networks"][vld_msg.name]["sites"].append(network) + openmano_instance_create["networks"][vld_msg.name]["sites"].append(network) if ip_profile: - openmano_instance_create["networks"][vld_msg.name]['ip-profile'] = ip_profile - + openmano_instance_create["networks"][vld_msg.name]['ip-profile'] = ip_profile + + return yaml.safe_dump(openmano_instance_create, default_flow_style=False) @asyncio.coroutine @@ -550,11 +596,11 @@ class OpenmanoNsr(object): for vm in vnf_status["vms"]: if vm["uuid"] not in self._vdur_console_handler: - vdur_console_handler = VnfrConsoleOperdataDtsHandler(self._dts, self._log, self._loop, + vdur_console_handler = VnfrConsoleOperdataDtsHandler(self._dts, self._log, self._loop, self, vnfr_msg.id,vm["uuid"],vm["name"]) yield from vdur_console_handler.register() self._vdur_console_handler[vm["uuid"]] = vdur_console_handler - + vdur_msg = vnfr_msg.vdur.add() vdur_msg.vim_id = vm["vim_vm_id"] vdur_msg.id = vm["uuid"] @@ -624,7 +670,7 @@ class OpenmanoNsr(object): for _,handler in self._vdur_console_handler.items(): handler._regh.deregister() - + if self._nsr_uuid is None: self._log.warning("Cannot terminate an un-instantiated nsr") return @@ -673,7 +719,7 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase): ro_account.openmano.tenant_id, ) - def create_nsr(self, nsr_config_msg, nsd_msg): + def create_nsr(self, nsr_config_msg, nsd_msg, key_pairs=None): """ Create Network service record """ @@ -685,7 +731,8 @@ class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase): self._cli_api, self._http_api, nsd_msg, - nsr_config_msg + nsr_config_msg, + key_pairs ) self._openmano_nsrs[nsr_config_msg.id] = openmano_nsr