summaryrefslogtreecommitdiff
path: root/cloudinit/ec2_utils.py
diff options
context:
space:
mode:
authorAndrew Jorgensen <ajorgens@amazon.com>2017-11-27 21:54:09 +0000
committerScott Moser <smoser@ubuntu.com>2017-12-11 18:18:08 -0500
commit703241a3c50f2cfec21e7c8e90616c3378ebbea2 (patch)
treec62cb25d76ca784c953a23ffa9c0f80db17b4b08 /cloudinit/ec2_utils.py
parentbd0ffd1e115c4f895c82e1115f1f586849925d88 (diff)
downloadvyos-cloud-init-703241a3c50f2cfec21e7c8e90616c3378ebbea2.tar.gz
vyos-cloud-init-703241a3c50f2cfec21e7c8e90616c3378ebbea2.zip
ec2: Use instance-identity doc for region and instance-id
The instance identity document is a better source for region information, partly because region isn't actually in meta-data at all, only availability-zone, which happens to be named similarly. Reviewed-by: Ethan Faust <efaust@amazon.com> Reviewed-by: Cyle Riggs <cyler@amazon.com> Reviewed-by: Tom Kirchner <tjk@amazon.com> Reviewed-by: Matt Nierzwicki <nierzwic@amazon.com> [ajorgens@amazon.com: rebase onto 0.7.9] [ajorgens@amazon.com: changes per merge proposal discussions]
Diffstat (limited to 'cloudinit/ec2_utils.py')
-rw-r--r--cloudinit/ec2_utils.py39
1 files changed, 30 insertions, 9 deletions
diff --git a/cloudinit/ec2_utils.py b/cloudinit/ec2_utils.py
index 723d6bd6..d6c61e4c 100644
--- a/cloudinit/ec2_utils.py
+++ b/cloudinit/ec2_utils.py
@@ -1,6 +1,8 @@
# Copyright (C) 2012 Yahoo! Inc.
+# Copyright (C) 2014 Amazon.com, Inc. or its affiliates.
#
# Author: Joshua Harlow <harlowja@yahoo-inc.com>
+# Author: Andrew Jorgensen <ajorgens@amazon.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
@@ -164,14 +166,11 @@ def get_instance_userdata(api_version='latest',
return user_data
-def get_instance_metadata(api_version='latest',
- metadata_address='http://169.254.169.254',
- ssl_details=None, timeout=5, retries=5,
- leaf_decoder=None):
- md_url = url_helper.combine_url(metadata_address, api_version)
- # Note, 'meta-data' explicitly has trailing /.
- # this is required for CloudStack (LP: #1356855)
- md_url = url_helper.combine_url(md_url, 'meta-data/')
+def _get_instance_metadata(tree, api_version='latest',
+ metadata_address='http://169.254.169.254',
+ ssl_details=None, timeout=5, retries=5,
+ leaf_decoder=None):
+ md_url = url_helper.combine_url(metadata_address, api_version, tree)
caller = functools.partial(util.read_file_or_url,
ssl_details=ssl_details, timeout=timeout,
retries=retries)
@@ -189,7 +188,29 @@ def get_instance_metadata(api_version='latest',
md = {}
return md
except Exception:
- util.logexc(LOG, "Failed fetching metadata from url %s", md_url)
+ util.logexc(LOG, "Failed fetching %s from url %s", tree, md_url)
return {}
+
+def get_instance_metadata(api_version='latest',
+ metadata_address='http://169.254.169.254',
+ ssl_details=None, timeout=5, retries=5,
+ leaf_decoder=None):
+ # Note, 'meta-data' explicitly has trailing /.
+ # this is required for CloudStack (LP: #1356855)
+ return _get_instance_metadata(tree='meta-data/', api_version=api_version,
+ metadata_address=metadata_address,
+ ssl_details=ssl_details, timeout=timeout,
+ retries=retries, leaf_decoder=leaf_decoder)
+
+
+def get_instance_identity(api_version='latest',
+ metadata_address='http://169.254.169.254',
+ ssl_details=None, timeout=5, retries=5,
+ leaf_decoder=None):
+ return _get_instance_metadata(tree='dynamic/instance-identity',
+ api_version=api_version,
+ metadata_address=metadata_address,
+ ssl_details=ssl_details, timeout=timeout,
+ retries=retries, leaf_decoder=leaf_decoder)
# vi: ts=4 expandtab