cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #03952
[Merge] ~smoser/cloud-init:bug/1712680-maas-use-token-for-check-instance-id into cloud-init:master
Scott Moser has proposed merging ~smoser/cloud-init:bug/1712680-maas-use-token-for-check-instance-id into cloud-init:master.
Commit message:
MAAS: add check_instance_id based off oauth tokens.
This stores a hash of the OAuth tokens as an 'id' for the maas
datasource. Since new instances get new tokens created and those tokens
are written by curtin into datasource system config this will provide
a way to identify a new "instance" (install).
LP: #1712680
Requested reviews:
cloud-init commiters (cloud-init-dev)
Related bugs:
Bug #1712680 in cloud-init: "cloud-init re-generates network config every reboot overwriting manual admin changes on CentOS."
https://bugs.launchpad.net/cloud-init/+bug/1712680
For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/335108
--
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:bug/1712680-maas-use-token-for-check-instance-id into cloud-init:master.
diff --git a/cloudinit/sources/DataSourceMAAS.py b/cloudinit/sources/DataSourceMAAS.py
index 496bd06..6c30591 100644
--- a/cloudinit/sources/DataSourceMAAS.py
+++ b/cloudinit/sources/DataSourceMAAS.py
@@ -8,6 +8,7 @@
from __future__ import print_function
+import hashlib
import os
import time
@@ -41,6 +42,7 @@ class DataSourceMAAS(sources.DataSource):
"""
dsname = "MAAS"
+ id_hash = None
def __init__(self, sys_cfg, distro, paths):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
@@ -147,6 +149,20 @@ class DataSourceMAAS(sources.DataSource):
return bool(url)
+ def check_instance_id(self, sys_cfg):
+ if self.id_hash is None:
+ return False
+ ncfg = util.get_cfg_by_path(sys_cfg, ("datasource", self.dsname), {})
+ return (self.id_hash == get_id_from_ds_cfg(ncfg))
+
+
+def get_id_from_ds_cfg(ds_cfg):
+ fields = ('token_key', 'token_secret', 'consumer_key')
+ idstr = '\0'.join([ds_cfg.get(k, "") for k in fields])
+ # store the encoding version as part of the hash in the event
+ # that it ever changed we can compute older versions.
+ return 'v1:' + hashlib.sha256(idstr.encode('utf-8')).hexdigest()
+
def read_maas_seed_dir(seed_d):
if seed_d.startswith("file://"):
References