mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
cloud-init: Add option to enable modules
Snatched from PR #256 by @JamesBromberger
This commit is contained in:
parent
8eb51524f3
commit
c14687a171
3 changed files with 36 additions and 1 deletions
|
@ -26,6 +26,8 @@ def resolve_tasks(taskset, manifest):
|
|||
taskset.add(tasks.SetUsername)
|
||||
if 'groups' in options and len(options['groups']):
|
||||
taskset.add(tasks.SetGroups)
|
||||
if 'enable_modules' in options:
|
||||
taskset.add(tasks.EnableModules)
|
||||
if 'disable_modules' in options:
|
||||
taskset.add(tasks.DisableModules)
|
||||
|
||||
|
|
|
@ -31,5 +31,14 @@ properties:
|
|||
type: array
|
||||
items: {type: string}
|
||||
uniqueItems: true
|
||||
enable_modules:
|
||||
type: object
|
||||
properties:
|
||||
cloud_init_modules:
|
||||
type: array
|
||||
properties:
|
||||
module: {type: string}
|
||||
position: { type: number}
|
||||
additionalProperties: false
|
||||
required: [username]
|
||||
additionalProperties: false
|
||||
|
|
|
@ -77,7 +77,7 @@ class SetMetadataSource(Task):
|
|||
|
||||
|
||||
class DisableModules(Task):
|
||||
description = 'Setting cloud.cfg modules'
|
||||
description = 'Disabling cloud.cfg modules'
|
||||
phase = phases.system_modification
|
||||
|
||||
@classmethod
|
||||
|
@ -97,3 +97,27 @@ class DisableModules(Task):
|
|||
for line in fileinput.input(files=cloud_cfg, inplace=True):
|
||||
if not regex.match(line):
|
||||
print line,
|
||||
|
||||
|
||||
class EnableModules(Task):
|
||||
description = 'Enabling cloud.cfg modules'
|
||||
phase = phases.system_modification
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
import fileinput
|
||||
import re
|
||||
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
|
||||
for section in info.manifest.plugins['cloud_init']['enable_modules']:
|
||||
regex = re.compile("^%s:" % section)
|
||||
for entry in info.manifest.plugins['cloud_init']['enable_modules'][section]:
|
||||
count = 0
|
||||
counting = 0
|
||||
for line in fileinput.input(files=cloud_cfg, inplace=True):
|
||||
if regex.match(line) and not counting:
|
||||
counting = True
|
||||
if counting:
|
||||
count = count + 1
|
||||
if int(entry['position']) == int(count):
|
||||
print(" - %s" % entry['module'])
|
||||
print line,
|
||||
|
|
Loading…
Add table
Reference in a new issue