+ def _checkLabelExistOnHost(self, client, label_to_check, host_id,
+ check_value=False) -> bool:
+ labels = client.label.list(host_id)
+ if check_value:
+ return any(label_to_check['key'] == label.label_key and
+ label_to_check['value'] == label.label_value
+ for label in labels)
+ else:
+ return any(label_to_check['key'] == label.label_key
+ for label in labels)
+
+ def _checkLabelExistOnCluster(self, client, label_to_check,
+ check_value=False) -> bool:
+ hosts = client.ihost.list()
+ for host in hosts:
+ if self._checkLabelExistOnHost(client, label_to_check,
+ host.uuid, check_value):
+ if check_value:
+ logger.info(
+ f"host {host.hostname} has the label "
+ f"{label_to_check['key']} with value "
+ f"{label_to_check['value']}")
+ else:
+ logger.info(
+ f"host {host.hostname} has the label "
+ f"{label_to_check['key']}")
+ return True
+ return False
+
+ def _getK8sNodes(self, k8sclient):
+ return k8sclient.list_node()
+
+ def _getK8sNodeDetail(self, k8sclient, node_name):
+ return k8sclient.read_node(name=node_name)
+
+ def _getK8sCapabilities(self, k8s_client):
+ k8s_capabilities = {}
+ nodes = self._getK8sNodes(k8s_client)
+ for node in nodes.items:
+ logger.debug(f'k8s node {node.metadata.name} allocatable: '
+ f'{node.status.allocatable}')
+ for allocatable in node.status.allocatable:
+ if allocatable.startswith('intel.com/pci_sriov_net_'):
+ k8s_capabilities[f'{node.metadata.name}_sriov'] = True
+ if allocatable == 'windriver.com/isolcpus':
+ k8s_capabilities[f'{node.metadata.name}_isolcpus'] = True
+ return k8s_capabilities
+
+ def _setK8sCapabilities(self, k8scluster, client, k8s_client):
+ capabilities = {}
+ label_OS_2chk = {'key': 'OS', 'value': 'low_latency'}
+ if self._checkLabelExistOnCluster(client, label_OS_2chk, True):
+ logger.debug("low latency host inside of the k8s cluster")
+ capabilities[label_OS_2chk['key']] = label_OS_2chk['value']
+
+ # Add Kubernetes capabilities
+ k8s_capabilities = self._getK8sCapabilities(k8s_client)
+ capabilities.update(k8s_capabilities)
+
+ setattr(k8scluster, 'capabilities', json.dumps(capabilities))
+ return k8scluster
+
+ def _getK8sCapacity(self, k8s_client):
+ k8s_capacity = {}
+ nodes = self._getK8sNodes(k8s_client)
+ for node in nodes.items:
+ logger.debug(f'k8s node {node.metadata.name} capacity: '
+ f'{node.status.capacity}')
+ for key, value in node.status.capacity.items():
+ k8s_capacity[f'{node.metadata.name}_{key}'] = value
+ return k8s_capacity
+
+ def _setK8sCapacity(self, k8scluster, client, k8s_client):
+ capacity = {}
+
+ # Add Kubernetes capacity
+ k8s_capacity = self._getK8sCapacity(k8s_client)
+ capacity.update(k8s_capacity)
+
+ setattr(k8scluster, 'capacity', json.dumps(capacity))
+ return k8scluster
+
+ def getLabelList(self, **filters) -> List[ocloudModel.StxGenericModel]:
+ hostid = filters.get('hostid', None)
+ assert (hostid is not None), 'missing hostid to query label list'
+ labels = self.stxclient.label.list(hostid)
+ return [ocloudModel.StxGenericModel(
+ ResourceTypeEnum.PSERVER_LABEL,
+ self._labelconverter(label)) for label in labels if label]
+