X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fns.py;h=193cab60876b52d5836947254d7f4d4ed58a912c;hb=c61e7813da16b2dc42d7ca4f625efe720096ab54;hp=d3acc581f8a0042853903145dc4bb0f9c75fbcec;hpb=da6fb108bb31d9ee12c1f0e5bb44936330cc99a7;p=osm%2FLCM.git diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index d3acc58..193cab6 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -114,6 +114,8 @@ class NsLcm(LcmBase): self.vca_config['public_key'] = self.vca_config['pubkey'] if 'cacert' in self.vca_config: self.vca_config['ca_cert'] = self.vca_config['cacert'] + if 'apiproxy' in self.vca_config: + self.vca_config['api_proxy'] = self.vca_config['apiproxy'] # create N2VC connector self.n2vc = N2VCJujuConnector( @@ -124,10 +126,9 @@ class NsLcm(LcmBase): url='{}:{}'.format(self.vca_config['host'], self.vca_config['port']), username=self.vca_config.get('user', None), vca_config=self.vca_config, - on_update_db=self._on_update_n2vc_db - # TODO - # New N2VC argument - # api_proxy=vca_config.get('apiproxy') + on_update_db=self._on_update_n2vc_db, + # ca_cert=self.vca_config.get('cacert'), + # api_proxy=self.vca_config.get('apiproxy'), ) self.k8sclusterhelm = K8sHelmConnector( @@ -867,12 +868,20 @@ class NsLcm(LcmBase): step = "Deployed at VIM" self.logger.debug(logging_text + step) - # wait for ip addres at RO, and optionally, insert public key in virtual machine - # returns IP address - async def insert_key_ro(self, logging_text, nsr_id, vnfr_id, vdu_id, vdu_index, pub_key=None, user=None): - - self.logger.debug(logging_text + "Starting insert_key_ro") + async def wait_vm_up_insert_key_ro(self, logging_text, nsr_id, vnfr_id, vdu_id, vdu_index, pub_key=None, user=None): + """ + Wait for ip addres at RO, and optionally, insert public key in virtual machine + :param logging_text: prefix use for logging + :param nsr_id: + :param vnfr_id: + :param vdu_id: + :param vdu_index: + :param pub_key: public ssh key to inject, None to skip + :param user: user to apply the public ssh key + :return: IP address + """ + # self.logger.debug(logging_text + "Starting wait_vm_up_insert_key_ro") ro_nsr_id = None ip_address = None nb_tries = 0 @@ -898,9 +907,9 @@ class NsLcm(LcmBase): for vdur in get_iterable(db_vnfr, "vdur"): if (vdur["vdu-id-ref"] == vdu_id and vdur["count-index"] == vdu_index) or \ (ip_address and vdur.get("ip-address") == ip_address): - if vdur["status"] == "ACTIVE": + if vdur.get("status") == "ACTIVE": target_vdu_id = vdur["vdu-id-ref"] - elif vdur["status"] == "ERROR": + elif vdur.get("status") == "ERROR": raise LcmException("Cannot inject ssh-key because target VM is in error state") break else: @@ -911,11 +920,11 @@ class NsLcm(LcmBase): if not target_vdu_id: continue - self.logger.debug(logging_text + "IP address={}".format(ip_address)) + # self.logger.debug(logging_text + "IP address={}".format(ip_address)) # inject public key into machine if pub_key and user: - self.logger.debug(logging_text + "Inserting RO key") + # self.logger.debug(logging_text + "Inserting RO key") try: ro_vm_id = "{}-{}".format(db_vnfr["member-vnf-index-ref"], target_vdu_id) # TODO add vdu_index result_dict = await self.RO.create_action( @@ -934,10 +943,12 @@ class NsLcm(LcmBase): result.get("description"))) break except ROclient.ROClientException as e: + if not nb_tries: + self.logger.debug(logging_text + "error injecting key: {}. Retrying until {} seconds". + format(e, 20*10)) nb_tries += 1 - if nb_tries >= 10: + if nb_tries >= 20: raise LcmException("Reaching max tries injecting key. Error: {}".format(e)) - self.logger.debug(logging_text + "error injecting key: {}".format(e)) else: break @@ -991,35 +1002,35 @@ class NsLcm(LcmBase): if is_proxy_charm: step = "create execution environment" self.logger.debug(logging_text + step) - ee_id, credentials = await self.n2vc.create_execution_environment( - namespace=namespace, - reuse_ee_id=ee_id, - db_dict=db_dict - ) - + ee_id, credentials = await self.n2vc.create_execution_environment(namespace=namespace, + reuse_ee_id=ee_id, + db_dict=db_dict) else: - step = "register execution environment" - # TODO wait until deployed by RO, when IP address has been filled. By pooling???? - credentials = {} # TODO db_credentials["ip_address"] + step = "Waiting to VM being up and getting IP address" + self.logger.debug(logging_text + step) + rw_mgmt_ip = await self.wait_vm_up_insert_key_ro(logging_text, nsr_id, vnfr_id, vdu_id, vdu_index, + user=None, pub_key=None) + credentials = {"hostname": rw_mgmt_ip} # get username + username = deep_get(config_descriptor, ("config-access", "ssh-access", "default-user")) # TODO remove this when changes on IM regarding config-access:ssh-access:default-user were # merged. Meanwhile let's get username from initial-config-primitive - if config_descriptor.get("initial-config-primitive"): - for param in config_descriptor["initial-config-primitive"][0].get("parameter", ()): - if param["name"] == "ssh-username": - credentials["username"] = param["value"] - if config_descriptor.get("config-access") and config_descriptor["config-access"].get("ssh-access"): - if config_descriptor["config-access"]["ssh-access"].get("required"): - credentials["username"] = \ - config_descriptor["config-access"]["ssh-access"].get("default-user") - + if not username and config_descriptor.get("initial-config-primitive"): + for config_primitive in config_descriptor["initial-config-primitive"]: + for param in config_primitive.get("parameter", ()): + if param["name"] == "ssh-username": + username = param["value"] + break + if not username: + raise LcmException("Cannot determine the username neither with 'initial-config-promitive' nor with " + "'config-access.ssh-access.default-user'") + credentials["username"] = username # n2vc_redesign STEP 3.2 + + step = "register execution environment {}".format(credentials) self.logger.debug(logging_text + step) - ee_id = await self.n2vc.register_execution_environment( - credentials=credentials, - namespace=namespace, - db_dict=db_dict - ) + ee_id = await self.n2vc.register_execution_environment(credentials=credentials, namespace=namespace, + db_dict=db_dict) # for compatibility with MON/POL modules, the need model and application name at database # TODO ask to N2VC instead of assuming the format "model_name.application_name" @@ -1031,55 +1042,46 @@ class NsLcm(LcmBase): db_update_entry + "ee_id": ee_id}) # n2vc_redesign STEP 3.3 - # TODO check if already done + step = "Install configuration Software" + # TODO check if already done self.logger.debug(logging_text + step) - await self.n2vc.install_configuration_sw( - ee_id=ee_id, - artifact_path=artifact_path, - db_dict=db_dict - ) + await self.n2vc.install_configuration_sw(ee_id=ee_id, artifact_path=artifact_path, db_dict=db_dict) # if SSH access is required, then get execution environment SSH public - required = deep_get(config_descriptor, ("config-access", "ssh-access", "required")) - if is_proxy_charm and required: - + if is_proxy_charm: # if native charm we have waited already to VM be UP pub_key = None - pub_key = await self.n2vc.get_ee_ssh_public__key( - ee_id=ee_id, - db_dict=db_dict - ) + user = None + if deep_get(config_descriptor, ("config-access", "ssh-access", "required")): + # Needed to inject a ssh key + user = deep_get(config_descriptor, ("config-access", "ssh-access", "default-user")) + step = "Install configuration Software, getting public ssh key" + pub_key = await self.n2vc.get_ee_ssh_public__key(ee_id=ee_id, db_dict=db_dict) + + step = "Insert public key into VM" + else: + step = "Waiting to VM being up and getting IP address" + self.logger.debug(logging_text + step) - user = deep_get(config_descriptor, ("config-access", "ssh-access", "default-user")) - # insert pub_key into VM # n2vc_redesign STEP 5.1 - step = "Insert public key into VM" - self.logger.debug(logging_text + step) + # wait for RO (ip-address) Insert pub_key into VM + rw_mgmt_ip = await self.wait_vm_up_insert_key_ro(logging_text, nsr_id, vnfr_id, vdu_id, vdu_index, + user=user, pub_key=pub_key) - # wait for RO (ip-address) - rw_mgmt_ip = await self.insert_key_ro( - logging_text=logging_text, - nsr_id=nsr_id, - vnfr_id=vnfr_id, - vdu_id=vdu_id, - vdu_index=vdu_index, - user=user, - pub_key=pub_key - ) + self.logger.debug(logging_text + ' VM_ip_address={}'.format(rw_mgmt_ip)) - # store rw_mgmt_ip in deploy params for later substitution - self.logger.debug('rw_mgmt_ip={}'.format(rw_mgmt_ip)) + # store rw_mgmt_ip in deploy params for later replacement deploy_params["rw_mgmt_ip"] = rw_mgmt_ip # n2vc_redesign STEP 6 Execute initial config primitive - initial_config_primitive_list = config_descriptor.get('initial-config-primitive') step = 'execute initial config primitive' + initial_config_primitive_list = config_descriptor.get('initial-config-primitive') # sort initial config primitives by 'seq' try: initial_config_primitive_list.sort(key=lambda val: int(val['seq'])) - except Exception: - self.logger.warn(logging_text + 'Cannot sort by "seq" field' + step) + except Exception as e: + self.logger.error(logging_text + step + ": " + str(e)) # add config if not present for NS charm initial_config_primitive_list = self._get_initial_config_primitive_list(initial_config_primitive_list, @@ -1091,6 +1093,7 @@ class NsLcm(LcmBase): deploy_params["ns_config_info"] = self._get_ns_config_info(vca_deployed_list) # TODO check if already done primitive_params_ = self._map_primitive_params(initial_config_primitive, {}, deploy_params) + step = "execute primitive '{}' params '{}'".format(initial_config_primitive["name"], primitive_params_) self.logger.debug(logging_text + step) await self.n2vc.exec_primitive( @@ -1145,7 +1148,6 @@ class NsLcm(LcmBase): nslcmop_operation_state = None db_vnfrs = {} # vnf's info indexed by member-index # n2vc_info = {} - # n2vc_key_list = [] # list of public keys to be injected as authorized to VMs task_instantiation_list = [] exc = None try: @@ -1237,7 +1239,10 @@ class NsLcm(LcmBase): task_instantiation_list.append(task_kdu) # n2vc_redesign STEP 1 Get VCA public ssh-key # feature 1429. Add n2vc public key to needed VMs - n2vc_key = await self.n2vc.get_public_key() + n2vc_key = self.n2vc.get_public_key() + n2vc_key_list = [n2vc_key] + if self.vca_config.get("public_key"): + n2vc_key_list.append(self.vca_config["public_key"]) # n2vc_redesign STEP 2 Deploy Network Scenario task_ro = asyncio.ensure_future( @@ -1249,7 +1254,7 @@ class NsLcm(LcmBase): db_nslcmop=db_nslcmop, db_vnfrs=db_vnfrs, db_vnfds_ref=db_vnfds_ref, - n2vc_key_list=[n2vc_key] + n2vc_key_list=n2vc_key_list ) ) self.lcm_tasks.register("ns", nsr_id, nslcmop_id, "instantiate_RO", task_ro)