def delete_vserver_in_aai(self, vim_id, vserver_id, vserver_name): logger.debug("delete_vserver_in_aai start![%s]", vserver_name) try: cloud_owner, cloud_region_id = split_vim_to_owner_region(vim_id) # query vim_info from aai, get tenant vim_info = get_vim_by_id({ "cloud_owner": cloud_owner, 'cloud_regionid': cloud_region_id }) tenant_id = vim_info["tenantId"] # query vserver instance in aai, get resource_version vserver_info = query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id) if vserver_info: resource_version = vserver_info["resource-version"] # delete vserver instance from aai resp_data, resp_status = delete_vserver_aai( cloud_owner, cloud_region_id, tenant_id, vserver_id, resource_version) logger.debug( "Success to delete vserver instance[%s] from aai, resp_status: [%s]." % (vserver_id, resp_status)) logger.debug("delete_vserver_in_aai end!") except RequestException: logger.debug("Vserver has been deleted from aai") except NSLCMException as e: logger.debug( "Fail to delete vserver from aai, detail message: %s" % e.args[0]) except: logger.error(traceback.format_exc())
def grant_vnf(req_param): grant_data = json.JSONEncoder().encode(req_param) ret = req_by_msb("/openoapi/resmgr/v1/resource/grant", "PUT", grant_data) if ret[0] != 0: logger.error("Failed to grant vnf to resmgr. detail is %s.", ret[1]) #raise NSLCMException('Failed to grant vnf to resmgr.') vim_id = "" if "vimId" in req_param: vim_id = req_param["vimId"] elif "additionalparam" in req_param and "vimid" in req_param["additionalparam"]: vim_id = req_param["additionalparam"]["vimid"] try: from lcm.pub.msapi import extsys vim = extsys.get_vim_by_id(vim_id) if isinstance(vim, list): vim = vim[0] vim_id = vim["vimId"] grant_rsp = { "vim": { "vimid": vim_id, "accessinfo": { "tenant": vim["tenant"] } } } logger.debug("grant_rsp=%s" % grant_rsp) return grant_rsp except: raise NSLCMException('Failed to grant vnf to resmgr.') return json.JSONDecoder().decode(ret[1])
def delete_vserver_in_aai(self): logger.debug("delete_vserver_in_aai start!") try: vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.vnf_inst_id) for vm_inst_info in vm_inst_infos: vserver_id = vm_inst_info.resouceid vim_id = vm_inst_info.vimid cloud_owner, cloud_region_id = split_vim_to_owner_region(vim_id) # query vim_info from aai, get tenant vim_info = get_vim_by_id({"cloud_owner": cloud_owner, 'cloud_regionid': cloud_region_id}) tenant_id = vim_info["tenantId"] # query vserver instance in aai, get resource_version vserver_info = query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id) resource_version = vserver_info["resource-version"] # delete vserver instance from aai resp_data, resp_status = delete_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, resource_version) logger.debug( "Success to delete vserver instance[%s] from aai, resp_status: [%s]." % (vserver_id, resp_status)) logger.debug("delete_vserver_in_aai end!") except NSLCMException as e: logger.debug("Fail to delete vserver from aai, detail message: %s" % e.args[0]) except: logger.error(traceback.format_exc())
def delete_vl_from_vim(self, vim_id, subnetwork_id_list, network_id): vim_resp_body = extsys.get_vim_by_id(vim_id) data = { "vimid": vim_id, "vimtype": vim_resp_body["type"], "url": vim_resp_body["url"], "user": vim_resp_body["userName"], "passwd": vim_resp_body["password"], "tenant": vim_resp_body["tenant"] } vim_api = vimadaptor.VimAdaptor(data) for subnetwork_id in subnetwork_id_list: vim_api.delete_subnet(subnet_id=subnetwork_id) vim_api.delete_network(network_id=network_id)
def create_vserver_in_aai(self, vim_id, vserver_id, vserver_name): logger.debug( "NotifyLcm::create_vserver_in_aai::report vserver instance to aai." ) try: cloud_owner, cloud_region_id = split_vim_to_owner_region(vim_id) # query vim_info from aai vim_info = get_vim_by_id({ "cloud_owner": cloud_owner, 'cloud_regionid': cloud_region_id }) tenant_id = vim_info["tenantId"] data = { "vserver-id": vserver_id, "vserver-name": vserver_name, "prov-status": "ACTIVE", "vserver-selflink": "", "in-maint": True, "is-closed-loop-disabled": False, "relationship-list": { "relationship": [{ "related-to": "generic-vnf", "relationship-data": [{ "relationship-key": "generic-vnf.vnf-id", "relationship-value": self.vnf_instid }] }] } } # create vserver instance in aai resp_data, resp_status = create_vserver_aai( cloud_owner, cloud_region_id, tenant_id, vserver_id, data) logger.debug( "Success to create vserver[%s] to aai, vnf instance=[%s], resp_status: [%s]." % (vserver_id, self.vnf_instid, resp_status)) except NSLCMException as e: logger.debug( "Fail to create vserver to aai, vnf instance=[%s], detail message: %s" % (self.vnf_instid, e.args[0])) except: logger.error(traceback.format_exc())
def create_network_to_vim(self, network_data): vim_resp_body = extsys.get_vim_by_id(self.vim_id) self.vim_name = vim_resp_body["name"] data = { "vimid": self.vim_id, "vimtype": vim_resp_body["type"], "url": vim_resp_body["url"], "user": vim_resp_body["userName"], "passwd": vim_resp_body["password"], "tenant": vim_resp_body["tenant"] } vim_api = vimadaptor.VimAdaptor(data) if not network_data["tenant"]: network_data["tenant"] = vim_resp_body["tenant"] vl_ret = vim_api.create_network(network_data) if vl_ret[0] != 0: logger.error("Send post vl request to vim failed, detail is %s" % vl_ret[1]) raise NSLCMException("Send post vl request to vim failed.") return vl_ret[1]