X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fadapter%2Fclients%2Focloud_client.py;h=eb4210974af87def71c20257cdf86939b704ebfb;hb=a425b1b3426dd9a3bca6ba07506e5f21c27c3822;hp=ddc644ee08454385342bc2dabf8977d07d0b03fd;hpb=d23f4cb727b41a43cdb28c3e819fa902cd4fc8cc;p=pti%2Fo2.git diff --git a/o2ims/adapter/clients/ocloud_client.py b/o2ims/adapter/clients/ocloud_client.py index ddc644e..eb42109 100644 --- a/o2ims/adapter/clients/ocloud_client.py +++ b/o2ims/adapter/clients/ocloud_client.py @@ -172,7 +172,37 @@ class StxIfPortClient(BaseClient): self.driver.setStxClient(self._pool_id) -# internal driver which implement client call to Stx Standalone instance +class StxDevClient(BaseClient): + def __init__(self): + super().__init__() + self.driver = StxClientImp() + + def _get(self, id) -> ocloudModel.StxGenericModel: + return self.driver.getDevice(id) + + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getDeviceList(**filters) + + def _set_stx_client(self): + self.driver.setStxClient(self._pool_id) + + +class StxAccClient(BaseClient): + def __init__(self): + super().__init__() + self.driver = StxClientImp() + + def _get(self, id) -> ocloudModel.StxGenericModel: + return self.driver.getAccelerator(id) + + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getAcceleratorList(**filters) + + def _set_stx_client(self): + self.driver.setStxClient(self._pool_id) + + +# internal driver which implement client call to Stx Standalone and DC instance class StxClientImp(object): def __init__(self, stx_client=None, dc_client=None): super().__init__() @@ -253,7 +283,8 @@ class StxClientImp(object): if systems[0].distributed_cloud_role is None or \ systems[0].distributed_cloud_role != 'systemcontroller': return [ocloudModel.StxGenericModel( - ResourceTypeEnum.RESOURCE_POOL, systems[0])] + ResourceTypeEnum.RESOURCE_POOL, + self._respoolconverter(systems[0]))] pools = [] if config.get_system_controller_as_respool(): @@ -275,7 +306,8 @@ class StxClientImp(object): return [ocloudModel.StxGenericModel( ResourceTypeEnum.RESOURCE_POOL, - respool) for respool in pools if respool] + self._respoolconverter( + respool)) for respool in pools if respool] def getResourcePoolDetail(self, id): self.setStxClient(id) @@ -446,6 +478,41 @@ class StxClientImp(object): return ocloudModel.StxGenericModel( ResourceTypeEnum.PSERVER_IF_PORT, portinfo) + def getDeviceList(self, **filters) -> List[ocloudModel.StxGenericModel]: + hostid = filters.get('hostid', None) + assert (hostid is not None), 'missing hostid to query pci device list' + pci_dev_list = self.stxclient.pci_device.list(hostid) + return [ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_PCI_DEV, + self._devconverter(pci_dev)) + for pci_dev in pci_dev_list if pci_dev] + + def getDevice(self, id) -> ocloudModel.StxGenericModel: + pciinfo = self.stxclient.pci_device.get(id) + return ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_PCI_DEV, self._devconverter(pciinfo)) + + def getAcceleratorList(self, **filters) -> \ + List[ocloudModel.StxGenericModel]: + hostid = filters.get('hostid', None) + assert (hostid is not None), 'missing hostid to query accelerator list' + pci_dev_list = self.stxclient.pci_device.list(hostid) + acc_list = [] + for pci_dev in pci_dev_list: + if pci_dev.pvendor_id in ['8086']: + if pci_dev.pdevice_id in ['0d5c', '0d5d']: + logger.info('Accelerator vendor ID: {}, device ID: {}'. + format(pci_dev.pvendor_id, pci_dev.pdevice_id)) + acc_list.append(ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_ACC, + self._devconverter(pci_dev))) + return acc_list + + def getAccelerator(self, id) -> ocloudModel.StxGenericModel: + pciinfo = self.stxclient.pci_device.get(id) + return ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_ACC, self._devconverter(pciinfo)) + def _getIsystems(self): return self.stxclient.isystem.list() @@ -459,6 +526,11 @@ class StxClientImp(object): 'more than one system exists in the account.') return isystems[0] + @ staticmethod + def _respoolconverter(res_pool): + setattr(res_pool, 'name', res_pool.region_name) + return res_pool + @ staticmethod def _hostconverter(host): setattr(host, 'name', host.hostname) @@ -490,6 +562,11 @@ class StxClientImp(object): setattr(ifs, 'created_at', None) return ifs + @ staticmethod + def _devconverter(dev): + setattr(dev, 'name', dev.host_uuid.split('-', 1)[0] + '-'+dev.name) + return dev + @ staticmethod def _k8sconverter(cluster): setattr(cluster, 'name', cluster.cloud_name +