+ systems = self.stxclient.isystem.list()\r
+ logger.debug("systems:" + str(systems[0].to_dict()))\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.OCLOUD, systems[0]) if systems else None\r
+\r
+ def getPserverList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ # resourcepoolid = filters.get("resourcepoolid", None)\r
+ hosts = self.stxclient.ihost.list()\r
+ logger.debug("host 1:" + str(hosts[0].to_dict()))\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER, self._hostconverter(host))\r
+ for host in hosts if host]\r
+\r
+ def getPserver(self, id) -> ocloudModel.StxGenericModel:\r
+ host = self.stxclient.ihost.get(id)\r
+ logger.debug("host:" + str(host.to_dict()))\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER, self._hostconverter(host))\r
+\r
+ def getK8sList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ k8sclusters = self.stxclient.kube_cluster.list()\r
+ logger.debug("k8sresources[0]:" + str(k8sclusters[0].to_dict()))\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.DMS,\r
+ self._k8sconverter(k8sres), self._k8shasher(k8sres))\r
+ for k8sres in k8sclusters if k8sres]\r
+\r
+ def getK8sDetail(self, name) -> ocloudModel.StxGenericModel:\r
+ if not name:\r
+ k8sclusters = self.stxclient.kube_cluster.list()\r
+ # logger.debug("k8sresources[0]:" + str(k8sclusters[0].to_dict()))\r
+ k8scluster = k8sclusters.pop()\r
+ else:\r
+ k8scluster = self.stxclient.kube_cluster.get(name)\r
+\r
+ if not k8scluster:\r
+ return None\r
+ logger.debug("k8sresource:" + str(k8scluster.to_dict()))\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.DMS,\r
+ self._k8sconverter(k8scluster), self._k8shasher(k8scluster))\r
+\r
+ def getCpuList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query icpu list"\r
+ cpulist = self.stxclient.icpu.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_CPU,\r
+ self._cpuconverter(cpures)) for cpures in cpulist if cpures]\r
+\r
+ def getCpu(self, id) -> ocloudModel.StxGenericModel:\r
+ cpuinfo = self.stxclient.icpu.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_CPU, self._cpuconverter(cpuinfo))\r
+\r
+ def getMemList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query imem list"\r
+ memlist = self.stxclient.imemory.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_RAM,\r
+ self._memconverter(memories)) for memories in memlist if memories]\r
+\r
+ def getMem(self, id) -> ocloudModel.StxGenericModel:\r
+ meminfo = self.stxclient.imemory.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_RAM, self._memconverter(meminfo))\r
+\r
+ def getPortList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query port list"\r
+ portlist = self.stxclient.port.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_PORT,\r
+ port) for port in portlist if port]\r
+\r
+ def getPort(self, id) -> ocloudModel.StxGenericModel:\r
+ portinfo = self.stxclient.port.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_PORT, portinfo)\r
+\r
+ def getIfList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+ hostid = filters.get("hostid", None)\r
+ assert (hostid is not None), "missing hostid to query iinterface list"\r
+ iflist = self.stxclient.iinterface.list(hostid)\r
+ return [ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_IF,\r
+ self._ifconverter(ifs)) for ifs in iflist if ifs]\r
+\r
+ def getIf(self, id) -> ocloudModel.StxGenericModel:\r
+ ifinfo = self.stxclient.iinterface.get(id)\r
+ return ocloudModel.StxGenericModel(\r
+ ResourceTypeEnum.PSERVER_IF, self._ifconverter(ifinfo))\r
+\r
+ def _getIsystems(self):\r
+ return self.stxclient.isystem.list()\r
+\r
+ def _getIsystem(self, id=None):\r
+ if id:\r
+ return self.stxclient.isystem.get(id)\r
+ else:\r
+ isystems = self.stxclient.isystem.list()\r
+ if len(isystems) != 1 and not id:\r
+ raise Exception('No system uuid was provided and '\r
+ 'more than one system exists in the account.')\r
+ return isystems[0]\r
+\r
+ @ staticmethod\r
+ def _hostconverter(host):\r
+ setattr(host, "name", host.hostname)\r
+ return host\r
+\r
+ @ staticmethod\r
+ def _cpuconverter(cpu):\r
+ setattr(cpu, "name", "cpu-"+str(cpu.cpu))\r
+ return cpu\r
+\r
+ @ staticmethod\r
+ def _memconverter(mem):\r
+ setattr(mem, "name", "mem-node-"+str(mem.numa_node))\r
+ return mem\r
+\r
+ @ staticmethod\r
+ def _ifconverter(ifs):\r
+ setattr(ifs, "name", ifs.ifname)\r
+ setattr(ifs, 'updated_at', None)\r
+ setattr(ifs, 'created_at', None)\r
+ return ifs\r