bootstrap-vz/bootstrapvz/plugins/apt_proxy/tasks.py
Tiago Ilieve 14682eb96d Moving remaining plugins to bootstrapvz/plugins/
Three of the last developed plugins remained on the old `plugins/`
folder. This probably happened because they didn't existed when the
`documentation` branch were created, so they weren't moved when it was
rebased against `master`.
2014-04-03 19:08:04 -03:00

28 lines
894 B
Python

from bootstrapvz.base import Task
from bootstrapvz.common import phases
from bootstrapvz.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'))