mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
New plugin: apt_proxy
This commit is contained in:
parent
b7592288d9
commit
88014671e8
3 changed files with 68 additions and 0 deletions
11
plugins/apt_proxy/__init__.py
Normal file
11
plugins/apt_proxy/__init__.py
Normal 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)
|
29
plugins/apt_proxy/manifest-schema.json
Normal file
29
plugins/apt_proxy/manifest-schema.json
Normal 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"]
|
||||
}
|
28
plugins/apt_proxy/tasks.py
Normal file
28
plugins/apt_proxy/tasks.py
Normal 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'))
|
Loading…
Add table
Reference in a new issue