summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-02-09 09:53:42 -0700
committerChad Smith <chad.smith@canonical.com>2018-02-12 10:20:09 -0700
commitd1a35a63c2a2ed32cb80fbebf098aa67160ea276 (patch)
tree396c0d8ec5157fa0400068cc6f0f85d6a0529394 /cloudinit
parentc6bdbef8d4dadec1b536dca09153632777547549 (diff)
downloadvyos-cloud-init-d1a35a63c2a2ed32cb80fbebf098aa67160ea276.tar.gz
vyos-cloud-init-d1a35a63c2a2ed32cb80fbebf098aa67160ea276.zip
EC2: Fix get_instance_id called against cached datasource pickle.
Fix an issue in EC2 where the datasource.identity had not been initialized before being used when restoring datasource from pickle. This is exposed in upgrade and reboot path. LP: #1748354
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/sources/DataSourceEc2.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py
index e14553b3..21e9ef84 100644
--- a/cloudinit/sources/DataSourceEc2.py
+++ b/cloudinit/sources/DataSourceEc2.py
@@ -147,6 +147,12 @@ class DataSourceEc2(sources.DataSource):
def get_instance_id(self):
if self.cloud_platform == Platforms.AWS:
# Prefer the ID from the instance identity document, but fall back
+ if not getattr(self, 'identity', None):
+ # If re-using cached datasource, it's get_data run didn't
+ # setup self.identity. So we need to do that now.
+ api_version = self.get_metadata_api_version()
+ self.identity = ec2.get_instance_identity(
+ api_version, self.metadata_address).get('document', {})
return self.identity.get(
'instanceId', self.metadata['instance-id'])
else: