Update DeploymentManagerInfo attributes
[pti/o2.git] / o2ims / adapter / clients / ocloud_client.py
index 899cebe..f601bbc 100644 (file)
@@ -226,9 +226,11 @@ class StxClientImp(object):
             subcloud_additional_details(subcloud_id)
         logger.debug('subcloud name: %s, oam_floating_ip: %s' %
                      (subcloud[0].name, subcloud[0].oam_floating_ip))
+        if subcloud[0].oam_floating_ip == 'unavailable':
+            raise EnvironmentError(f"{subcloud[0].name} was unavailable")
         try:
             os_client_args = config.get_stx_access_info(
-                region_name=subcloud[0].name,
+                region_name=subcloud[0].region_name,
                 subcloud_hostname=subcloud[0].oam_floating_ip)
             # logger.info(os_client_args)
             config_client = get_stx_client(**os_client_args)
@@ -236,7 +238,7 @@ class StxClientImp(object):
             msg = e.format_message()
             if CGTSCLIENT_ENDPOINT_ERROR_MSG in msg:
                 os_client_args = config.get_stx_access_info(
-                    region_name=subcloud[0].name, sub_is_https=True,
+                    region_name=subcloud[0].region_name, sub_is_https=True,
                     subcloud_hostname=subcloud[0].oam_floating_ip)
                 # logger.info(os_client_args)
                 config_client = get_stx_client(**os_client_args)
@@ -299,7 +301,7 @@ class StxClientImp(object):
                 subcloud_stxclient = self.getSubcloudClient(
                     subcloud.subcloud_id)
                 systems = subcloud_stxclient.isystem.list()
-                logger.debug('systems:' + str(systems[0].to_dict()))
+                logger.debug('subcloud system:' + str(systems[0].to_dict()))
                 pools.append(systems[0])
             except Exception as ex:
                 logger.warning('Failed get cgstclient of subcloud %s: %s' %
@@ -383,6 +385,7 @@ class StxClientImp(object):
     def getK8sList(self, **filters) -> List[ocloudModel.StxGenericModel]:
         def process_cluster(client, cluster):
             setattr(cluster, 'cloud_name', systems[0].name)
+            setattr(cluster, 'cloud_uuid', systems[0].uuid)
             cluster = self._setK8sCapabilities(client, cluster)
             logger.debug('k8sresources cluster_api_endpoint: ' +
                          str(cluster.cluster_api_endpoint))
@@ -430,13 +433,15 @@ class StxClientImp(object):
         return k8s_list
 
     def getK8sDetail(self, name) -> ocloudModel.StxGenericModel:
-        def process_k8s_cluster(client, k8s_cluster, cloud_name):
+        def process_k8s_cluster(client, k8s_cluster, cloud_name, cloud_uuid):
             setattr(k8s_cluster, 'cloud_name', cloud_name)
+            setattr(k8s_cluster, 'cloud_uuid', cloud_uuid)
             k8s_cluster = self._setK8sCapabilities(client, k8s_cluster)
             return k8s_cluster
 
         systems = self.stxclient.isystem.list()
         system_name = systems[0].name
+        system_uuid = systems[0].uuid
 
         if not name:
             k8s_clusters = self.stxclient.kube_cluster.list()
@@ -450,16 +455,20 @@ class StxClientImp(object):
             if cloud_name == system_name:
                 k8s_cluster = process_k8s_cluster(
                     self.stxclient,
-                    self.stxclient.kube_cluster.get(k8s_name), cloud_name)
+                    self.stxclient.kube_cluster.get(k8s_name), cloud_name,
+                    system_uuid)
             else:
                 subclouds = self.getSubcloudList()
                 subcloud_id = next(
                     sub.subcloud_id for sub in subclouds
                     if sub.name == cloud_name)
                 subcloud_stxclient = self.getSubcloudClient(subcloud_id)
