def post(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("registration with : %s, %s" % (cloud_owner, cloud_region_id)) self._logger.debug("with data: %s" % request.data) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(RegistryV1, self).post(request, vimid)
def delete(self, request, cloud_owner="", cloud_region_id=""): self._logger.debug("unregister cloud region: %s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) gAZCapAuditThread.remove(vimid) return super(APIv1Registry, self).delete(request, vimid)
def _get_system_info(self, cloud_owner, cloud_region_id, viminfo, session=None): ''' query and populate system info into cloud_extra_info ''' system_info = {} try: vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) # check system version of starlingx isysteminfo = self._get_list_resources("/isystems", "platform", session, viminfo, vimid, "isystems") system_info['software_version'] = isysteminfo[0].get( "software_version", None) if isysteminfo else None system_info['system_mode'] = isysteminfo[0].get( "system_mode", None) if isysteminfo else None system_info['system_type'] = isysteminfo[0].get( "system_type", None) if isysteminfo else None return system_info except HttpError as e: self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) except Exception: self._logger.error(traceback.format_exc()) return None
def post(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) # self._logger.debug("META> %s" % request.META) # self._logger.debug("data> %s" % request.data) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1TokensV2, self).post(request, vimid)
def post(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("vimid, data> %s,%s, %s" % (cloud_owner, cloud_region_id, request.data)) self._logger.debug("META> %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1CapacityCheck, self).post(request, vimid)
def delete(self, request, cloud_owner="", cloud_region_id="", requri=""): # self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % # (cloud_owner, cloud_region_id, request.data)) # self._logger.debug("META: %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1InfraWorkload, self).delete(request, vimid, requri)
def post(self, request, cloud_owner="", cloud_region_id="", tenantid="", portid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Vports, self).post(request, vimid, tenantid, portid)
def get(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1VMlist, self).get(request, vimid, tenantid, serverid)
def delete(self, request, cloud_owner="", cloud_region_id="", tenantid="", flavorid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Flavors, self).delete(request, vimid, tenantid, flavorid)
def get(self, request, cloud_owner="", cloud_region_id=""): ''' :param request: :param cloud_owner: :param cloud_region_id: :return: ''' self._logger.info("cloud_owner, cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1VesAgentCtrl, self).get(request, vimid)
def get_hypervisors(self, request, cloud_owner="", cloud_region_id="", tenantid="", hypervisorid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Hypervisors, self).get_hypervisors(request, vimid, tenantid, hypervisorid)
def delete(self, request, cloud_owner="", cloud_region_id="", servicetype="identity", requri=""): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1GetTenants, self).delete(request, vimid, servicetype, requri)
def put(self, request, cloud_owner="", cloud_region_id="", servicetype="", requri=""): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Services, self).put(request, vimid, servicetype, requri)
def delete(self, request, cloud_owner="", cloud_region_id=""): ''' wrapper of inherited API with VIM ID :param request: :param cloud_owner: :param cloud_region_id: :return: ''' self._logger.info("cloud_owner, cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1VesAgentCtrl, self).delete(request, vimid)
def head(self, request, cloud_owner="", cloud_region_id="", servicetype="", requri=""): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) # self._logger.info("servicetype, requri> %s,%s" % (servicetype, requri)) # self._logger.debug("META, data> %s , %s" % (request.META, request.data)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Services, self).head(request, vimid, servicetype, requri)
def get(self, request, cloud_owner="", cloud_region_id="", servicetype="identity", requri='v3/projects'): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) # self._logger.debug("with servicetype, requri> %s,%s" % (servicetype, requri)) # self._logger.debug("with META> %s" % request.META) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1GetTenants, self).get(request, vimid, servicetype, requri)
def post(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("registration with : %s, %s" % (cloud_owner, cloud_region_id)) try: # Get the specified tenant id specified_project_idorname = request.META.get("Project", None) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) viminfo = VimDriverUtils.get_vim_info(vimid) cloud_extra_info = viminfo.get("cloud_extra_info_json", {}) if cloud_extra_info.get("capacity_auditor_enabled", False): # vim registration will trigger the start the audit of AZ capacity worker_self = InfraResourceAuditor( settings.MULTICLOUD_API_V1_PREFIX, settings.AAI_BASE_URL) backlog_item = { "id": vimid, "worker": worker_self.azcap_audit, "payload": (vimid, specified_project_idorname), "repeat": 5 * 1000000, # repeat every 5 seconds } gAZCapAuditThread.add(backlog_item) if 0 == gAZCapAuditThread.state(): gAZCapAuditThread.start() return super(APIv1Registry, self).post(request, vimid) except HttpError as e: self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: self._logger.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("registration with : %s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Tenants, self).get(request, vimid)
def delete(self, request, cloud_owner="", cloud_region_id="", servicetype="dns-delegate", requri=""): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner,cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1DnsaasDelegate,self).delete(request, vimid, servicetype, requri)
def get(self, request, cloud_owner="", cloud_region_id=""): self._logger.debug("get cloud region: %s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Registry, self).get(request, vimid)
def registryV0(self, vimid="", project_idorname=None): ''' extend base method ''' viminfo = VimDriverUtils.get_vim_info(vimid) if not viminfo: return (10, "Cloud Region not found in AAI: %s" % vimid) # cloud_extra_info_str = viminfo.get('cloud_extra_info', {}) # cloud_extra_info = {} # try: # cloud_extra_info = json.loads(cloud_extra_info_str) # except Exception as ex: # logger.error("Can not convert cloud extra info %s %s" % ( # str(ex), cloud_extra_info_str)) # pass cloud_extra_info = viminfo.get("cloud_extra_info_json", {}) region_specified = cloud_extra_info.get("openstack-region-id", None) multi_region_discovery = cloud_extra_info.get("multi-region-discovery", None) sess = None if project_idorname: try: # check if specified with tenant id sess = VimDriverUtils.get_session(viminfo, tenant_name=None, tenant_id=project_idorname) except Exception as e: pass if not sess: try: # check if specified with tenant name sess = VimDriverUtils.get_session( viminfo, tenant_name=project_idorname, tenant_id=None) except Exception as e: pass if not sess: # set the default tenant since there is no tenant info in the VIM yet sess = VimDriverUtils.get_session(viminfo, tenant_name=viminfo.get( 'tenant', None)) # discover the regions, expect it always returns a list (even empty list) cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) # region_ids = self._discover_regions(cloud_owner, cloud_region_id, sess, viminfo) region_ids = self._discover_regions(vimid, sess, viminfo) if len(region_ids) == 0: self._logger.warn("failed to get region id") # compare the regions with region_specified and then cloud_region_id if region_specified in region_ids: pass elif cloud_region_id in region_ids: region_specified = cloud_region_id pass else: # assume the first region be the primary region # since we have no other way to determine it. region_specified = region_ids.pop(0) # update cloud region and discover/register resource if multi_region_discovery: # no input for specified cloud region, # so discover all cloud region for regionid in region_ids: # do not update the specified region here if region_specified == regionid: continue # create cloud region with composed AAI cloud_region_id # except for the one onboarded externally (e.g. ESR) gen_cloud_region_id = cloud_region_id + "_" + regionid self._logger.info("create a cloud region: %s,%s,%s" % (cloud_owner, gen_cloud_region_id, regionid)) try: self._update_cloud_region(cloud_owner, gen_cloud_region_id, regionid, viminfo, sess) except Exception as e: self._logger.debug("update cloud region fails %s" % str(e)) try: new_vimid = extsys.encode_vim_id(cloud_owner, gen_cloud_region_id) super(RegistryHelper, self).registryV0(new_vimid, project_idorname) # update k8s connectivity try: newviminfo = VimDriverUtils.get_vim_info(new_vimid) sess = VimDriverUtils.get_session( newviminfo, tenant_name=newviminfo.get('tenant', None)) self._update_k8s_info(cloud_owner, gen_cloud_region_id, newviminfo, sess) except Exception as e: self.__logger.debug( "update k8s info failes for cloud region:%s,%s, %s" % (cloud_owner, gen_cloud_region_id, str(e))) # continue the registration without reporting error except Exception as e: self._logger.debug("registryV0 fails %s" % str(e)) # update the specified region try: self._update_cloud_region(cloud_owner, cloud_region_id, region_specified, viminfo, sess) #re-fetch viminfo viminfo = VimDriverUtils.get_vim_info(vimid) except Exception as e: self._logger.debug( "update cloud region fails for cloud region: %s,%s, %s" % (cloud_owner, cloud_region_id, str(e))) # update k8s connectivity try: self._update_k8s_info(cloud_owner, cloud_region_id, viminfo, sess) except Exception as e: self.__logger.debug("update k8s info failes %s" % str(e)) # continue the registration without reporting error try: return super(RegistryHelper, self).registryV0(vimid, project_idorname) except Exception as e: errmsg = "registryV0 fails %s" % str(e) self._logger.debug(errmsg) return 11, errmsg
def unregistryV1(self, cloud_owner, cloud_region_id): # cloud_owner = payload.get("cloud-owner", None) # cloud_region_id = payload.get("cloud-region-id", None) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return self.unregistryV0(vimid)
def delete(self, request, cloud_owner="", cloud_region_id="", tenantid="", serverid="", portid=""): self._logger.info("%s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1ServerOsInterfacePort, self).post(request, vimid, tenantid, serverid, portid)
def delete(self, request, cloud_owner="", cloud_region_id=""): self._logger.debug("unregister cloud region: %s, %s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(RegistryV1, self).delete(request, vimid)
def get(self, request, cloud_owner="", cloud_region_id=""): self._logger.info("cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) return super(APIv1Extensions, self).get(request, vimid)