+ 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 _setK8sCapabilities(self, client, k8scluster):
+ 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']
+ setattr(k8scluster, 'capabilities', json.dumps(capabilities))
+ 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]
+