diff options
author | Chad Smith <chad.smith@canonical.com> | 2018-02-09 09:53:42 -0700 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2018-02-09 17:02:27 -0500 |
commit | 644048e31a9509390871a6a5ab49b92a5e6c3b87 (patch) | |
tree | 71eb96b6338f30505efe7dc446d02e429abb6b4b /cloudinit/sources | |
parent | 86d2fc7f515f70a5117f00baf701a0bed6310b3e (diff) | |
download | vyos-cloud-init-644048e31a9509390871a6a5ab49b92a5e6c3b87.tar.gz vyos-cloud-init-644048e31a9509390871a6a5ab49b92a5e6c3b87.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/sources')
-rw-r--r-- | cloudinit/sources/DataSourceEc2.py | 6 |
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: |