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


Python EC2.get_metadata方法代码示例

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


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

示例1: _get_hostname_metadata

# 需要导入模块: from util import EC2 [as 别名]
# 或者: from util.EC2 import get_metadata [as 别名]
    def _get_hostname_metadata(self):
        """
        Returns a dictionnary that contains hostname metadata.
        """
        metadata = EC2.get_metadata(self.agentConfig)
        if metadata.get('hostname'):
            metadata['ec2-hostname'] = metadata.get('hostname')
            del metadata['hostname']

        if self.agentConfig.get('hostname'):
            metadata['agent-hostname'] = self.agentConfig.get('hostname')
        else:
            try:
                metadata["socket-hostname"] = socket.gethostname()
            except Exception:
                pass
        try:
            metadata["socket-fqdn"] = socket.getfqdn()
        except Exception:
            pass

        metadata["hostname"] = self.hostname
        metadata["timezones"] = sanitize_tzname(time.tzname)

        # Add cloud provider aliases
        host_aliases = GCE.get_host_aliases(self.agentConfig)
        if host_aliases:
            metadata['host_aliases'] = host_aliases

        return metadata
开发者ID:p1r4te,项目名称:dd-agent,代码行数:32,代码来源:collector.py

示例2: test_metadata

# 需要导入模块: from util import EC2 [as 别名]
# 或者: from util.EC2 import get_metadata [as 别名]
 def test_metadata(self):
     # Test gathering metadata from ec2
     start = time.time()
     d = EC2.get_metadata()
     end = time.time()
     assert type(d) == types.DictType
     # Either we're on ec2 or we're not (at least 7 attributes expected)
     assert len(d) == 0 or len(d) >= 7, d
     if "instance-id" in d:
         assert d["instance-id"].startswith("i-"), d
         assert d["hostname"].startswith("i-") or d["hostname"].startswith("domU-"), d
     assert end - start <= 1.1, "It took %s seconds to get ec2 metadata" % (end-start)
开发者ID:dwradcliffe,项目名称:dd-agent,代码行数:14,代码来源:test_ec2.py

示例3: test_metadata

# 需要导入模块: from util import EC2 [as 别名]
# 或者: from util.EC2 import get_metadata [as 别名]
 def test_metadata(self):
     # Reset metadata just to be sure
     EC2.metadata = {}
     # Test gathering metadata from ec2
     start = time.time()
     d = EC2.get_metadata({'collect_instance_metadata': True})
     end = time.time()
     assert type(d) == types.DictType
     # Either we're on ec2 or we're not (at least 7 attributes expected)
     assert len(d) == 0 or len(d) >= 7, d
     if "instance-id" in d:
         assert d["instance-id"].startswith("i-"), d
     assert end - start <= 1.1, "It took %s seconds to get ec2 metadata" % (end-start)
开发者ID:AquaBindi,项目名称:dd-agent,代码行数:15,代码来源:test_ec2.py

示例4: test_metadata

# 需要导入模块: from util import EC2 [as 别名]
# 或者: from util.EC2 import get_metadata [as 别名]
 def test_metadata(self):
     # Skip this step on travis
     if os.environ.get("TRAVIS", False):
         return
     # Test gathering metadata from ec2
     start = time.time()
     d = EC2.get_metadata({"collect_instance_metadata": True})
     end = time.time()
     assert type(d) == types.DictType
     # Either we're on ec2 or we're not (at least 7 attributes expected)
     assert len(d) == 0 or len(d) >= 7, d
     if "instance-id" in d:
         assert d["instance-id"].startswith("i-"), d
         assert d["hostname"].startswith("i-") or d["hostname"].startswith("domU-"), d
     assert end - start <= 1.1, "It took %s seconds to get ec2 metadata" % (end - start)
开发者ID:Erni,项目名称:dd-agent,代码行数:17,代码来源:test_ec2.py

示例5: _get_metadata

# 需要导入模块: from util import EC2 [as 别名]
# 或者: from util.EC2 import get_metadata [as 别名]
    def _get_metadata(self):
        metadata = EC2.get_metadata()
        if metadata.get('hostname'):
            metadata['ec2-hostname'] = metadata.get('hostname')
            del metadata['hostname']

        if self.agentConfig.get('hostname'):
            metadata['agent-hostname'] = self.agentConfig.get('hostname')
        else:
            try:
                metadata["socket-hostname"] = socket.gethostname()
            except Exception:
                pass
        try:
            metadata["socket-fqdn"] = socket.getfqdn()
        except Exception:
            pass

        metadata["hostname"] = get_hostname()

        return metadata
开发者ID:arthurnn,项目名称:dd-agent,代码行数:23,代码来源:collector.py

示例6: _get_hostname_metadata

# 需要导入模块: from util import EC2 [as 别名]
# 或者: from util.EC2 import get_metadata [as 别名]
    def _get_hostname_metadata(self):
        """
        Returns a dictionnary that contains hostname metadata.
        """
        metadata = EC2.get_metadata(self.agentConfig)
        if metadata.get('hostname'):
            metadata['ec2-hostname'] = metadata.get('hostname')
            del metadata['hostname']

        if self.agentConfig.get('hostname'):
            metadata['agent-hostname'] = self.agentConfig.get('hostname')
        else:
            try:
                metadata["socket-hostname"] = socket.gethostname()
            except Exception:
                pass
        try:
            metadata["socket-fqdn"] = socket.getfqdn()
        except Exception:
            pass

        metadata["hostname"] = get_hostname()

        return metadata
开发者ID:ermandoser,项目名称:dd-agent,代码行数:26,代码来源:collector.py


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