1 # Copyright (C) 2022 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # client talking to Stx standalone
19 from typing import List
22 from cgtsclient.client import get_client as get_stx_client
23 from cgtsclient.exc import EndpointException
24 from dcmanagerclient.api.client import client as get_dc_client
26 from o2common.config import config
27 from o2common.service.client.base_client import BaseClient
28 from o2ims.domain import stx_object as ocloudModel
29 from o2ims.domain.resource_type import ResourceTypeEnum
31 from o2common.helper import o2logging
32 logger = o2logging.get_logger(__name__)
35 CGTSCLIENT_ENDPOINT_ERROR_MSG = \
36 'Must provide Keystone credentials or user-defined endpoint and token'
39 class StxOcloudClient(BaseClient):
40 def __init__(self, driver=None):
42 self.driver = driver if driver else StxClientImp()
44 def _get(self, id) -> ocloudModel.StxGenericModel:
45 return self.driver.getInstanceInfo()
47 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
48 return [self.driver.getInstanceInfo()]
50 def _set_stx_client(self):
54 class StxResourcePoolClient(BaseClient):
57 self.driver = StxClientImp()
59 def _get(self, id) -> ocloudModel.StxGenericModel:
60 return self.driver.getResourcePoolDetail(id)
62 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
63 return self.driver.getResourcePoolList(**filters)
65 def _set_stx_client(self):
69 class StxDmsClient(BaseClient):
72 self.driver = StxClientImp()
74 def _get(self, name) -> ocloudModel.StxGenericModel:
75 return self.driver.getK8sDetail(name)
77 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
78 return self.driver.getK8sList(**filters)
80 def _set_stx_client(self):
84 class StxPserverClient(BaseClient):
87 self.driver = StxClientImp()
89 def _get(self, id) -> ocloudModel.StxGenericModel:
90 return self.driver.getPserver(id)
92 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
93 return self.driver.getPserverList(**filters)
95 def _set_stx_client(self):
96 self.driver.setStxClient(self._pool_id)
99 class StxCpuClient(BaseClient):
102 # self._pserver_id = pserver_id
103 self.driver = StxClientImp()
105 def _get(self, id) -> ocloudModel.StxGenericModel:
106 return self.driver.getCpu(id)
108 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
109 return self.driver.getCpuList(**filters)
111 def _set_stx_client(self):
112 self.driver.setStxClient(self._pool_id)
115 class StxMemClient(BaseClient):
118 self.driver = StxClientImp()
120 def _get(self, id) -> ocloudModel.StxGenericModel:
121 return self.driver.getMem(id)
123 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
124 return self.driver.getMemList(**filters)
126 def _set_stx_client(self):
127 self.driver.setStxClient(self._pool_id)
130 class StxEthClient(BaseClient):
133 self.driver = StxClientImp()
135 def _get(self, id) -> ocloudModel.StxGenericModel:
136 return self.driver.getEthernet(id)
138 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
139 return self.driver.getEthernetList(**filters)
141 def _set_stx_client(self):
142 self.driver.setStxClient(self._pool_id)
145 class StxIfClient(BaseClient):
148 self.driver = StxClientImp()
150 def _get(self, id) -> ocloudModel.StxGenericModel:
151 return self.driver.getIf(id)
153 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
154 return self.driver.getIfList(**filters)
156 def _set_stx_client(self):
157 self.driver.setStxClient(self._pool_id)
160 class StxIfPortClient(BaseClient):
163 self.driver = StxClientImp()
165 def _get(self, id) -> ocloudModel.StxGenericModel:
166 return self.driver.getPort(id)
168 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
169 return self.driver.getPortList(**filters)
171 def _set_stx_client(self):
172 self.driver.setStxClient(self._pool_id)
175 class StxDevClient(BaseClient):
178 self.driver = StxClientImp()
180 def _get(self, id) -> ocloudModel.StxGenericModel:
181 return self.driver.getDevice(id)
183 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
184 return self.driver.getDeviceList(**filters)
186 def _set_stx_client(self):
187 self.driver.setStxClient(self._pool_id)
190 class StxAccClient(BaseClient):
193 self.driver = StxClientImp()
195 def _get(self, id) -> ocloudModel.StxGenericModel:
196 return self.driver.getAccelerator(id)
198 def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:
199 return self.driver.getAcceleratorList(**filters)
201 def _set_stx_client(self):
202 self.driver.setStxClient(self._pool_id)
205 # internal driver which implement client call to Stx Standalone and DC instance
206 class StxClientImp(object):
207 def __init__(self, stx_client=None, dc_client=None):
209 self.stxclient = stx_client if stx_client else self.getStxClient()
210 self.dcclient = dc_client if dc_client else self.getDcmanagerClient()
211 # if subcloud_id is not None:
212 # self.stxclient = self.getSubcloudClient(subcloud_id)
214 def getStxClient(self):
215 os_client_args = config.get_stx_access_info()
216 config_client = get_stx_client(**os_client_args)
219 def getDcmanagerClient(self):
220 os_client_args = config.get_dc_access_info()
221 config_client = get_dc_client(**os_client_args)
224 def getSubcloudClient(self, subcloud_id):
225 subcloud = self.dcclient.subcloud_manager.\
226 subcloud_additional_details(subcloud_id)
227 logger.debug('subcloud name: %s, oam_floating_ip: %s' %
228 (subcloud[0].name, subcloud[0].oam_floating_ip))
230 os_client_args = config.get_stx_access_info(
231 region_name=subcloud[0].name,
232 subcloud_hostname=subcloud[0].oam_floating_ip)
233 # logger.info(os_client_args)
234 config_client = get_stx_client(**os_client_args)
235 except EndpointException as e:
236 msg = e.format_message()
237 if CGTSCLIENT_ENDPOINT_ERROR_MSG in msg:
238 os_client_args = config.get_stx_access_info(
239 region_name=subcloud[0].name, sub_is_https=True,
240 subcloud_hostname=subcloud[0].oam_floating_ip)
241 # logger.info(os_client_args)
242 config_client = get_stx_client(**os_client_args)
244 raise ValueError('Stx endpoint exception: %s' % msg)
246 raise ValueError('cgtsclient get subcloud client failed')
250 def setStxClient(self, resource_pool_id):
251 systems = self.stxclient.isystem.list()
252 if resource_pool_id == systems[0].uuid:
253 logger.debug('Stx Client not change: %s' % resource_pool_id)
256 subclouds = self.getSubcloudList()
257 for subcloud in subclouds:
258 subcloud_stxclient = self.getSubcloudClient(subcloud.subcloud_id)
259 systems = subcloud_stxclient.isystem.list()
260 # logger.debug('subcloud %s id: %s' %
261 # (systems[0].name, systems[0].uuid))
262 # logger.debug('subcloud: %s' % (systems[0].to_dict()))
263 if resource_pool_id == systems[0].uuid:
264 self.stxclient = subcloud_stxclient
266 def getInstanceInfo(self) -> ocloudModel.StxGenericModel:
267 systems = self.stxclient.isystem.list()
268 logger.debug('systems:' + str(systems[0].to_dict()))
269 # logger.debug('systems[0] uuid: ' + str(systems[0].uuid))
270 return ocloudModel.StxGenericModel(
271 ResourceTypeEnum.OCLOUD, systems[0]) if systems else None
273 def getSubcloudList(self):
274 self.dcclient = self.getDcmanagerClient()
275 subs = self.dcclient.subcloud_manager.list_subclouds()
276 known_subs = [sub for sub in subs if sub.sync_status != 'unknown']
279 def getResourcePoolList(self, **filters) -> List[
280 ocloudModel.StxGenericModel]:
281 systems = self.stxclient.isystem.list()
282 logger.debug('system controller distributed_cloud_role:' +
283 str(systems[0].distributed_cloud_role))
285 if systems[0].distributed_cloud_role is None or \
286 systems[0].distributed_cloud_role != 'systemcontroller':
287 return [ocloudModel.StxGenericModel(
288 ResourceTypeEnum.RESOURCE_POOL,
289 self._respoolconverter(systems[0]))]
292 if config.get_system_controller_as_respool():
293 pools.append(systems[0])
295 subclouds = self.getSubcloudList()
296 logger.debug('subclouds numbers: %s' % len(subclouds))
297 for subcloud in subclouds:
299 subcloud_stxclient = self.getSubcloudClient(
300 subcloud.subcloud_id)
301 systems = subcloud_stxclient.isystem.list()
302 logger.debug('systems:' + str(systems[0].to_dict()))
303 pools.append(systems[0])
304 except Exception as ex:
305 logger.warning('Failed get cgstclient of subcloud %s: %s' %
309 return [ocloudModel.StxGenericModel(
310 ResourceTypeEnum.RESOURCE_POOL,
311 self._respoolconverter(
312 respool)) for respool in pools if respool]
314 def getResourcePoolDetail(self, id):
315 self.setStxClient(id)
316 systems = self.stxclient.isystem.list()
317 logger.debug('systems:' + str(systems[0].to_dict()))
318 return ocloudModel.StxGenericModel(
319 ResourceTypeEnum.RESOURCE_POOL,
320 self._respoolconverter(systems[0])) if systems else None
322 def getPserverList(self, **filters) -> List[ocloudModel.StxGenericModel]:
323 hosts = self.stxclient.ihost.list()
324 logger.debug('host 1:' + str(hosts[0].to_dict()))
325 return [ocloudModel.StxGenericModel(
326 ResourceTypeEnum.PSERVER, self._hostconverter(host))
327 for host in hosts if host and (host.availability == 'available'
328 or host.availability == 'online'
329 or host.availability == 'degraded')]
331 def getPserver(self, id) -> ocloudModel.StxGenericModel:
332 host = self.stxclient.ihost.get(id)
333 logger.debug('host:' + str(host.to_dict()))
334 return ocloudModel.StxGenericModel(
335 ResourceTypeEnum.PSERVER, self._hostconverter(host))
337 def _checkLabelExistOnHost(self, label_key, hostid) -> bool:
338 labels = self.stxclient.label.list(hostid)
339 return any(label_key == label.label_key for label in labels)
341 def _checkLabelExistOnCluster(self, label_key) -> bool:
342 hosts = self.stxclient.ihost.list()
344 def find_label_on_host():
349 if self._checkLabelExistOnHost(label_key, host.uuid)
355 logger.info("host %s has the label %s" %
356 (result[0].hostname, label_key))
360 return find_label_on_host()
362 # return any(self._checkLabelExistOnHost(label_key, host.uuid) for host
365 def _setK8sCapabilities(self, k8scluster):
367 if self._checkLabelExistOnCluster('OS'):
368 logger.debug("low latency host inside of the cluster")
369 capabilities['OS'] = 'low_latency'
370 setattr(k8scluster, 'capabilities', json.dumps(capabilities))
373 def getLabelList(self, **filters) -> List[ocloudModel.StxGenericModel]:
374 hostid = filters.get('hostid', None)
375 assert (hostid is not None), 'missing hostid to query label list'
376 labels = self.stxclient.label.list(hostid)
377 return [ocloudModel.StxGenericModel(
378 ResourceTypeEnum.PSERVER_LABEL,
379 self._labelconverter(label)) for label in labels if label]
381 def getK8sList(self, **filters) -> List[ocloudModel.StxGenericModel]:
382 systems = self.stxclient.isystem.list()
383 logger.debug('system controller distributed_cloud_role:' +
384 str(systems[0].distributed_cloud_role))
386 if systems[0].distributed_cloud_role is None or \
387 systems[0].distributed_cloud_role != 'systemcontroller':
388 k8sclusters = self.stxclient.kube_cluster.list()
389 setattr(k8sclusters[0], 'cloud_name', systems[0].name)
390 k8sclusters[0] = self._setK8sCapabilities(k8sclusters[0])
391 # logger.debug('k8sresources[0]:' + str(k8sclusters[0].to_dict()))
392 logger.debug('k8sresources[0] cluster_api_endpoint: ' +
393 str(k8sclusters[0].cluster_api_endpoint))
394 return [ocloudModel.StxGenericModel(
395 ResourceTypeEnum.DMS,
396 self._k8sconverter(k8sres), self._k8shasher(k8sres))
397 for k8sres in k8sclusters if k8sres]
400 if config.get_system_controller_as_respool():
401 k8sclusters = self.stxclient.kube_cluster.list()
402 setattr(k8sclusters[0], 'cloud_name', systems[0].name)
403 k8sclusters[0] = self._setK8sCapabilities(k8sclusters[0])
404 # logger.debug('k8sresources[0]:' + str(k8sclusters[0].to_dict()))
405 logger.debug('k8sresources[0] cluster_api_endpoint: ' +
406 str(k8sclusters[0].cluster_api_endpoint))
407 k8s_list.append(k8sclusters[0])
409 subclouds = self.getSubcloudList()
410 logger.debug('subclouds numbers: %s' % len(subclouds))
411 for subcloud in subclouds:
413 subcloud_stxclient = self.getSubcloudClient(
414 subcloud.subcloud_id)
415 systems = subcloud_stxclient.isystem.list()
416 k8sclusters = subcloud_stxclient.kube_cluster.list()
417 setattr(k8sclusters[0], 'cloud_name', systems[0].name)
418 k8sclusters[0] = self._setK8sCapabilities(k8sclusters[0])
419 logger.debug('k8sresources[0]:' +
420 str(k8sclusters[0].to_dict()))
421 # logger.debug('k8sresources[0] cluster_api_endpoint: ' +
422 # str(k8sclusters[0].cluster_api_endpoint))
423 k8s_list.append(k8sclusters[0])
424 except Exception as ex:
425 logger.warning('Failed get cgstclient of subcloud %s: %s' %
429 return [ocloudModel.StxGenericModel(ResourceTypeEnum.DMS,
430 self._k8sconverter(k8sres), self._k8shasher(k8sres))
431 for k8sres in k8s_list if k8sres]
433 def getK8sDetail(self, name) -> ocloudModel.StxGenericModel:
434 systems = self.stxclient.isystem.list()
436 k8sclusters = self.stxclient.kube_cluster.list()
437 # logger.debug("k8sresources[0]:" + str(k8sclusters[0].to_dict()))
438 setattr(k8sclusters[0], 'cloud_name', systems[0].name)
439 k8sclusters[0] = self._setK8sCapabilities(k8sclusters[0])
440 k8scluster = k8sclusters.pop()
442 sname = name.split('.')
443 cloud_name = '.'.join(sname[:-1])
445 if cloud_name == systems[0].name:
446 k8scluster = self.stxclient.kube_cluster.get(k8s_name)
447 setattr(k8scluster, 'cloud_name', cloud_name)
448 k8scluster = self._setK8sCapabilities(k8scluster)
450 subclouds = self.getSubcloudList()
452 sub.subcloud_id for sub in subclouds
453 if sub.name == cloud_name][0]
454 subcloud_stxclient = self.getSubcloudClient(subcloud_id)
455 k8scluster = subcloud_stxclient.kube_cluster.get(k8s_name)
456 setattr(k8scluster, 'cloud_name', cloud_name)
457 k8scluster = self._setK8sCapabilities(k8scluster)
458 # logger.debug('k8sresources[0]:' +
459 # str(k8sclusters[0].to_dict()))
460 # logger.debug('k8sresources[0] cluster_api_endpoint: ' +
461 # str(k8sclusters[0].cluster_api_endpoint))
465 logger.debug('k8sresource:' + str(k8scluster.to_dict()))
466 return ocloudModel.StxGenericModel(
467 ResourceTypeEnum.DMS,
468 self._k8sconverter(k8scluster), self._k8shasher(k8scluster))
470 def getCpuList(self, **filters) -> List[ocloudModel.StxGenericModel]:
471 hostid = filters.get('hostid', None)
472 assert (hostid is not None), 'missing hostid to query icpu list'
473 cpulist = self.stxclient.icpu.list(hostid)
474 return [ocloudModel.StxGenericModel(
475 ResourceTypeEnum.PSERVER_CPU,
476 self._cpuconverter(cpures)) for cpures in cpulist if cpures]
478 def getCpu(self, id) -> ocloudModel.StxGenericModel:
479 cpuinfo = self.stxclient.icpu.get(id)
480 return ocloudModel.StxGenericModel(
481 ResourceTypeEnum.PSERVER_CPU, self._cpuconverter(cpuinfo))
483 def getMemList(self, **filters) -> List[ocloudModel.StxGenericModel]:
484 hostid = filters.get('hostid', None)
485 assert (hostid is not None), 'missing hostid to query imem list'
486 memlist = self.stxclient.imemory.list(hostid)
487 return [ocloudModel.StxGenericModel(
488 ResourceTypeEnum.PSERVER_RAM,
489 self._memconverter(memories)) for memories in memlist if memories]
491 def getMem(self, id) -> ocloudModel.StxGenericModel:
492 meminfo = self.stxclient.imemory.get(id)
493 return ocloudModel.StxGenericModel(
494 ResourceTypeEnum.PSERVER_RAM, self._memconverter(meminfo))
496 def getEthernetList(self, **filters) -> List[ocloudModel.StxGenericModel]:
497 hostid = filters.get('hostid', None)
498 assert (hostid is not None), 'missing hostid to query port list'
499 ethlist = self.stxclient.ethernet_port.list(hostid)
500 return [ocloudModel.StxGenericModel(
501 ResourceTypeEnum.PSERVER_ETH,
502 self._ethconverter(eth)) for eth in ethlist if eth]
504 def getEthernet(self, id) -> ocloudModel.StxGenericModel:
505 ethinfo = self.stxclient.ethernet_port.get(id)
506 return ocloudModel.StxGenericModel(
507 ResourceTypeEnum.PSERVER_ETH, self._ethconverter(ethinfo))
509 def getIfList(self, **filters) -> List[ocloudModel.StxGenericModel]:
510 hostid = filters.get('hostid', None)
511 assert (hostid is not None), 'missing hostid to query iinterface list'
512 iflist = self.stxclient.iinterface.list(hostid)
513 return [ocloudModel.StxGenericModel(
514 ResourceTypeEnum.PSERVER_IF,
515 self._ifconverter(ifs)) for ifs in iflist if ifs]
517 def getIf(self, id) -> ocloudModel.StxGenericModel:
518 ifinfo = self.stxclient.iinterface.get(id)
519 return ocloudModel.StxGenericModel(
520 ResourceTypeEnum.PSERVER_IF, self._ifconverter(ifinfo))
522 def getPortList(self, **filters) -> List[ocloudModel.StxGenericModel]:
523 ifid = filters.get('interfaceid', None)
524 assert (ifid is not None), 'missing interface id to query port list'
525 portlist = self.stxclient.iinterface.list_ports(ifid)
526 return [ocloudModel.StxGenericModel(
527 ResourceTypeEnum.PSERVER_IF_PORT,
528 port) for port in portlist if port]
530 def getPort(self, id) -> ocloudModel.StxGenericModel:
531 portinfo = self.stxclient.port.get(id)
532 return ocloudModel.StxGenericModel(
533 ResourceTypeEnum.PSERVER_IF_PORT, portinfo)
535 def getDeviceList(self, **filters) -> List[ocloudModel.StxGenericModel]:
536 hostid = filters.get('hostid', None)
537 assert (hostid is not None), 'missing hostid to query pci device list'
538 pci_dev_list = self.stxclient.pci_device.list(hostid)
539 return [ocloudModel.StxGenericModel(
540 ResourceTypeEnum.PSERVER_PCI_DEV,
541 self._devconverter(pci_dev))
542 for pci_dev in pci_dev_list if pci_dev]
544 def getDevice(self, id) -> ocloudModel.StxGenericModel:
545 pciinfo = self.stxclient.pci_device.get(id)
546 return ocloudModel.StxGenericModel(
547 ResourceTypeEnum.PSERVER_PCI_DEV, self._devconverter(pciinfo))
549 def getAcceleratorList(self, **filters) -> \
550 List[ocloudModel.StxGenericModel]:
551 hostid = filters.get('hostid', None)
552 assert (hostid is not None), 'missing hostid to query accelerator list'
553 pci_dev_list = self.stxclient.pci_device.list(hostid)
555 for pci_dev in pci_dev_list:
556 if pci_dev.pvendor_id in ['8086']:
557 if pci_dev.pdevice_id in ['0d5c', '0d5d']:
558 logger.info('Accelerator vendor ID: {}, device ID: {}'.
559 format(pci_dev.pvendor_id, pci_dev.pdevice_id))
560 acc_list.append(ocloudModel.StxGenericModel(
561 ResourceTypeEnum.PSERVER_ACC,
562 self._devconverter(pci_dev)))
565 def getAccelerator(self, id) -> ocloudModel.StxGenericModel:
566 pciinfo = self.stxclient.pci_device.get(id)
567 return ocloudModel.StxGenericModel(
568 ResourceTypeEnum.PSERVER_ACC, self._devconverter(pciinfo))
570 def _getIsystems(self):
571 return self.stxclient.isystem.list()
573 def _getIsystem(self, id=None):
575 return self.stxclient.isystem.get(id)
577 isystems = self.stxclient.isystem.list()
578 if len(isystems) != 1 and not id:
579 raise Exception('No system uuid was provided and '
580 'more than one system exists in the account.')
584 def _respoolconverter(res_pool):
585 setattr(res_pool, 'name', res_pool.region_name)
589 def _hostconverter(host):
591 "hostname", "personality", "id", "mgmt_ip", "mgmt_mac",
592 "software_load", "capabilities",
593 "operational", "availability", "administrative",
594 "boot_device", "rootfs_device", "install_state", "subfunctions",
595 "clock_synchronization", "max_cpu_mhz_allowed"
597 content = host.to_dict()
599 filter(lambda item: item[0] in selected_keys, content.items()))
600 setattr(host, 'filtered', filtered)
601 setattr(host, 'name', host.hostname)
605 def _labelconverter(label):
607 "uuid", "label_key", "label_value", "host_uuid"
609 content = label.to_dict()
612 filter(lambda item: item[0] in selected_keys, content.items()))
613 setattr(label, 'filtered', filtered)
614 setattr(label, 'name', label.uuid.split(
615 '-', 1)[0] + '-label-' + label.label_key)
616 setattr(label, 'updated_at', None)
617 setattr(label, 'created_at', None)
621 def _cpuconverter(cpu):
623 "cpu", "core", "thread", "allocated_function", "numa_node",
624 "cpu_model", "cpu_family"
626 content = cpu.to_dict()
628 filter(lambda item: item[0] in selected_keys, content.items()))
629 setattr(cpu, 'filtered', filtered)
630 setattr(cpu, 'name', cpu.ihost_uuid.split(
631 '-', 1)[0] + '-cpu-'+str(cpu.cpu))
635 def _memconverter(mem):
637 "memtotal_mib", "memavail_mib", "vm_hugepages_use_1G",
638 "vm_hugepages_possible_1G", "hugepages_configured",
639 "vm_hugepages_avail_1G", "vm_hugepages_nr_1G",
640 "vm_hugepages_nr_4K", "vm_hugepages_nr_2M",
641 "vm_hugepages_possible_2M", "vm_hugepages_avail_2M",
642 "platform_reserved_mib", "numa_node"
644 content = mem.to_dict()
646 filter(lambda item: item[0] in selected_keys, content.items()))
647 setattr(mem, 'filtered', filtered)
648 setattr(mem, 'name', mem.ihost_uuid.split('-', 1)[0] +
649 '-mem-node-'+str(mem.numa_node))
653 def _ethconverter(eth):
655 "name", "namedisplay", "dev_id", "pdevice", "capabilities",
656 "type", "driver", "mac", "numa_node",
657 "pciaddr", "pclass", "psvendor", "psdevice",
658 "sriov_totalvfs", "sriov_numvfs", "dpdksupport",
659 "sriov_vf_driver", "sriov_vf_pdevice_id", "interface_uuid"
661 content = eth.to_dict()
663 filter(lambda item: item[0] in selected_keys, content.items()))
664 setattr(eth, 'filtered', filtered)
665 setattr(eth, 'name', eth.host_uuid.split('-', 1)[0] + '-'+eth.name)
666 setattr(eth, 'updated_at', None)
667 setattr(eth, 'created_at', None)
671 def _ifconverter(ifs):
673 "ifname", "iftype", "imac", "vlan_id", "imtu",
674 "ifclass", "uses", "max_tx_rate",
675 "sriov_vf_driver", "sriov_numvfs", "ptp_role"
677 content = ifs.to_dict()
679 filter(lambda item: item[0] in selected_keys, content.items()))
680 setattr(ifs, 'filtered', filtered)
681 setattr(ifs, 'name', ifs.ihost_uuid.split('-', 1)[0] + '-'+ifs.ifname)
682 setattr(ifs, 'updated_at', None)
683 setattr(ifs, 'created_at', None)
687 def _devconverter(dev):
689 "name", "pdevice", "pciaddr", "pvendor_id", "pvendor",
690 "pclass_id", "pclass", "psvendor", "psdevice",
691 "sriov_totalvfs", "sriov_numvfs", "numa_node"
693 content = dev.to_dict()
695 filter(lambda item: item[0] in selected_keys, content.items()))
696 setattr(dev, 'filtered', filtered)
697 setattr(dev, 'name', dev.host_uuid.split('-', 1)[0] + '-'+dev.name)
701 def _k8sconverter(cluster):
702 setattr(cluster, 'name', cluster.cloud_name +
703 '.' + cluster.cluster_name)
704 setattr(cluster, 'uuid',
705 uuid.uuid3(uuid.NAMESPACE_URL, cluster.cluster_name))
706 setattr(cluster, 'updated_at', None)
707 setattr(cluster, 'created_at', None)
708 setattr(cluster, 'events', [])
709 logger.debug('k8s cluster name/uuid:' +
710 cluster.name + '/' + str(cluster.uuid))
714 def _k8shasher(cluster):
715 return str(hash((cluster.cluster_name, cluster.cloud_name,
716 cluster.cluster_api_endpoint, cluster.admin_user,
717 cluster.capabilities)))