Merge pull request #93 from JamesBromberger/python

Plugin for adding backports to apt and a set of packages from backports.
This commit is contained in:
Anders Ingemann 2013-08-17 07:01:23 -07:00
commit 6065cd5d2c
4 changed files with 80 additions and 0 deletions

View file

@ -31,6 +31,10 @@
"enabled": true, "enabled": true,
"username": "admin" "username": "admin"
}, },
"backports": {
"enabled": true,
"packages": [ "cloud-init" ]
},
"build_metadata": { "build_metadata": {
"enabled": false, "enabled": false,
"path": "/root/build-metadata-{ami_name}" "path": "/root/build-metadata-{ami_name}"

View file

@ -0,0 +1,12 @@
def tasks(tasklist, manifest):
import tasks
tasklist.add(tasks.AptSourcesBackports())
tasklist.add(tasks.AddBackportsPackages())
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)

View file

@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Backports setup and package install",
"type": "object",
"properties": {
"plugins": {
"type": "object",
"properties": {
"backports": {
"type": "object",
"properties": {
"packages": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["packages"]
}
},
"required": ["backports"]
}
},
"required": ["plugins"]
}

View file

@ -0,0 +1,38 @@
from base import Task
from common import phases
from common.tasks.packages import ImagePackages
from common.tasks.initd import InstallInitScripts
from common.tasks.apt import AptUpgrade
from common.tasks.apt import AptSources
import os
class AptSourcesBackports(Task):
description = 'Adding backports to sources.list'
phase = phases.system_modification
after = [AptSources]
before = [AptUpgrade]
def run(self, info):
sources_path = os.path.join(info.root, 'etc/apt/sources.list')
with open(sources_path, 'a') as apt_sources:
apt_sources.write(('deb {apt_mirror} {release}-backports main\n'
'deb-src {apt_mirror} {release}-backports main\n'
.format(apt_mirror='http://http.debian.net/debian',
release=info.manifest.system['release'])))
class AddBackportsPackages(Task):
description = 'Adding backport packages to the image'
phase = phases.system_modification
after = [AptUpgrade]
def run(self, info):
if 'packages' not in info.manifest.plugins['backports']:
return
from shutil import copy
from common.tools import log_check_call
for pkg in info.manifest.plugins['backports']['packages']:
log_check_call(['/usr/sbin/chroot', info.root, 'apt-get', 'install', '-y', '-t', info.manifest.system['release'] + '-backports', pkg])