summaryrefslogtreecommitdiff
path: root/cloudinit/sources/__init__.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-08-27 20:51:00 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-08-27 20:51:00 -0700
commit2e51e2efc292870479a7b972c7ebc9ceac85da6f (patch)
tree7ae5688835309fa24c9f0ffe3f6876cbe964591e /cloudinit/sources/__init__.py
parent92b99b325b2d437825cc87253e76c756a136ff28 (diff)
downloadvyos-cloud-init-2e51e2efc292870479a7b972c7ebc9ceac85da6f.tar.gz
vyos-cloud-init-2e51e2efc292870479a7b972c7ebc9ceac85da6f.zip
For the userdata 'post-filtering' add in a new folder that
can contain filters that serve this purpose only and add in the initial launch-index filter and replace the code in the datasource class that previously did this.
Diffstat (limited to 'cloudinit/sources/__init__.py')
-rw-r--r--cloudinit/sources/__init__.py51
1 files changed, 9 insertions, 42 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 74944e38..3f611d44 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -29,6 +29,8 @@ from cloudinit import log as logging
from cloudinit import user_data as ud
from cloudinit import util
+from cloudinit.filters import launch_index
+
DEP_FILESYSTEM = "FILESYSTEM"
DEP_NETWORK = "NETWORK"
DS_PREFIX = 'DataSource'
@@ -77,48 +79,13 @@ class DataSource(object):
return None
def _filter_userdata(self, processed_ud):
- if not processed_ud:
- return processed_ud
- idx = self.launch_index
- if idx is None:
- return processed_ud
- # First do a scan to see if any one with launch-index
- # headers, if not just skip this....
- launch_idxs = 0
- for part in processed_ud.walk():
- if ud.is_skippable(part):
- continue
- launch_idx_h = part.get('Launch-Index', None)
- if launch_idx_h is not None:
- launch_idxs += 1
- if not launch_idxs:
- return processed_ud
- # Reform a new message with those that either have
- # no launch index or ones that have our launch index or ones
- # that have some other garbage that we don't know what to do with
- accumulating_msg = MIMEMultipart()
- tot_attached = 0
- tot_processed = 0
- for part in processed_ud.walk():
- if ud.is_skippable(part):
- continue
- try:
- tot_processed += 1
- launch_idx_h = part.get('Launch-Index', None)
- if launch_idx_h is None or int(launch_idx_h) == int(idx):
- accumulating_msg.attach(part)
- tot_attached += 1
- else:
- LOG.debug(("Discarding multipart message %s, "
- "launch-index provided destined for %s "
- "and not %s"),
- tot_processed, launch_idx_h, idx)
- except (TypeError, ValueError):
- # If any int conversion fails keep the message
- accumulating_msg.attach(part)
- tot_attached += 1
- accumulating_msg[ud.ATTACHMENT_FIELD] = str(tot_attached)
- return accumulating_msg
+ filters = [
+ launch_index.Filter(util.safe_int(self.launch_index)),
+ ]
+ new_ud = processed_ud
+ for f in filters:
+ new_ud = f.apply(new_ud)
+ return new_ud
@property
def is_disconnected(self):