feat(sol006): sol006 migration
[osm/MON.git] / osm_mon / collector / infra_collectors / base_osinfra.py
index 3541dbd..1c1999c 100644 (file)
@@ -46,12 +46,25 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector):
     def collect(self) -> List[Metric]:
         metrics = []
         vim_status = self.is_vim_ok()
-        vim_status_metric = Metric({'vim_account_id': self.vim_account['_id']}, 'vim_status', vim_status)
+        if self.vim_account['_admin']['projects_read']:
+            vim_project_id = self.vim_account['_admin']['projects_read'][0]
+        else:
+            vim_project_id = ''
+        vim_tags = {
+            'vim_account_id': self.vim_account['_id'],
+            'project_id': vim_project_id
+        }
+        vim_status_metric = Metric(vim_tags, 'vim_status', vim_status)
         metrics.append(vim_status_metric)
         vnfrs = self.common_db.get_vnfrs(vim_account_id=self.vim_account['_id'])
         for vnfr in vnfrs:
             nsr_id = vnfr['nsr-id-ref']
+            ns_name = self.common_db.get_nsr(nsr_id)['name']
             vnf_member_index = vnfr['member-vnf-index-ref']
+            if vnfr['_admin']['projects_read']:
+                vnfr_project_id = vnfr['_admin']['projects_read'][0]
+            else:
+                vnfr_project_id = ''
             for vdur in vnfr['vdur']:
                 if 'vim-id' not in vdur:
                     log.debug("Field vim-id is not present in vdur")
@@ -61,8 +74,10 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector):
                     'vim_account_id': self.vim_account['_id'],
                     'resource_uuid': resource_uuid,
                     'nsr_id': nsr_id,
+                    'ns_name': ns_name,
                     'vnf_member_index': vnf_member_index,
-                    'vdur_name': vdur['name']
+                    'vdur_name': vdur.get("name", ""),
+                    'project_id': vnfr_project_id
                 }
                 try:
                     vm = self.nova.servers.get(resource_uuid)
@@ -85,8 +100,8 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector):
 
     def _build_keystone_client(self, vim_account: dict) -> keystone_client.Client:
         sess = OpenstackUtils.get_session(vim_account)
-        return keystone_client.Client(session=sess)
+        return keystone_client.Client(session=sess, timeout=10)
 
     def _build_nova_client(self, vim_account: dict) -> nova_client.Client:
         sess = OpenstackUtils.get_session(vim_account)
-        return nova_client.Client("2", session=sess)
+        return nova_client.Client("2", session=sess, timeout=10)