+                systems = subcloud_stxclient.isystem.list()
+                system_uuid = systems[0].uuid
                 k8s_cluster = process_k8s_cluster(
                     subcloud_stxclient,
-                    subcloud_stxclient.kube_cluster.get(k8s_name), cloud_name)
+                    subcloud_stxclient.kube_cluster.get(k8s_name), cloud_name,
+                    system_uuid)
 
         if not k8s_cluster:
             return None
@@ -582,12 +591,12 @@ class StxClientImp(object):
                                 'more than one system exists in the account.')
             return isystems[0]
 
-    @ staticmethod
+    @staticmethod
     def _respoolconverter(res_pool):
         setattr(res_pool, 'name', res_pool.region_name)
         return res_pool
 
-    @ staticmethod
+    @staticmethod
     def _hostconverter(host):
         selected_keys = [
             "hostname", "personality", "id", "mgmt_ip", "mgmt_mac",
@@ -603,7 +612,7 @@ class StxClientImp(object):
         setattr(host, 'name', host.hostname)
         return host
 
-    @ staticmethod
+    @staticmethod
     def _labelconverter(label):
         selected_keys = [
             "uuid", "label_key", "label_value", "host_uuid"
@@ -619,7 +628,7 @@ class StxClientImp(object):
         setattr(label, 'created_at', None)
         return label
 
-    @ staticmethod
+    @staticmethod
     def _cpuconverter(cpu):
         selected_keys = [
             "cpu", "core", "thread", "allocated_function", "numa_node",
@@ -633,7 +642,7 @@ class StxClientImp(object):
             '-', 1)[0] + '-cpu-'+str(cpu.cpu))
         return cpu
 
-    @ staticmethod
+    @staticmethod
     def _memconverter(mem):
         selected_keys = [
             "memtotal_mib", "memavail_mib", "vm_hugepages_use_1G",
@@ -651,7 +660,7 @@ class StxClientImp(object):
                 '-mem-node-'+str(mem.numa_node))
         return mem
 
-    @ staticmethod
+    @staticmethod
     def _ethconverter(eth):
         selected_keys = [
             "name", "namedisplay", "dev_id", "pdevice", "capabilities",
@@ -669,7 +678,7 @@ class StxClientImp(object):
         setattr(eth, 'created_at', None)
         return eth
 
-    @ staticmethod
+    @staticmethod
     def _ifconverter(ifs):
         selected_keys = [
             "ifname", "iftype", "imac", "vlan_id", "imtu",
@@ -685,7 +694,7 @@ class StxClientImp(object):
         setattr(ifs, 'created_at', None)
         return ifs
 
-    @ staticmethod
+    @staticmethod
     def _devconverter(dev):
         selected_keys = [
             "name", "pdevice", "pciaddr", "pvendor_id", "pvendor",
@@ -699,12 +708,12 @@ class StxClientImp(object):
         setattr(dev, 'name', dev.host_uuid.split('-', 1)[0] + '-'+dev.name)
         return dev
 
-    @ staticmethod
+    @staticmethod
     def _k8sconverter(cluster):
         setattr(cluster, 'name', cluster.cloud_name +
                 '.' + cluster.cluster_name)
         setattr(cluster, 'uuid',
-                uuid.uuid3(uuid.NAMESPACE_URL, cluster.name))
+                uuid.uuid3(uuid.NAMESPACE_URL, cluster.cloud_uuid))
         setattr(cluster, 'updated_at', None)
         setattr(cluster, 'created_at', None)
         setattr(cluster, 'events', [])
@@ -712,7 +721,7 @@ class StxClientImp(object):
                      cluster.name + '/' + str(cluster.uuid))
         return cluster
 
-    @ staticmethod
+    @staticmethod
     def _k8shasher(cluster):
         return str(hash((cluster.cluster_name, cluster.cloud_name,
                          cluster.cluster_api_endpoint, cluster.admin_user,