cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #00271
[Merge] lp:~harlowja/cloud-init/constants-handler-types into lp:cloud-init
Joshua Harlow has proposed merging lp:~harlowja/cloud-init/constants-handler-types into lp:cloud-init.
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/constants-handler-types/+merge/176066
Just cleans up some repeated strings into module constants.
--
https://code.launchpad.net/~harlowja/cloud-init/constants-handler-types/+merge/176066
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/constants-handler-types into lp:cloud-init.
=== modified file 'cloudinit/handlers/boot_hook.py'
--- cloudinit/handlers/boot_hook.py 2013-06-19 06:44:00 +0000
+++ cloudinit/handlers/boot_hook.py 2013-07-21 16:29:26 +0000
@@ -29,6 +29,7 @@
from cloudinit.settings import (PER_ALWAYS)
LOG = logging.getLogger(__name__)
+BOOTHOOK_PREFIX = "#cloud-boothook"
class BootHookPartHandler(handlers.Handler):
@@ -41,18 +42,16 @@
def list_types(self):
return [
- handlers.type_from_starts_with("#cloud-boothook"),
+ handlers.type_from_starts_with(BOOTHOOK_PREFIX),
]
def _write_part(self, payload, filename):
filename = util.clean_filename(filename)
- payload = util.dos2unix(payload)
- prefix = "#cloud-boothook"
- start = 0
- if payload.startswith(prefix):
- start = len(prefix) + 1
filepath = os.path.join(self.boothook_dir, filename)
- contents = payload[start:]
+ contents = util.dos2unix(payload)
+ if contents.startswith(BOOTHOOK_PREFIX):
+ real_start = len(BOOTHOOK_PREFIX) + 1
+ contents = contents[real_start:]
util.write_file(filepath, contents, 0700)
return filepath
=== modified file 'cloudinit/handlers/cloud_config.py'
--- cloudinit/handlers/cloud_config.py 2013-05-10 05:47:14 +0000
+++ cloudinit/handlers/cloud_config.py 2013-07-21 16:29:26 +0000
@@ -49,6 +49,7 @@
#
# This gets loaded into yaml with final result {'a': 22}
DEF_MERGERS = mergers.string_extract_mergers('dict(replace)+list()+str()')
+CLOUD_PREFIX = "#cloud-config"
class CloudConfigPartHandler(handlers.Handler):
@@ -60,7 +61,7 @@
def list_types(self):
return [
- handlers.type_from_starts_with("#cloud-config"),
+ handlers.type_from_starts_with(CLOUD_PREFIX),
]
def _write_cloud_config(self):
@@ -78,7 +79,7 @@
if self.cloud_buf is not None:
# Something was actually gathered....
lines = [
- "#cloud-config",
+ CLOUD_PREFIX,
'',
]
lines.extend(file_lines)
=== modified file 'cloudinit/handlers/shell_script.py'
--- cloudinit/handlers/shell_script.py 2013-03-07 22:13:05 +0000
+++ cloudinit/handlers/shell_script.py 2013-07-21 16:29:26 +0000
@@ -29,6 +29,7 @@
from cloudinit.settings import (PER_ALWAYS)
LOG = logging.getLogger(__name__)
+SHELL_PREFIX = "#!"
class ShellScriptPartHandler(handlers.Handler):
@@ -38,7 +39,7 @@
def list_types(self):
return [
- handlers.type_from_starts_with("#!"),
+ handlers.type_from_starts_with(SHELL_PREFIX),
]
def handle_part(self, _data, ctype, filename, # pylint: disable=W0221
=== modified file 'cloudinit/handlers/upstart_job.py'
--- cloudinit/handlers/upstart_job.py 2013-07-11 14:14:49 +0000
+++ cloudinit/handlers/upstart_job.py 2013-07-21 16:29:26 +0000
@@ -31,6 +31,7 @@
from cloudinit.settings import (PER_INSTANCE)
LOG = logging.getLogger(__name__)
+UPSTART_PREFIX = "#upstart-job"
class UpstartJobPartHandler(handlers.Handler):
@@ -40,7 +41,7 @@
def list_types(self):
return [
- handlers.type_from_starts_with("#upstart-job"),
+ handlers.type_from_starts_with(UPSTART_PREFIX),
]
def handle_part(self, _data, ctype, filename, # pylint: disable=W0221
Follow ups