本文整理汇总了Python中utils.platform.Platform.is_nomad方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.is_nomad方法的具体用法?Python Platform.is_nomad怎么用?Python Platform.is_nomad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.platform.Platform
的用法示例。
在下文中一共展示了Platform.is_nomad方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_nomad [as 别名]
def __init__(self, agentConfig):
try:
self.config_store = get_config_store(agentConfig=agentConfig)
except Exception as e:
log.error('Failed to instantiate the config store client. '
'Auto-config only will be used. %s' % str(e))
agentConfig['sd_config_backend'] = None
self.config_store = get_config_store(agentConfig=agentConfig)
self.dockerutil = DockerUtil(config_store=self.config_store)
self.docker_client = self.dockerutil.client
if Platform.is_k8s():
try:
self.kubeutil = KubeUtil()
except Exception as ex:
self.kubeutil = None
log.error("Couldn't instantiate the kubernetes client, "
"subsequent kubernetes calls will fail as well. Error: %s" % str(ex))
if Platform.is_nomad():
self.nomadutil = NomadUtil()
elif Platform.is_ecs_instance():
self.ecsutil = ECSUtil()
self.VAR_MAPPING = {
'host': self._get_host_address,
'port': self._get_port,
'tags': self._get_additional_tags,
}
AbstractSDBackend.__init__(self, agentConfig)
示例2: _get_events
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_nomad [as 别名]
def _get_events(self):
"""Get the list of events."""
events, changed_container_ids = self.docker_util.get_events()
if not self._disable_net_metrics:
self._invalidate_network_mapping_cache(events)
if changed_container_ids and self._service_discovery:
get_sd_backend(self.agentConfig).update_checks(changed_container_ids)
if changed_container_ids:
self.metadata_collector.invalidate_cache(events)
if Platform.is_nomad():
self.nomadutil.invalidate_cache(events)
elif Platform.is_ecs_instance():
self.ecsutil.invalidate_cache(events)
return events
示例3: get_tags
# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_nomad [as 别名]
def get_tags(self, state, c_id):
"""Extract useful tags from docker or platform APIs. These are collected by default."""
tags = []
ctr = state.inspect_container(c_id)
# TODO: extend with labels, container ID, etc.
tags.append('docker_image:%s' % self.dockerutil.image_name_extractor(ctr))
tags.append('image_name:%s' % self.dockerutil.image_tag_extractor(ctr, 0)[0])
tags.append('image_tag:%s' % self.dockerutil.image_tag_extractor(ctr, 1)[0])
if Platform.is_k8s():
pod_metadata = state.get_kube_config(c_id, 'metadata')
if pod_metadata is None:
log.warning("Failed to fetch pod metadata for container %s."
" Kubernetes tags may be missing." % c_id[:12])
return []
# get pod labels
kube_labels = pod_metadata.get('labels', {})
for label, value in kube_labels.iteritems():
tags.append('%s:%s' % (label, value))
# get kubernetes namespace
namespace = pod_metadata.get('namespace')
tags.append('kube_namespace:%s' % namespace)
# add creator tags
creator_tags = self.kubeutil.get_pod_creator_tags(pod_metadata)
tags.extend(creator_tags)
# add services tags
services = self.kubeutil.match_services_for_pod(pod_metadata)
for s in services:
if s is not None:
tags.append('kube_service:%s' % s)
elif Platform.is_swarm():
c_labels = state.inspect_container(c_id).get('Config', {}).get('Labels', {})
swarm_svc = c_labels.get(SWARM_SVC_LABEL)
if swarm_svc:
tags.append('swarm_service:%s' % swarm_svc)
elif Platform.is_rancher():
c_inspect = state.inspect_container(c_id)
service_name = c_inspect.get('Config', {}).get('Labels', {}).get(RANCHER_SVC_NAME)
stack_name = c_inspect.get('Config', {}).get('Labels', {}).get(RANCHER_STACK_NAME)
container_name = c_inspect.get('Config', {}).get('Labels', {}).get(RANCHER_CONTAINER_NAME)
if service_name:
tags.append('rancher_service:%s' % service_name)
if stack_name:
tags.append('rancher_stack:%s' % stack_name)
if container_name:
tags.append('rancher_container:%s' % container_name)
elif Platform.is_nomad():
nomad_tags = self.nomadutil.extract_container_tags(state.inspect_container(c_id))
if nomad_tags:
tags.extend(nomad_tags)
elif Platform.is_ecs_instance():
ecs_tags = self.ecsutil.extract_container_tags(state.inspect_container(c_id))
tags.extend(ecs_tags)
return tags