mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
cloud-init plugin implemented.
There is no need for the sed plugin any longer
This commit is contained in:
parent
80d1a7ffc0
commit
2320b2cb74
9 changed files with 78 additions and 61 deletions
|
@ -43,10 +43,8 @@
|
||||||
{ "name": "cloud-init", "target": "{release}-backports" }
|
{ "name": "cloud-init", "target": "{release}-backports" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"sed": {
|
"cloud_init": {
|
||||||
"file": "etc/cloud/cloud.cfg",
|
"username": "admin"
|
||||||
"find": "^ name: debian$",
|
|
||||||
"replace": " name: admin\n sudo: ALL=(ALL) NOPASSWD:ALL\n shell: /bin/bash"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,8 @@
|
||||||
{ "name": "cloud-init", "target": "{release}-backports" }
|
{ "name": "cloud-init", "target": "{release}-backports" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"sed": {
|
"cloud_init": {
|
||||||
"file": "etc/cloud/cloud.cfg",
|
"username": "admin"
|
||||||
"find": "^ name: debian$",
|
|
||||||
"replace": " name: admin\n sudo: ALL=(ALL) NOPASSWD:ALL\n shell: /bin/bash"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
plugins/cloud_init/__init__.py
Normal file
31
plugins/cloud_init/__init__.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
|
||||||
|
def validate_manifest(data, schema_validate):
|
||||||
|
from os import path
|
||||||
|
schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json'))
|
||||||
|
schema_validate(data, schema_path)
|
||||||
|
packages = data['plugins']['packages']
|
||||||
|
cloud_init_installed = False
|
||||||
|
if 'remote' in packages:
|
||||||
|
for package in packages['remote']:
|
||||||
|
if isinstance(package, basestring):
|
||||||
|
name = package
|
||||||
|
else:
|
||||||
|
name = package['name']
|
||||||
|
if name == 'cloud-init':
|
||||||
|
cloud_init_installed = True
|
||||||
|
break
|
||||||
|
if not cloud_init_installed:
|
||||||
|
from common.exceptions import ManifestError
|
||||||
|
raise ManifestError('The cloud-init package must be installed for the cloud_init plugin to work')
|
||||||
|
|
||||||
|
|
||||||
|
def tasks(tasklist, manifest):
|
||||||
|
from tasks import SetUsername
|
||||||
|
from providers.ec2.tasks.initd import AddEC2InitScripts
|
||||||
|
from common.tasks import initd
|
||||||
|
tasklist.add(SetUsername)
|
||||||
|
tasklist.remove(AddEC2InitScripts,
|
||||||
|
initd.AddExpandRoot,
|
||||||
|
initd.AdjustExpandRootScript,
|
||||||
|
initd.AddSSHKeyGeneration)
|
23
plugins/cloud_init/manifest-schema.json
Normal file
23
plugins/cloud_init/manifest-schema.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "cloud-init plugin manifest",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"plugins": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cloud_init": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"username": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["username"]
|
||||||
|
},
|
||||||
|
"packages": {"type": "object"}
|
||||||
|
},
|
||||||
|
"required": ["cloud_init", "packages"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
plugins/cloud_init/tasks.py
Normal file
20
plugins/cloud_init/tasks.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
from base import Task
|
||||||
|
from common import phases
|
||||||
|
from plugins.packages.tasks import InstallRemotePackages
|
||||||
|
|
||||||
|
|
||||||
|
class SetUsername(Task):
|
||||||
|
description = 'Setting username in cloud.cfg'
|
||||||
|
phase = phases.system_modification
|
||||||
|
predecessors = [InstallRemotePackages]
|
||||||
|
|
||||||
|
def run(self, info):
|
||||||
|
from common.tools import sed_i
|
||||||
|
import os.path
|
||||||
|
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
|
||||||
|
username = info.manifest.plugins['cloud_init']['username']
|
||||||
|
search = '^ name: debian$'
|
||||||
|
replace = (' name: {username}\n'
|
||||||
|
' sudo: ALL=(ALL) NOPASSWD:ALL\n'
|
||||||
|
' shell: /bin/bash').format(username=username)
|
||||||
|
sed_i(cloud_cfg, search, replace)
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
def tasks(tasklist, manifest):
|
|
||||||
import tasks
|
|
||||||
tasklist.add(tasks.DoSeds)
|
|
||||||
|
|
||||||
def validate_manifest(data, schema_validate):
|
|
||||||
from os import path
|
|
||||||
schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json'))
|
|
||||||
schema_validate(data, schema_path)
|
|
|
@ -1,28 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
||||||
"title": "Backports setup and package install",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"plugins": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"sed": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"file": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"find": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"replace": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["sed"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["plugins"]
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
from base import Task
|
|
||||||
from common import phases
|
|
||||||
from common.tasks.apt import AptUpgrade
|
|
||||||
from common.tools import sed_i
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class DoSeds(Task):
|
|
||||||
description = 'Sedding files'
|
|
||||||
phase = phases.system_modification
|
|
||||||
predecessors = [AptUpgrade]
|
|
||||||
|
|
||||||
def run(self, info):
|
|
||||||
chroot_path = os.path.join(info.root, info.manifest.plugins['sed']['file'])
|
|
||||||
sed_i(chroot_path, info.manifest.plugins['sed']['find'], info.manifest.plugins['sed']['replace'])
|
|
Loading…
Add table
Reference in a new issue