X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fadapter%2Fclients%2Focloud_sa_client.py;h=97592d3e11bd9cbe5e8d756ba39711ae35662d64;hb=44f01a560347914798d8f913696d0e495ee076f8;hp=0ec88e21f2d1578fb1cf480f33eb0573938f21c2;hpb=d4513e022d7d75d9967072cec1e0d7db34571120;p=pti%2Fo2.git diff --git a/o2ims/adapter/clients/ocloud_sa_client.py b/o2ims/adapter/clients/ocloud_sa_client.py index 0ec88e2..97592d3 100644 --- a/o2ims/adapter/clients/ocloud_sa_client.py +++ b/o2ims/adapter/clients/ocloud_sa_client.py @@ -15,11 +15,11 @@ # client talking to Stx standalone import uuid -from o2ims.service.client.base_client import BaseClient +from o2common.service.client.base_client import BaseClient from typing import List # Optional, Set from o2ims.domain import stx_object as ocloudModel -from o2ims import config +from o2common.config import config from o2ims.domain.resource_type import ResourceTypeEnum # from dcmanagerclient.api import client @@ -89,9 +89,56 @@ class StxCpuClient(BaseClient): def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: return self.driver.getCpuList(**filters) -# internal driver which implement client call to Stx Standalone instance + +class StxMemClient(BaseClient): + def __init__(self): + super().__init__() + self.driver = StxSaClientImp() + + def _get(self, id) -> ocloudModel.StxGenericModel: + return self.driver.getMem(id) + + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getMemList(**filters) + + +class StxEthClient(BaseClient): + def __init__(self): + super().__init__() + self.driver = StxSaClientImp() + + def _get(self, id) -> ocloudModel.StxGenericModel: + return self.driver.getEthernet(id) + + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getEthernetList(**filters) + + +class StxIfClient(BaseClient): + def __init__(self): + super().__init__() + self.driver = StxSaClientImp() + + def _get(self, id) -> ocloudModel.StxGenericModel: + return self.driver.getIf(id) + + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getIfList(**filters) +class StxIfPortClient(BaseClient): + def __init__(self): + super().__init__() + self.driver = StxSaClientImp() + + def _get(self, id) -> ocloudModel.StxGenericModel: + return self.driver.getPort(id) + + def _list(self, **filters) -> List[ocloudModel.StxGenericModel]: + return self.driver.getPortList(**filters) + + +# internal driver which implement client call to Stx Standalone instance class StxSaClientImp(object): def __init__(self, stx_client=None): super().__init__() @@ -104,27 +151,27 @@ class StxSaClientImp(object): def getInstanceInfo(self) -> ocloudModel.StxGenericModel: systems = self.stxclient.isystem.list() - logger.debug("systems:" + str(systems[0].to_dict())) + logger.debug('systems:' + str(systems[0].to_dict())) return ocloudModel.StxGenericModel( ResourceTypeEnum.OCLOUD, systems[0]) if systems else None def getPserverList(self, **filters) -> List[ocloudModel.StxGenericModel]: # resourcepoolid = filters.get("resourcepoolid", None) hosts = self.stxclient.ihost.list() - logger.debug("host 1:" + str(hosts[0].to_dict())) + logger.debug('host 1:' + str(hosts[0].to_dict())) return [ocloudModel.StxGenericModel( ResourceTypeEnum.PSERVER, self._hostconverter(host)) - for host in hosts if host] + for host in hosts if host] def getPserver(self, id) -> ocloudModel.StxGenericModel: host = self.stxclient.ihost.get(id) - logger.debug("host:" + str(host.to_dict())) + logger.debug('host:' + str(host.to_dict())) return ocloudModel.StxGenericModel( ResourceTypeEnum.PSERVER, self._hostconverter(host)) def getK8sList(self, **filters) -> List[ocloudModel.StxGenericModel]: k8sclusters = self.stxclient.kube_cluster.list() - logger.debug("k8sresources[0]:" + str(k8sclusters[0].to_dict())) + logger.debug('k8sresources[0]:' + str(k8sclusters[0].to_dict())) return [ocloudModel.StxGenericModel( ResourceTypeEnum.DMS, self._k8sconverter(k8sres), self._k8shasher(k8sres)) @@ -140,14 +187,14 @@ class StxSaClientImp(object): if not k8scluster: return None - logger.debug("k8sresource:" + str(k8scluster.to_dict())) + logger.debug('k8sresource:' + str(k8scluster.to_dict())) return ocloudModel.StxGenericModel( ResourceTypeEnum.DMS, self._k8sconverter(k8scluster), self._k8shasher(k8scluster)) def getCpuList(self, **filters) -> List[ocloudModel.StxGenericModel]: - hostid = filters.get("hostid", None) - assert (hostid is not None), "missing hostid to query icpu list" + hostid = filters.get('hostid', None) + assert (hostid is not None), 'missing hostid to query icpu list' cpulist = self.stxclient.icpu.list(hostid) return [ocloudModel.StxGenericModel( ResourceTypeEnum.PSERVER_CPU, @@ -158,6 +205,58 @@ class StxSaClientImp(object): return ocloudModel.StxGenericModel( ResourceTypeEnum.PSERVER_CPU, self._cpuconverter(cpuinfo)) + def getMemList(self, **filters) -> List[ocloudModel.StxGenericModel]: + hostid = filters.get('hostid', None) + assert (hostid is not None), 'missing hostid to query imem list' + memlist = self.stxclient.imemory.list(hostid) + return [ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_RAM, + self._memconverter(memories)) for memories in memlist if memories] + + def getMem(self, id) -> ocloudModel.StxGenericModel: + meminfo = self.stxclient.imemory.get(id) + return ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_RAM, self._memconverter(meminfo)) + + def getEthernetList(self, **filters) -> List[ocloudModel.StxGenericModel]: + hostid = filters.get('hostid', None) + assert (hostid is not None), 'missing hostid to query port list' + ethlist = self.stxclient.ethernet_port.list(hostid) + return [ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_ETH, + self._ethconverter(eth)) for eth in ethlist if eth] + + def getEthernet(self, id) -> ocloudModel.StxGenericModel: + ethinfo = self.stxclient.ethernet_port.get(id) + return ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_ETH, self._ethconverter(ethinfo)) + + def getIfList(self, **filters) -> List[ocloudModel.StxGenericModel]: + hostid = filters.get('hostid', None) + assert (hostid is not None), 'missing hostid to query iinterface list' + iflist = self.stxclient.iinterface.list(hostid) + return [ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_IF, + self._ifconverter(ifs)) for ifs in iflist if ifs] + + def getIf(self, id) -> ocloudModel.StxGenericModel: + ifinfo = self.stxclient.iinterface.get(id) + return ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_IF, self._ifconverter(ifinfo)) + + def getPortList(self, **filters) -> List[ocloudModel.StxGenericModel]: + ifid = filters.get('interfaceid', None) + assert (ifid is not None), 'missing interface id to query port list' + portlist = self.stxclient.iinterface.list_ports(ifid) + return [ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_IF_PORT, + port) for port in portlist if port] + + def getPort(self, id) -> ocloudModel.StxGenericModel: + portinfo = self.stxclient.port.get(id) + return ocloudModel.StxGenericModel( + ResourceTypeEnum.PSERVER_IF_PORT, portinfo) + def _getIsystems(self): return self.stxclient.isystem.list() @@ -171,28 +270,50 @@ class StxSaClientImp(object): 'more than one system exists in the account.') return isystems[0] - @staticmethod + @ staticmethod def _hostconverter(host): - setattr(host, "name", host.hostname) + setattr(host, 'name', host.hostname) return host - @staticmethod + @ staticmethod def _cpuconverter(cpu): - setattr(cpu, "name", "core-"+str(cpu.core)) + setattr(cpu, 'name', cpu.ihost_uuid.split( + '-', 1)[0] + '-cpu-'+str(cpu.cpu)) return cpu - @staticmethod + @ staticmethod + def _memconverter(mem): + setattr(mem, 'name', mem.ihost_uuid.split('-', 1)[0] + + '-mem-node-'+str(mem.numa_node)) + return mem + + @ staticmethod + def _ethconverter(eth): + setattr(eth, 'name', eth.host_uuid.split('-', 1)[0] + '-'+eth.name) + setattr(eth, 'updated_at', None) + setattr(eth, 'created_at', None) + return eth + + @ staticmethod + def _ifconverter(ifs): + setattr(ifs, 'name', ifs.ihost_uuid.split('-', 1)[0] + '-'+ifs.ifname) + setattr(ifs, 'updated_at', None) + setattr(ifs, 'created_at', None) + return ifs + + @ staticmethod def _k8sconverter(cluster): - setattr(cluster, "name", cluster.cluster_name) - setattr(cluster, "uuid", + setattr(cluster, 'name', cluster.cluster_name) + setattr(cluster, 'uuid', uuid.uuid3(uuid.NAMESPACE_URL, cluster.cluster_name)) setattr(cluster, 'updated_at', None) setattr(cluster, 'created_at', None) - logger.debug("k8s cluster name/uuid:" + - cluster.name + "/" + str(cluster.uuid)) + setattr(cluster, 'events', []) + logger.debug('k8s cluster name/uuid:' + + cluster.name + '/' + str(cluster.uuid)) return cluster - @staticmethod + @ staticmethod def _k8shasher(cluster): return str(hash((cluster.cluster_name, cluster.cluster_api_endpoint, cluster.admin_user)))