本文整理汇总了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
示例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)
示例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)
示例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)
示例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
示例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