diff --git a/manifests/one-raw-virtio.manifest.json b/manifests/one-raw-virtio.manifest.json index 33cff2a..913c8ac 100644 --- a/manifests/one-raw-virtio.manifest.json +++ b/manifests/one-raw-virtio.manifest.json @@ -41,6 +41,12 @@ "prebootstrapped": { "enabled": false, "snapshot": "" - } + }, + "user_packages": { + "enabled": true, + "repo": [ "apache2" ], + "local": [] + } + } } diff --git a/plugins/user_packages/__init__.py b/plugins/user_packages/__init__.py new file mode 100644 index 0000000..e223e0a --- /dev/null +++ b/plugins/user_packages/__init__.py @@ -0,0 +1,6 @@ + + +def tasks(tasklist, manifest): + from user_packages import AddUserPackages, AddLocalUserPackages + tasklist.add(AddUserPackages()) + tasklist.add(AddLocalUserPackages()) diff --git a/plugins/user_packages/user_packages.py b/plugins/user_packages/user_packages.py new file mode 100644 index 0000000..296c536 --- /dev/null +++ b/plugins/user_packages/user_packages.py @@ -0,0 +1,45 @@ +from base import Task +from common import phases +import os +from providers.one.tasks.packages import ImagePackages +from providers.one.tasks.host import CheckPackages +from providers.one.tasks.filesystem import MountVolume + + +class AddUserPackages(Task): + description = 'Adding user defined packages to the image packages' + phase = phases.preparation + after = [ImagePackages] + before = [CheckPackages] + + def run(self, info): + if 'repo' not in info.manifest.plugins['user_packages']: + return + for pkg in info.manifest.plugins['user_packages']['repo']: + info.img_packages[0].add(pkg) + +class AddLocalUserPackages(Task): + description = 'Adding user local packages to the image packages' + phase = phases.system_modification + after = [MountVolume] + + def run(self, info): + if 'local' not in info.manifest.plugins['user_packages']: + return + + import stat + rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | + stat.S_IRGRP | stat.S_IXGRP | + stat.S_IROTH | stat.S_IXOTH) + + from shutil import copy + from common.tools import log_check_call + + for pkg in info.manifest.plugins['user_packages']['local']: + script_src = os.path.normpath(pkg) + script_dst = os.path.join(info.root, 'tmp/'+os.path.basename(script_src)) + copy(script_src, script_dst) + os.chmod(script_dst, rwxr_xr_x) + + log_check_call(['/usr/sbin/chroot', info.root, 'dpkg', '-i', '/tmp/'+os.path.basename(script_src)]) + diff --git a/providers/one/__init__.py b/providers/one/__init__.py index 73af652..bdf9fba 100644 --- a/providers/one/__init__.py +++ b/providers/one/__init__.py @@ -52,8 +52,7 @@ def tasks(tasklist, manifest): boot.DisableGetTTYs(), security.EnableShadowConfig(), security.SetRootPassword(), - # Disable for the time of debugging - #security.DisableSSHPasswordAuthentication(), + security.DisableSSHPasswordAuthentication(), security.DisableSSHDNSLookup(), network.RemoveDNSInfo(), network.ConfigureNetworkIF(), diff --git a/providers/one/tasks/locale.py b/providers/one/tasks/locale.py index de3e434..a0005b4 100644 --- a/providers/one/tasks/locale.py +++ b/providers/one/tasks/locale.py @@ -16,7 +16,7 @@ class GenerateLocale(Task): search = '# ' + locale_str sed_i(locale_gen, search, locale_str) - command = ['/usr/sbin/chroot', info.root, '/usr/sbin/dpkg-reconfigure', '--priority=critical', 'locales'] + command = ['/usr/sbin/chroot', info.root, '/usr/sbin/locale-gen'] log_check_call(command) diff --git a/providers/one/tasks/one.py b/providers/one/tasks/one.py index 745cb43..fda5185 100644 --- a/providers/one/tasks/one.py +++ b/providers/one/tasks/one.py @@ -1,11 +1,13 @@ from base import Task from common import phases import os +from providers.one.tasks.locale import GenerateLocale class OpenNebulaContext(Task): description = 'Setup OpenNebula init context' phase = phases.system_modification + after = [GenerateLocale] def run(self, info): import stat diff --git a/providers/one/tasks/security.py b/providers/one/tasks/security.py index af1aa8c..77f986c 100644 --- a/providers/one/tasks/security.py +++ b/providers/one/tasks/security.py @@ -26,8 +26,10 @@ class DisableSSHPasswordAuthentication(Task): def run(self, info): from common.tools import sed_i - sshd_config_path = os.path.join(info.root, 'etc/ssh/sshd_config') - sed_i(sshd_config_path, '^#PasswordAuthentication yes', 'PasswordAuthentication no') + if 'root' not in info.manifest.credentials: + # If no password set for root + sshd_config_path = os.path.join(info.root, 'etc/ssh/sshd_config') + sed_i(sshd_config_path, '^#PasswordAuthentication yes', 'PasswordAuthentication no') class DisableSSHDNSLookup(Task):