summaryrefslogtreecommitdiff
path: root/cloudinit/handlers/boot_hook.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2013-07-23 12:05:04 -0400
committerScott Moser <smoser@ubuntu.com>2013-07-23 12:05:04 -0400
commit838d6c7ddcac8544afb99cb78e8d044fd63b835f (patch)
treec44bde5e0e7a64a70d1981c38d468311435fafd5 /cloudinit/handlers/boot_hook.py
parenta8d2b2f8d7b9315d729873b15ed8dedb9c1b069f (diff)
parent27f096a1ab2e60222f85d87c961e388fdefaf92c (diff)
downloadvyos-cloud-init-838d6c7ddcac8544afb99cb78e8d044fd63b835f.tar.gz
vyos-cloud-init-838d6c7ddcac8544afb99cb78e8d044fd63b835f.zip
use constants for startswith in handlers. add strip_prefix_suffix.
Just cleans up some repeated strings into module constants + a util function to do the boothook prefix cleanup (before writing).
Diffstat (limited to 'cloudinit/handlers/boot_hook.py')
-rw-r--r--cloudinit/handlers/boot_hook.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/cloudinit/handlers/boot_hook.py b/cloudinit/handlers/boot_hook.py
index 11ac4fe5..1848ce2c 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,19 +42,15 @@ 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:]
- util.write_file(filepath, contents, 0700)
+ contents = util.strip_prefix_suffix(util.dos2unix(payload),
+ prefix=BOOTHOOK_PREFIX)
+ util.write_file(filepath, contents.lstrip(), 0700)
return filepath
def handle_part(self, _data, ctype, filename, # pylint: disable=W0221