mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00

Up until now I didn't see the point of using spaces for indentation. However, the previous commit (a18bec3) was quite eye opening. Given that python is an indentation aware language, the amount of mistakes that went unnoticed because tabs and spaces were used at the same time (tabs for indentation and spaces for alignment) were unacceptable. E101,W191 have been re-enable in the tox flake8 checker and the documentation has been modified accordingly. The following files have been left as-is: * bootstrapvz/common/assets/extlinux/extlinux.conf * bootstrapvz/common/assets/init.d/expand-root * bootstrapvz/common/assets/init.d/generate-ssh-hostkeys * bootstrapvz/common/assets/init.d/squeeze/generate-ssh-hostkeys * bootstrapvz/plugins/docker_daemon/assets/init.d/docker * bootstrapvz/providers/ec2/assets/bin/growpart * bootstrapvz/providers/ec2/assets/grub.d/40_custom * bootstrapvz/providers/ec2/assets/init.d/ec2-get-credentials * bootstrapvz/providers/ec2/assets/init.d/ec2-run-user-data * docs/_static/taskoverview.coffee * docs/_static/taskoverview.less * tests/unit/subprocess.sh
60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
from bootstrapvz.base import Task
|
|
from bootstrapvz.common import phases
|
|
from bootstrapvz.common.tasks import apt
|
|
import os
|
|
import urllib2
|
|
|
|
|
|
class CheckAptProxy(Task):
|
|
description = 'Checking reachability of APT proxy server'
|
|
phase = phases.preparation
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
proxy_address = info.manifest.plugins['apt_proxy']['address']
|
|
proxy_port = info.manifest.plugins['apt_proxy']['port']
|
|
proxy_url = 'http://{address}:{port}'.format(address=proxy_address, port=proxy_port)
|
|
try:
|
|
urllib2.urlopen(proxy_url, timeout=5)
|
|
except Exception as e:
|
|
# Default response from `apt-cacher-ng`
|
|
if isinstance(e, urllib2.HTTPError) and e.code in [404, 406] and e.msg == 'Usage Information':
|
|
pass
|
|
else:
|
|
import logging
|
|
log = logging.getLogger(__name__)
|
|
log.warning('The APT proxy server couldn\'t be reached. `apt-get\' commands may fail.')
|
|
|
|
|
|
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_username = info.manifest.plugins['apt_proxy'].get('username')
|
|
proxy_password = info.manifest.plugins['apt_proxy'].get('password')
|
|
proxy_address = info.manifest.plugins['apt_proxy']['address']
|
|
proxy_port = info.manifest.plugins['apt_proxy']['port']
|
|
|
|
if None not in (proxy_username, proxy_password):
|
|
proxy_auth = '{username}:{password}@'.format(
|
|
username=proxy_username, password=proxy_password)
|
|
else:
|
|
proxy_auth = ''
|
|
|
|
with open(proxy_path, 'w') as proxy_file:
|
|
proxy_file.write(
|
|
'Acquire::http {{ Proxy "http://{auth}{address}:{port}"; }};\n'
|
|
.format(auth=proxy_auth, 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'))
|