当前位置: 首页>>代码示例>>Python>>正文


Python Platform.is_containerized方法代码示例

本文整理汇总了Python中utils.platform.Platform.is_containerized方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.is_containerized方法的具体用法?Python Platform.is_containerized怎么用?Python Platform.is_containerized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.platform.Platform的用法示例。


在下文中一共展示了Platform.is_containerized方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_ecs_address

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_containerized [as 别名]
    def _get_ecs_address(self):
        """Detect how to connect to the ecs-agent"""
        ecs_config = self.docker_util.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 self._is_ecs_agent_local():
                ip = "localhost"
            elif Platform.is_containerized() and self.docker_gateway:
                ip = self.docker_gateway
            else:
                raise Exception("Unable to determine ecs-agent IP address")

        return ip, port
开发者ID:netsil,项目名称:dd-agent,代码行数:18,代码来源:ecsutil.py

示例2: refresh_ecs_tags

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_containerized [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 Platform.is_containerized() 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
开发者ID:Wattpad,项目名称:dd-agent,代码行数:26,代码来源:docker_daemon.py

示例3: get_hostname

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_containerized [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
    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 Platform.is_containerized():

        # First we try from the Docker API
        docker_util = DockerUtil()
        docker_hostname = docker_util.get_hostname(use_default_gw=False)
        if docker_hostname is not None and is_valid_hostname(docker_hostname):
            hostname = docker_hostname

        elif Platform.is_k8s(): # Let's try from the kubelet
            kube_util = KubeUtil()
            _, kube_hostname = kube_util.get_node_info()
            if kube_hostname is not None and is_valid_hostname(kube_hostname):
                hostname = kube_hostname

    # then move on to os-specific detection
    if hostname is None:
        if Platform.is_unix() or Platform.is_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')

    return hostname
开发者ID:Everlane,项目名称:dd-agent,代码行数:71,代码来源:hostname.py

示例4: get_hostname

# 需要导入模块: from utils.platform import Platform [as 别名]
# 或者: from utils.platform.Platform import is_containerized [as 别名]
+++ utils/hostname.py
@@ -9,8 +9,6 @@ import socket
 
 # project
 from utils.cloud_metadata import EC2, GCE
-from utils.dockerutil import DockerUtil
-from utils.kubeutil import KubeUtil
 from utils.platform import Platform
 from utils.subprocess_output import get_subprocess_output
 
@@ -72,21 +70,6 @@ def get_hostname(config=None):
         if is_valid_hostname(gce_hostname):
             return gce_hostname
 
-    # Try to get the docker hostname
-    if Platform.is_containerized():
-
-        # First we try from the Docker API
-        docker_util = DockerUtil()
-        docker_hostname = docker_util.get_hostname(use_default_gw=False)
-        if docker_hostname is not None and is_valid_hostname(docker_hostname):
-            hostname = docker_hostname
-
-        elif Platform.is_k8s(): # Let's try from the kubelet
-            kube_util = KubeUtil()
-            _, kube_hostname = kube_util.get_node_info()
-            if kube_hostname is not None and is_valid_hostname(kube_hostname):
-                hostname = kube_hostname
-
     # then move on to os-specific detection
     if hostname is None:
开发者ID:urosgruber,项目名称:dd-agent-FreeBSD,代码行数:33,代码来源:patch-utils_hostname.py


注:本文中的utils.platform.Platform.is_containerized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。