summaryrefslogtreecommitdiff
path: root/cloudinit/handlers/boot_hook.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2013-07-21 09:26:44 -0700
committerJoshua Harlow <harlowja@gmail.com>2013-07-21 09:26:44 -0700
commit7022512f3ceb955be2834844f05d4683f78ff276 (patch)
tree221822e3510d36c2e1ebbab142394b5bfe241ce2 /cloudinit/handlers/boot_hook.py
parent1edfb2a7a36a2bdddfe0ca48ba5d23721bf17a35 (diff)
downloadvyos-cloud-init-7022512f3ceb955be2834844f05d4683f78ff276.tar.gz
vyos-cloud-init-7022512f3ceb955be2834844f05d4683f78ff276.zip
Use constants for repeated type strings.
Diffstat (limited to 'cloudinit/handlers/boot_hook.py')
-rw-r--r--cloudinit/handlers/boot_hook.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/cloudinit/handlers/boot_hook.py b/cloudinit/handlers/boot_hook.py
index 11ac4fe5..5e7b6204 100644
--- a/cloudinit/handlers/boot_hook.py
+++ b/cloudinit/handlers/boot_hook.py
@@ -29,6 +29,7 @@ from cloudinit import util
from cloudinit.settings import (PER_ALWAYS)
LOG = logging.getLogger(__name__)
+BOOTHOOK_PREFIX = "#cloud-boothook"
class BootHookPartHandler(handlers.Handler):
@@ -41,18 +42,16 @@ class BootHookPartHandler(handlers.Handler):
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