本文整理汇总了Python中utils.dockerutil.DockerUtil.is_dockerized方法的典型用法代码示例。如果您正苦于以下问题:Python DockerUtil.is_dockerized方法的具体用法?Python DockerUtil.is_dockerized怎么用?Python DockerUtil.is_dockerized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.dockerutil.DockerUtil
的用法示例。
在下文中一共展示了DockerUtil.is_dockerized方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh_ecs_tags
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import is_dockerized [as 别名]
def refresh_ecs_tags(self):
ecs_config = self.docker_client.inspect_container('ecs-agent')
ip = ecs_config.get('NetworkSettings', {}).get('IPAddress')
ports = ecs_config.get('NetworkSettings', {}).get('Ports')
port = ports.keys()[0].split('/')[0] if ports else None
if not ip:
port = ECS_INTROSPECT_DEFAULT_PORT
if DockerUtil.is_dockerized() and self.docker_gateway():
ip = self.docker_gateway
else:
ip = "localhost"
ecs_tags = {}
try:
if ip and port:
tasks = requests.get('http://%s:%s/v1/tasks' % (ip, port)).json()
for task in tasks.get('Tasks', []):
for container in task.get('Containers', []):
tags = ['task_name:%s' % task['Family'], 'task_version:%s' % task['Version']]
ecs_tags[container['DockerId']] = tags
except (requests.exceptions.HTTPError, requests.exceptions.HTTPError) as e:
self.log.warning("Unable to collect ECS task names: %s" % e)
self.ecs_tags = ecs_tags
示例2: get_hostname
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import is_dockerized [as 别名]
def get_hostname(config=None):
"""
Get the canonical host name this agent should identify as. This is
the authoritative source of the host name for the agent.
Tries, in order:
* agent config (datadog.conf, "hostname:")
* 'hostname -f' (on unix)
* socket.gethostname()
"""
from utils.dockerutil import DockerUtil
hostname = None
# first, try the config
if config is None:
from config import get_config
config = get_config(parse_args=True)
config_hostname = config.get('hostname')
if config_hostname and is_valid_hostname(config_hostname):
return config_hostname
# Try to get GCE instance name
if hostname is None:
gce_hostname = GCE.get_hostname(config)
if gce_hostname is not None:
if is_valid_hostname(gce_hostname):
return gce_hostname
# Try to get the docker hostname
if hostname is None and DockerUtil.is_dockerized():
docker_util = DockerUtil(agentConfig=config)
docker_hostname = docker_util.get_hostname()
if docker_hostname is not None and is_valid_hostname(docker_hostname):
hostname = docker_hostname
# then move on to os-specific detection
if hostname is None:
def _get_hostname_unix():
try:
# try fqdn
out, _, rtcode = get_subprocess_output(['/bin/hostname', '-f'], log)
if rtcode == 0:
return out.strip()
except Exception:
return None
os_name = get_os()
if os_name in ['mac', 'freebsd', 'linux', 'solaris']:
unix_hostname = _get_hostname_unix()
if unix_hostname and is_valid_hostname(unix_hostname):
hostname = unix_hostname
# if we have an ec2 default hostname, see if there's an instance-id available
if (Platform.is_ecs_instance()) or (hostname is not None and EC2.is_default(hostname)):
instanceid = EC2.get_instance_id(config)
if instanceid:
hostname = instanceid
# fall back on socket.gethostname(), socket.getfqdn() is too unreliable
if hostname is None:
try:
socket_hostname = socket.gethostname()
except socket.error:
socket_hostname = None
if socket_hostname and is_valid_hostname(socket_hostname):
hostname = socket_hostname
if hostname is None:
log.critical('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
raise Exception('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
else:
return hostname
示例3: get_hostname
# 需要导入模块: from utils.dockerutil import DockerUtil [as 别名]
# 或者: from utils.dockerutil.DockerUtil import is_dockerized [as 别名]
def get_hostname(config=None):
"""
Get the canonical host name this agent should identify as. This is
the authoritative source of the host name for the agent.
Tries, in order:
* agent config (datadog.conf, "hostname:")
* 'hostname -f' (on unix)
* socket.gethostname()
"""
hostname = None
# first, try the config
if config is None:
from config import get_config
config = get_config(parse_args=True)
config_hostname = config.get('hostname')
if config_hostname and is_valid_hostname(config_hostname):
return config_hostname
# Try to get GCE instance name
if hostname is None:
gce_hostname = GCE.get_hostname(config)
if gce_hostname is not None:
if is_valid_hostname(gce_hostname):
return gce_hostname
# Try to get the docker hostname
docker_util = DockerUtil()
if hostname is None and docker_util.is_dockerized():
docker_hostname = docker_util.get_hostname()
if docker_hostname is not None and is_valid_hostname(docker_hostname):
return docker_hostname
# then move on to os-specific detection
if hostname is None:
def _get_hostname_unix():
try:
# try fqdn
out, _, rtcode = get_subprocess_output(['/bin/hostname', '-f'], log)
if rtcode == 0:
return out.strip()
except Exception:
return None
os_name = get_os()
if os_name in ['mac', 'freebsd', 'linux', 'solaris']:
unix_hostname = _get_hostname_unix()
if unix_hostname and is_valid_hostname(unix_hostname):
hostname = unix_hostname
# if the host is an ECS worker, or has an EC2 hostname
# or it's a windows machine and the EC2 config service folder exists
# try and find an EC2 instance ID
if (Platform.is_ecs_instance()) or \
(hostname is not None and True in [hostname.lower().startswith(p) for p in [u'ip-', u'domu']]) or \
(os_name == 'windows' and os.path.exists('C:\Program Files\Amazon\Ec2ConfigService')):
instanceid = EC2.get_instance_id(config)
if instanceid:
hostname = instanceid
# fall back on socket.gethostname(), socket.getfqdn() is too unreliable
if hostname is None:
try:
socket_hostname = socket.gethostname()
except socket.error:
socket_hostname = None
if socket_hostname and is_valid_hostname(socket_hostname):
hostname = socket_hostname
if hostname is None:
log.critical('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
raise Exception('Unable to reliably determine host name. You can define one in datadog.conf or in your hosts file')
else:
return hostname