From 478e00a9974130ebdf92b76d57cf1a974399edae Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 27 Aug 2012 10:56:47 -0700 Subject: [PATCH] Update so that the content types searched for launch-index variable has a little more meaning and by default look in metadata for 'launch-index' and have ec2 instead look for a different variable (thus allowing more datasources to just work). --- cloudinit/cloud.py | 5 +++-- cloudinit/sources/DataSourceEc2.py | 5 ++++- cloudinit/sources/__init__.py | 9 +++++++-- cloudinit/user_data.py | 5 +++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cloudinit/cloud.py b/cloudinit/cloud.py index af69a541..95e0cfb2 100644 --- a/cloudinit/cloud.py +++ b/cloudinit/cloud.py @@ -76,8 +76,9 @@ class Cloud(object): def get_instance_id(self): return self.datasource.get_instance_id() - def get_launch_index(self): - return self.datasource.get_launch_index() + @property + def launch_index(self): + return self.datasource.launch_index def get_public_ssh_keys(self): return self.datasource.get_public_ssh_keys() diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index 3e450e7e..2a9a70f7 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -77,7 +77,10 @@ class DataSourceEc2(sources.DataSource): self.metadata_address) return False - def get_launch_index(self): + @property + def launch_index(self): + if not self.metadata: + return None return self.metadata.get('ami-launch-index') def get_instance_id(self): diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index d49b67b2..74944e38 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -68,13 +68,18 @@ class DataSource(object): return self._filter_userdata(self.userdata) return self.userdata - def get_launch_index(self): + @property + def launch_index(self): + if not self.metadata: + return None + if 'launch-index' in self.metadata: + return self.metadata['launch-index'] return None def _filter_userdata(self, processed_ud): if not processed_ud: return processed_ud - idx = self.get_launch_index() + idx = self.launch_index if idx is None: return processed_ud # First do a scan to see if any one with launch-index diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py index 2b76482a..5d550e1d 100644 --- a/cloudinit/user_data.py +++ b/cloudinit/user_data.py @@ -53,7 +53,8 @@ ARCHIVE_UNDEF_TYPE = "text/cloud-config" ATTACHMENT_FIELD = 'Number-Attachments' # Only the following content types can have there launch index examined -CAN_HAVE_LAUNCH_INDEX = ["text/cloud-config", "text/cloud-config-archive"] +# in there payload, evey other content type can still provide a header +EXAMINE_FOR_LAUNCH_INDEX = ["text/cloud-config", "text/cloud-config-archive"] class UserDataProcessor(object): @@ -101,7 +102,7 @@ class UserDataProcessor(object): def _attach_launch_index(self, msg): header_idx = msg.get('Launch-Index', None) payload_idx = None - if msg.get_content_type() in CAN_HAVE_LAUNCH_INDEX: + if msg.get_content_type() in EXAMINE_FOR_LAUNCH_INDEX: try: # See if it has a launch-index field # that might affect the final header