diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-03-21 22:31:15 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-03-21 22:31:15 -0400 |
commit | 5fa9d4c3acbb4f7bf98a8eea7e121f3bc71ad7e0 (patch) | |
tree | 8f79ffffaa497c6efbc3104c1078f9d356034411 /cloudinit/sources/DataSourceNoCloud.py | |
parent | 7a22e352b2f87636554d9787f60cd3168f3d77bc (diff) | |
parent | 4f2065ad569355d5d0bc54176bde6b8e55047341 (diff) | |
download | vyos-cloud-init-5fa9d4c3acbb4f7bf98a8eea7e121f3bc71ad7e0.tar.gz vyos-cloud-init-5fa9d4c3acbb4f7bf98a8eea7e121f3bc71ad7e0.zip |
merge from trunk
Diffstat (limited to 'cloudinit/sources/DataSourceNoCloud.py')
-rw-r--r-- | cloudinit/sources/DataSourceNoCloud.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py index 64853385..538df7d9 100644 --- a/cloudinit/sources/DataSourceNoCloud.py +++ b/cloudinit/sources/DataSourceNoCloud.py @@ -209,6 +209,41 @@ class DataSourceNoCloud(sources.DataSource): mydata['meta-data']['dsmode']) return False + def check_instance_id(self): + # quickly (local check only) if self.instance_id is still valid + # we check kernel command line or files. + current = self.get_instance_id() + if not current: + return None + + quick_id = _quick_read_instance_id(cmdline_id=self.cmdline_id, + dirs=[self.seed_dir]) + if not quick_id: + return None + return quick_id == current + + +def _quick_read_instance_id(cmdline_id, dirs=None): + if dirs is None: + dirs = [] + + iid_key = 'instance-id' + if cmdline_id is None: + fill = {} + if parse_cmdline_data(cmdline_id, fill) and iid_key in fill: + return fill[iid_key] + + for d in dirs: + try: + data = util.pathprefix2dict(d, required=['meta-data']) + md = util.load_yaml(data['meta-data']) + if iid_key in md: + return md[iid_key] + except ValueError: + pass + + return None + # Returns true or false indicating if cmdline indicated # that this module should be used |