New plugin: apt_proxy

This commit is contained in:
Tiago Ilieve 2014-03-27 23:44:38 -03:00
parent b7592288d9
commit 88014671e8
3 changed files with 68 additions and 0 deletions

View file

@ -0,0 +1,11 @@
def validate_manifest(data, validator, error):
import os.path
schema_path = os.path.normpath(os.path.join(os.path.dirname(__file__), 'manifest-schema.json'))
validator(data, schema_path)
def resolve_tasks(taskset, manifest):
import tasks
taskset.add(tasks.SetAptProxy)
if not manifest.plugins['apt_proxy'].get('persistent', False):
taskset.add(tasks.RemoveAptProxy)

View file

@ -0,0 +1,29 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "APT proxy plugin manifest",
"type": "object",
"properties": {
"plugins": {
"type": "object",
"properties": {
"apt_proxy": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"persistent": {
"type": "boolean"
},
"port": {
"type": "integer"
}
},
"required": ["address", "port"]
}
},
"required": ["apt_proxy"]
}
},
"required": ["plugins"]
}

View file

@ -0,0 +1,28 @@
from base import Task
from common import phases
from common.tasks import apt
import os
class SetAptProxy(Task):
description = 'Setting proxy for APT'
phase = phases.package_installation
successors = [apt.AptUpdate]
@classmethod
def run(cls, info):
proxy_path = os.path.join(info.root, 'etc/apt/apt.conf.d/02proxy')
proxy_address = info.manifest.plugins['apt_proxy']['address']
proxy_port = info.manifest.plugins['apt_proxy']['port']
with open(proxy_path, 'w') as proxy_file:
proxy_file.write('Acquire::http {{ Proxy "http://{address}:{port}"; }};\n'
.format(address=proxy_address, port=proxy_port))
class RemoveAptProxy(Task):
description = 'Removing APT proxy configuration file'
phase = phases.system_cleaning
@classmethod
def run(cls, info):
os.remove(os.path.join(info.root, 'etc/apt/apt.conf.d/02proxy'))