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))
229 if subcloud[0].oam_floating_ip == 'unavailable':
230 raise EnvironmentError(f"{subcloud[0].name} was unavailable")
232 os_client_args = config.get_stx_access_info(
233 region_name=subcloud[0].region_name,
234 subcloud_hostname=subcloud[0].oam_floating_ip)
235 # logger.info(os_client_args)
236 config_client = get_stx_client(**os_client_args)
237 except EndpointException as e:
238 msg = e.format_message()
239 if CGTSCLIENT_ENDPOINT_ERROR_MSG in msg:
240 os_client_args = config.get_stx_access_info(
241 region_name=subcloud[0].region_name, sub_is_https=True,
242 subcloud_hostname=subcloud[0].oam_floating_ip)
243 # logger.info(os_client_args)
244 config_client = get_stx_client(**os_client_args)
246 raise ValueError('Stx endpoint exception: %s' % msg)
248 raise ValueError('cgtsclient get subcloud client failed')
252 def setStxClient(self, resource_pool_id):
253 systems = self.stxclient.isystem.list()
254 if resource_pool_id == systems[0].uuid:
255 logger.debug('Stx Client not change: %s' % resource_pool_id)
258 subclouds = self.getSubcloudList()
259 for subcloud in subclouds:
260 subcloud_stxclient = self.getSubcloudClient(subcloud.subcloud_id)
261 systems = subcloud_stxclient.isystem.list()
262 # logger.debug('subcloud %s id: %s' %
263 # (systems[0].name, systems[0].uuid))
264 # logger.debug('subcloud: %s' % (systems[0].to_dict()))
265 if resource_pool_id == systems[0].uuid:
266 self.stxclient = subcloud_stxclient
268 def getInstanceInfo(self) -> ocloudModel.StxGenericModel:
269 systems = self.stxclient.isystem.list()
270 logger.debug('systems:' + str(systems[0].to_dict()))
271 # logger.debug('systems[0] uuid: ' + str(systems[0].uuid))
272 return ocloudModel.StxGenericModel(
273 ResourceTypeEnum.OCLOUD, systems[0]) if systems else None
275 def getSubcloudList(self):
276 self.dcclient = self.getDcmanagerClient()
277 subs = self.dcclient.subcloud_manager.list_subclouds()
278 known_subs = [sub for sub in subs if sub.sync_status != 'unknown']
281 def getResourcePoolList(self, **filters) -> List[
282 ocloudModel.StxGenericModel]:
283 systems = self.stxclient.isystem.list()
284 logger.debug('system controller distributed_cloud_role:' +
285 str(systems[0].distributed_cloud_role))
287 if systems[0].distributed_cloud_role is None or \
288 systems[0].distributed_cloud_role != 'systemcontroller':
289 return [ocloudModel.StxGenericModel(
290 ResourceTypeEnum.RESOURCE_POOL,
291 self._respoolconverter(systems[0]))]
294 if config.get_system_controller_as_respool():
295 pools.append(systems[0])
297 subclouds = self.getSubcloudList()
298 logger.debug('subclouds numbers: %s' % len(subclouds))
299 for subcloud in subclouds:
301 subcloud_stxclient = self.getSubcloudClient(
302 subcloud.subcloud_id)
303 systems = subcloud_stxclient.isystem.list()
304 logger.debug('systems:' + str(systems[0].to_dict()))
305 pools.append(systems[0])
306 except Exception as ex:
307 logger.warning('Failed get cgstclient of subcloud %s: %s' %
311 return [ocloudModel.StxGenericModel(
312 ResourceTypeEnum.RESOURCE_POOL,
313 self._respoolconverter(
314 respool)) for respool in pools if respool]
316 def getResourcePoolDetail(self, id):
317 self.setStxClient(id)
318 systems = self.stxclient.isystem.list()
319 logger.debug('systems:' + str(systems[0].to_dict()))
320 return ocloudModel.StxGenericModel(
321 ResourceTypeEnum.RESOURCE_POOL,
322 self._respoolconverter(systems[0])) if systems else None
324 def getPserverList(self, **filters) -> List[ocloudModel.StxGenericModel]:
325 hosts = self.stxclient.ihost.list()
326 logger.debug('host 1:' + str(hosts[0].to_dict()))
327 return [ocloudModel.StxGenericModel(
328 ResourceTypeEnum.PSERVER, self._hostconverter(host))
329 for host in hosts if host and (host.availability == 'available'
330 or host.availability == 'online'
331 or host.availability == 'degraded')]
333 def getPserver(self, id) -> ocloudModel.StxGenericModel:
334 host = self.stxclient.ihost.get(id)
335 logger.debug('host:' + str(host.to_dict()))
336 return ocloudModel.StxGenericModel(
337 ResourceTypeEnum.PSERVER, self._hostconverter(host))
339 def _checkLabelExistOnHost(self, client, label_to_check, host_id,
340 check_value=False) -> bool:
341 labels = client.label.list(host_id)
343 return any(label_to_check['key'] == label.label_key and
344 label_to_check['value'] == label.label_value
347 return any(label_to_check['key'] == label.label_key
350 def _checkLabelExistOnCluster(self, client, label_to_check,
351 check_value=False) -> bool:
352 hosts = client.ihost.list()
354 if self._checkLabelExistOnHost(client, label_to_check,
355 host.uuid, check_value):
358 f"host {host.hostname} has the label "
359 f"{label_to_check['key']} with value "
360 f"{label_to_check['value']}")
363 f"host {host.hostname} has the label "
364 f"{label_to_check['key']}")
368 def _setK8sCapabilities(self, client, k8scluster):
370 label_OS_2chk = {'key': 'OS', 'value': 'low_latency'}
371 if self._checkLabelExistOnCluster(client, label_OS_2chk, True):
372 logger.debug("low latency host inside of the k8s cluster")
373 capabilities[label_OS_2chk['key']] = label_OS_2chk['value']
374 setattr(k8scluster, 'capabilities', json.dumps(capabilities))
377 def getLabelList(self, **filters) -> List[ocloudModel.StxGenericModel]:
378 hostid = filters.get('hostid', None)
379 assert (hostid is not None), 'missing hostid to query label list'
380 labels = self.stxclient.label.list(hostid)
381 return [ocloudModel.StxGenericModel(
382 ResourceTypeEnum.PSERVER_LABEL,
383 self._labelconverter(label)) for label in labels if label]
385 def getK8sList(self, **filters) -> List[ocloudModel.StxGenericModel]:
386 def process_cluster(client, cluster):
387 setattr(cluster, 'cloud_name', systems[0].name)
388 setattr(cluster, 'cloud_uuid', systems[0].uuid)
389 cluster = self._setK8sCapabilities(client, cluster)
390 logger.debug('k8sresources cluster_api_endpoint: ' +
391 str(cluster.cluster_api_endpoint))
392 return ocloudModel.StxGenericModel(ResourceTypeEnum.DMS,
393 self._k8sconverter(cluster),
394 self._k8shasher(cluster))
396 systems = self.stxclient.isystem.list()
397 distributed_cloud_role = systems[0].distributed_cloud_role
399 f'system controller distributed_cloud_role: '
400 f'{distributed_cloud_role}'))
404 if distributed_cloud_role is None or distributed_cloud_role != \
407 [process_cluster(self.stxclient, k8s)
408 for k8s in self.stxclient.kube_cluster.list() if k8s])
411 if config.get_system_controller_as_respool():
413 [process_cluster(self.stxclient, k8s)
414 for k8s in self.stxclient.kube_cluster.list() if k8s])
416 subclouds = self.getSubcloudList()
417 logger.debug(f'subclouds numbers: {len(subclouds)}')
419 for subcloud in subclouds:
421 subcloud_stxclient = self.getSubcloudClient(
422 subcloud.subcloud_id)
423 systems = subcloud_stxclient.isystem.list()
424 k8sclusters = subcloud_stxclient.kube_cluster.list()
425 k8s_list.extend([process_cluster(subcloud_stxclient, k8s)
426 for k8s in k8sclusters if k8s])
427 except Exception as ex:
429 f'Failed to get cgstclient of subcloud '
430 f'{subcloud.name}: {ex}'))
435 def getK8sDetail(self, name) -> ocloudModel.StxGenericModel:
436 def process_k8s_cluster(client, k8s_cluster, cloud_name, cloud_uuid):
437 setattr(k8s_cluster, 'cloud_name', cloud_name)
438 setattr(k8s_cluster, 'cloud_uuid', cloud_uuid)
439 k8s_cluster = self._setK8sCapabilities(client, k8s_cluster)
442 systems = self.stxclient.isystem.list()
443 system_name = systems[0].name
444 system_uuid = systems[0].uuid
447 k8s_clusters = self.stxclient.kube_cluster.list()
448 k8s_cluster = process_k8s_cluster(
449 self.stxclient, k8s_clusters.pop(), system_name)
451 sname = name.split('.')
452 cloud_name = '.'.join(sname[:-1])
455 if cloud_name == system_name:
456 k8s_cluster = process_k8s_cluster(
458 self.stxclient.kube_cluster.get(k8s_name), cloud_name,
461 subclouds = self.getSubcloudList()
463 sub.subcloud_id for sub in subclouds
464 if sub.name == cloud_name)
465 subcloud_stxclient = self.getSubcloudClient(subcloud_id)
466 systems = subcloud_stxclient.isystem.list()
467 system_uuid = systems[0].uuid
468 k8s_cluster = process_k8s_cluster(
470 subcloud_stxclient.kube_cluster.get(k8s_name), cloud_name,
476 logger.debug(f'k8sresource: {k8s_cluster.to_dict()}')
477 return ocloudModel.StxGenericModel(
478 ResourceTypeEnum.DMS, self._k8sconverter(k8s_cluster),
479 self._k8shasher(k8s_cluster))
481 def getCpuList(self, **filters) -> List[ocloudModel.StxGenericModel]:
482 hostid = filters.get('hostid', None)
483 assert (hostid is not None), 'missing hostid to query icpu list'
484 cpulist = self.stxclient.icpu.list(hostid)
485 return [ocloudModel.StxGenericModel(
486 ResourceTypeEnum.PSERVER_CPU,
487 self._cpuconverter(cpures)) for cpures in cpulist if cpures]
489 def getCpu(self, id) -> ocloudModel.StxGenericModel:
490 cpuinfo = self.stxclient.icpu.get(id)
491 return ocloudModel.StxGenericModel(
492 ResourceTypeEnum.PSERVER_CPU, self._cpuconverter(cpuinfo))
494 def getMemList(self, **filters) -> List[ocloudModel.StxGenericModel]:
495 hostid = filters.get('hostid', None)
496 assert (hostid is not None), 'missing hostid to query imem list'
497 memlist = self.stxclient.imemory.list(hostid)
498 return [ocloudModel.StxGenericModel(
499 ResourceTypeEnum.PSERVER_RAM,
500 self._memconverter(memories)) for memories in memlist if memories]
502 def getMem(self, id) -> ocloudModel.StxGenericModel:
503 meminfo = self.stxclient.imemory.get(id)
504 return ocloudModel.StxGenericModel(
505 ResourceTypeEnum.PSERVER_RAM, self._memconverter(meminfo))
507 def getEthernetList(self, **filters) -> List[ocloudModel.StxGenericModel]:
508 hostid = filters.get('hostid', None)
509 assert (hostid is not None), 'missing hostid to query port list'
510 ethlist = self.stxclient.ethernet_port.list(hostid)
511 return [ocloudModel.StxGenericModel(
512 ResourceTypeEnum.PSERVER_ETH,
513 self._ethconverter(eth)) for eth in ethlist if eth]
515 def getEthernet(self, id) -> ocloudModel.StxGenericModel:
516 ethinfo = self.stxclient.ethernet_port.get(id)
517 return ocloudModel.StxGenericModel(
518 ResourceTypeEnum.PSERVER_ETH, self._ethconverter(ethinfo))
520 def getIfList(self, **filters) -> List[ocloudModel.StxGenericModel]:
521 hostid = filters.get('hostid', None)
522 assert (hostid is not None), 'missing hostid to query iinterface list'
523 iflist = self.stxclient.iinterface.list(hostid)
524 return [ocloudModel.StxGenericModel(
525 ResourceTypeEnum.PSERVER_IF,
526 self._ifconverter(ifs)) for ifs in iflist if ifs]
528 def getIf(self, id) -> ocloudModel.StxGenericModel:
529 ifinfo = self.stxclient.iinterface.get(id)
530 return ocloudModel.StxGenericModel(
531 ResourceTypeEnum.PSERVER_IF, self._ifconverter(ifinfo))
533 def getPortList(self, **filters) -> List[ocloudModel.StxGenericModel]:
534 ifid = filters.get('interfaceid', None)
535 assert (ifid is not None), 'missing interface id to query port list'
536 portlist = self.stxclient.iinterface.list_ports(ifid)
537 return [ocloudModel.StxGenericModel(
538 ResourceTypeEnum.PSERVER_IF_PORT,
539 port) for port in portlist if port]
541 def getPort(self, id) -> ocloudModel.StxGenericModel:
542 portinfo = self.stxclient.port.get(id)
543 return ocloudModel.StxGenericModel(
544 ResourceTypeEnum.PSERVER_IF_PORT, portinfo)
546 def getDeviceList(self, **filters) -> List[ocloudModel.StxGenericModel]:
547 hostid = filters.get('hostid', None)
548 assert (hostid is not None), 'missing hostid to query pci device list'
549 pci_dev_list = self.stxclient.pci_device.list(hostid)
550 return [ocloudModel.StxGenericModel(
551 ResourceTypeEnum.PSERVER_PCI_DEV,
552 self._devconverter(pci_dev))
553 for pci_dev in pci_dev_list if pci_dev]
555 def getDevice(self, id) -> ocloudModel.StxGenericModel:
556 pciinfo = self.stxclient.pci_device.get(id)
557 return ocloudModel.StxGenericModel(
558 ResourceTypeEnum.PSERVER_PCI_DEV, self._devconverter(pciinfo))
560 def getAcceleratorList(self, **filters) -> \
561 List[ocloudModel.StxGenericModel]:
562 hostid = filters.get('hostid', None)
563 assert (hostid is not None), 'missing hostid to query accelerator list'
564 pci_dev_list = self.stxclient.pci_device.list(hostid)
566 for pci_dev in pci_dev_list:
567 if pci_dev.pvendor_id in ['8086']:
568 if pci_dev.pdevice_id in ['0d5c', '0d5d']:
569 logger.info('Accelerator vendor ID: {}, device ID: {}'.
570 format(pci_dev.pvendor_id, pci_dev.pdevice_id))
571 acc_list.append(ocloudModel.StxGenericModel(
572 ResourceTypeEnum.PSERVER_ACC,
573 self._devconverter(pci_dev)))
576 def getAccelerator(self, id) -> ocloudModel.StxGenericModel:
577 pciinfo = self.stxclient.pci_device.get(id)
578 return ocloudModel.StxGenericModel(
579 ResourceTypeEnum.PSERVER_ACC, self._devconverter(pciinfo))
581 def _getIsystems(self):
582 return self.stxclient.isystem.list()
584 def _getIsystem(self, id=None):
586 return self.stxclient.isystem.get(id)
588 isystems = self.stxclient.isystem.list()
589 if len(isystems) != 1 and not id:
590 raise Exception('No system uuid was provided and '
591 'more than one system exists in the account.')
595 def _respoolconverter(res_pool):
596 setattr(res_pool, 'name', res_pool.region_name)
600 def _hostconverter(host):
602 "hostname", "personality", "id", "mgmt_ip", "mgmt_mac",
603 "software_load", "capabilities",
604 "operational", "availability", "administrative",
605 "boot_device", "rootfs_device", "install_state", "subfunctions",
606 "clock_synchronization", "max_cpu_mhz_allowed"
608 content = host.to_dict()
610 filter(lambda item: item[0] in selected_keys, content.items()))
611 setattr(host, 'filtered', filtered)
612 setattr(host, 'name', host.hostname)
616 def _labelconverter(label):
618 "uuid", "label_key", "label_value", "host_uuid"
620 content = label.to_dict()
623 filter(lambda item: item[0] in selected_keys, content.items()))
624 setattr(label, 'filtered', filtered)
625 setattr(label, 'name', label.uuid.split(
626 '-', 1)[0] + '-label-' + label.label_key)
627 setattr(label, 'updated_at', None)
628 setattr(label, 'created_at', None)
632 def _cpuconverter(cpu):
634 "cpu", "core", "thread", "allocated_function", "numa_node",
635 "cpu_model", "cpu_family"
637 content = cpu.to_dict()
639 filter(lambda item: item[0] in selected_keys, content.items()))
640 setattr(cpu, 'filtered', filtered)
641 setattr(cpu, 'name', cpu.ihost_uuid.split(
642 '-', 1)[0] + '-cpu-'+str(cpu.cpu))
646 def _memconverter(mem):
648 "memtotal_mib", "memavail_mib", "vm_hugepages_use_1G",
649 "vm_hugepages_possible_1G", "hugepages_configured",
650 "vm_hugepages_avail_1G", "vm_hugepages_nr_1G",
651 "vm_hugepages_nr_4K", "vm_hugepages_nr_2M",
652 "vm_hugepages_possible_2M", "vm_hugepages_avail_2M",
653 "platform_reserved_mib", "numa_node"
655 content = mem.to_dict()
657 filter(lambda item: item[0] in selected_keys, content.items()))
658 setattr(mem, 'filtered', filtered)
659 setattr(mem, 'name', mem.ihost_uuid.split('-', 1)[0] +
660 '-mem-node-'+str(mem.numa_node))
664 def _ethconverter(eth):
666 "name", "namedisplay", "dev_id", "pdevice", "capabilities",
667 "type", "driver", "mac", "numa_node",
668 "pciaddr", "pclass", "psvendor", "psdevice",
669 "sriov_totalvfs", "sriov_numvfs", "dpdksupport",
670 "sriov_vf_driver", "sriov_vf_pdevice_id", "interface_uuid"
672 content = eth.to_dict()
674 filter(lambda item: item[0] in selected_keys, content.items()))
675 setattr(eth, 'filtered', filtered)
676 setattr(eth, 'name', eth.host_uuid.split('-', 1)[0] + '-'+eth.name)
677 setattr(eth, 'updated_at', None)
678 setattr(eth, 'created_at', None)
682 def _ifconverter(ifs):
684 "ifname", "iftype", "imac", "vlan_id", "imtu",
685 "ifclass", "uses", "max_tx_rate",
686 "sriov_vf_driver", "sriov_numvfs", "ptp_role"
688 content = ifs.to_dict()
690 filter(lambda item: item[0] in selected_keys, content.items()))
691 setattr(ifs, 'filtered', filtered)
692 setattr(ifs, 'name', ifs.ihost_uuid.split('-', 1)[0] + '-'+ifs.ifname)
693 setattr(ifs, 'updated_at', None)
694 setattr(ifs, 'created_at', None)
698 def _devconverter(dev):
700 "name", "pdevice", "pciaddr", "pvendor_id", "pvendor",
701 "pclass_id", "pclass", "psvendor", "psdevice",
702 "sriov_totalvfs", "sriov_numvfs", "numa_node"
704 content = dev.to_dict()
706 filter(lambda item: item[0] in selected_keys, content.items()))
707 setattr(dev, 'filtered', filtered)
708 setattr(dev, 'name', dev.host_uuid.split('-', 1)[0] + '-'+dev.name)
712 def _k8sconverter(cluster):
713 setattr(cluster, 'name', cluster.cloud_name +
714 '.' + cluster.cluster_name)
715 setattr(cluster, 'uuid',
716 uuid.uuid3(uuid.NAMESPACE_URL, cluster.cloud_uuid))
717 setattr(cluster, 'updated_at', None)
718 setattr(cluster, 'created_at', None)
719 setattr(cluster, 'events', [])
720 logger.debug('k8s cluster name/uuid:' +
721 cluster.name + '/' + str(cluster.uuid))
725 def _k8shasher(cluster):
726 return str(hash((cluster.cluster_name, cluster.cloud_name,
727 cluster.cluster_api_endpoint, cluster.admin_user,
728 cluster.capabilities)))