diff options
Diffstat (limited to 'share/starlingx_base/registration/registration.py')
-rw-r--r-- | share/starlingx_base/registration/registration.py | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/share/starlingx_base/registration/registration.py b/share/starlingx_base/registration/registration.py index 507f0fbf..b6ed9250 100644 --- a/share/starlingx_base/registration/registration.py +++ b/share/starlingx_base/registration/registration.py @@ -58,7 +58,7 @@ class APIv0Registry(newton_registration.Registry): backlog_item = { "id": vimid, "worker": worker_self.azcap_audit, - "payload": (worker_self, vimid, specified_project_idorname), + "payload": (vimid, specified_project_idorname), "repeat": 10*1000000, # repeat every 10 seconds } gAZCapAuditThread.add(backlog_item) @@ -88,6 +88,9 @@ class APIv1Registry(newton_registration.Registry): % (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) # vim registration will trigger the start the audit of AZ capacity @@ -98,7 +101,7 @@ class APIv1Registry(newton_registration.Registry): backlog_item = { "id": vimid, "worker": worker_self.azcap_audit, - "payload": (worker_self, vimid), + "payload": (vimid, specified_project_idorname), "repeat": 5 * 1000000, # repeat every 5 seconds } gAZCapAuditThread.add(backlog_item) @@ -162,6 +165,7 @@ class RegistryHelper(newton_registration.RegistryHelper): multi_region_discovery = cloud_extra_info.get( "multi-region-discovery", None) if cloud_extra_info else None + sess = None if project_idorname: try: # check if specified with tenant id @@ -221,18 +225,30 @@ class RegistryHelper(newton_registration.RegistryHelper): self._logger.info("create a cloud region: %s,%s,%s" % (cloud_owner, gen_cloud_region_id, regionid)) - self._update_cloud_region( - cloud_owner, gen_cloud_region_id, regionid, viminfo) - new_vimid = extsys.encode_vim_id( - cloud_owner, gen_cloud_region_id) - # super(APIv1Registry, self).post(request, new_vimid) - super(RegistryHelper, self)(new_vimid) + try: + self._update_cloud_region( + cloud_owner, gen_cloud_region_id, regionid, viminfo) + except Exception as e: + self._logger.debug("update cloud region fails %s" % e.message) + + try: + new_vimid = extsys.encode_vim_id( + cloud_owner, gen_cloud_region_id) + super(RegistryHelper, self).registryV0(new_vimid, project_idorname) + except Exception as e: + self._logger.debug("registryV0 fails %s" % e.message) # update the specified region - self._update_cloud_region(cloud_owner, cloud_region_id, - region_specified, viminfo) + try: + self._update_cloud_region(cloud_owner, cloud_region_id, + region_specified, viminfo) + except Exception as e: + self._logger.debug("update cloud region fails %s" % e.message) - self.super(RegistryHelper, self).registry(vimid) + try: + super(RegistryHelper, self).registryV0(vimid, project_idorname) + except Exception as e: + self._logger.debug("registryV0 fails %s" % e.message) return 0 @@ -403,6 +419,7 @@ class InfraResourceAuditor(newton_registration.RegistryHelper): self._logger.warn("azcap_audit no valid vimid: %s" % vimid) return + sess = None if project_idorname: try: # check if specified with tenant id @@ -456,9 +473,8 @@ class InfraResourceAuditor(newton_registration.RegistryHelper): viminfo, vimid, "availabilityZoneInfo"): az_info = { - 'availability-zone-name': az['zoneName'], - 'operational-status': az['zoneState']['available'] - if az.get('zoneState') else '', + 'availability-zone-name': az.get('zoneName', ""), + 'operational-status': az.get('zoneState', {}).get('available', ""), 'hypervisor-type': '', } # filter out the default az: "internal" and "nova" @@ -477,7 +493,7 @@ class InfraResourceAuditor(newton_registration.RegistryHelper): # Get current cap info of azName azCapCacheKey = "cap_" + vimid + "_" + azName azCapInfoCacheStr = cache.get(azCapCacheKey) - azCapInfoCache = json.loads(azCapInfoCacheStr) if azCapInfoCacheStr else None + azCapInfoCache = json.loads(azCapInfoCacheStr) if azCapInfoCacheStr else {} for psname in pservers_info: psinfo = hypervisors_dict.get(psname, None) @@ -487,7 +503,7 @@ class InfraResourceAuditor(newton_registration.RegistryHelper): # get current pserver cap info psCapInfoCacheKey = "cap_" + vimid + "_" + psname psCapInfoCacheStr = cache.get(psCapInfoCacheKey) - psCapInfoCache = json.loads(psCapInfoCacheStr) if psCapInfoCacheStr else None + psCapInfoCache = json.loads(psCapInfoCacheStr) if psCapInfoCacheStr else {} # compare latest info with cached one vcpu_delta = 0 @@ -520,19 +536,21 @@ class InfraResourceAuditor(newton_registration.RegistryHelper): localstorage_free_delta += psinfo.get("free_disk_gb", 0)\ - psCapInfoCache.get("free_disk_gb", 0) psCapInfoCache["free_disk_gb"] = psinfo.get("free_disk_gb", 0) - pass - # now apply the delta to azCapInfo - azCapInfoCache["vcpus"] = azCapInfoCache.get("vcpus", 0) + vcpu_delta - azCapInfoCache["memory_mb"] = azCapInfoCache.get("memory_mb", 0) + mem_delta - azCapInfoCache["local_gb"] = azCapInfoCache.get("local_gb", 0) + localstorage_delta - azCapInfoCache["vcpus_used"] = azCapInfoCache.get("vcpus_used", 0) + vcpu_used_delta - azCapInfoCache["free_ram_mb"] = azCapInfoCache.get("free_ram_mb", 0) + mem_free_delta - azCapInfoCache["free_disk_gb"] = azCapInfoCache.get("free_disk_gb", 0) + localstorage_free_delta + cache.set(psCapInfoCacheKey, json.dumps(psCapInfoCache), 3600 * 24) + + # now apply the delta to azCapInfo + azCapInfoCache["vcpus"] = azCapInfoCache.get("vcpus", 0) + vcpu_delta + azCapInfoCache["memory_mb"] = azCapInfoCache.get("memory_mb", 0) + mem_delta + azCapInfoCache["local_gb"] = azCapInfoCache.get("local_gb", 0) + localstorage_delta + azCapInfoCache["vcpus_used"] = azCapInfoCache.get("vcpus_used", 0) + vcpu_used_delta + azCapInfoCache["free_ram_mb"] = azCapInfoCache.get("free_ram_mb", 0) + mem_free_delta + azCapInfoCache["free_disk_gb"] = azCapInfoCache.get("free_disk_gb", 0) + localstorage_free_delta + pass # update the cache cache.set(azCapCacheKey, json.dumps(azCapInfoCache), 3600 * 24) - cache.set(vimAzCacheKey, vimAzList, 3600 * 24) + cache.set(vimAzCacheKey, json.dumps(vimAzList), 3600 * 24) except Exception as e: self._logger.error("azcap_audit raise exception: %s" % e) pass |