+ def _checkLabelExistOnHost(self, label_key, hostid) -> bool:
+ labels = self.stxclient.label.list(hostid)
+ return any(label_key == label.label_key for label in labels)
+
+ def _checkLabelExistOnCluster(self, label_key) -> bool:
+ hosts = self.stxclient.ihost.list()
+
+ def find_label_on_host():
+ result = next(
+ (
+ (host, True)
+ for host in hosts
+ if self._checkLabelExistOnHost(label_key, host.uuid)
+ ),
+ (None, False),
+ )
+
+ if result[1]:
+ logger.info("host %s has the label %s" %
+ (result[0].hostname, label_key))
+
+ return result[1]
+
+ return find_label_on_host()
+
+ # return any(self._checkLabelExistOnHost(label_key, host.uuid) for host
+ # in hosts)
+
+ def _setK8sCapabilities(self, k8scluster):
+ capabilities = {}
+ if self._checkLabelExistOnCluster('OS'):
+ logger.debug("low latency host inside of the cluster")
+ capabilities['OS'] = 'low_latency'
+ 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]
+