Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def install_hook():
# Run both during initial install and during upgrade-charm.
if not os.path.exists(default_haproxy_service_config_dir):
os.mkdir(default_haproxy_service_config_dir, 0o600)
config_data = config_get()
source = config_data.get('source')
if source == 'backports':
release = lsb_release()['DISTRIB_CODENAME']
source = apt_backports_template % {'release': release}
add_backports_preferences(release)
add_source(source, config_data.get('key'))
apt_update(fatal=True)
apt_install(['haproxy', 'python-jinja2'], fatal=True)
# Install pyasn1 library and modules for inspecting SSL certificates
apt_install(['python-pyasn1', 'python-pyasn1-modules'], fatal=False)
ensure_package_status(service_affecting_packages,
config_data['package_status'])
enable_haproxy()
group='nogroup')
# Touch
with open(jenkins_bootstrap_flag, 'w'):
pass
log("Stopping jenkins for plugin update(s)", level=DEBUG)
service_stop('jenkins')
install_jenkins_plugins(jenkins_uid, jenkins_gid)
log("Starting jenkins to pickup configuration changes", level=DEBUG)
service_start('jenkins')
apt_install(['python-jenkins'], fatal=True)
tools = config('tools')
if tools:
log("Installing tools.", level=DEBUG)
apt_install(tools.split(), fatal=True)
def install():
"""Basic Ceph client installation."""
ceph_dir = "/etc/ceph"
if not os.path.exists(ceph_dir):
os.mkdir(ceph_dir)
apt_install('ceph-common', fatal=True)
def update_nrpe_config():
# python-dbus is used by check_upstart_job
apt_install('python-dbus')
hostname = nrpe.get_nagios_hostname()
current_unit = nrpe.get_nagios_unit_name()
nrpe_setup = nrpe.NRPE(hostname=hostname)
nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
nrpe_setup.write()
def _ensure_packages(self, packages):
'''Install but do not upgrade required packages'''
required = filter_installed_packages(packages)
if required:
apt_install(required, fatal=True)
def __init__(self, endpoint, **kwargs):
try:
from keystoneclient.v3 import client
from keystoneclient.auth import token_endpoint
from keystoneclient import session
from keystoneclient.auth.identity import v3
except ImportError:
if six.PY2:
apt_install(["python-keystoneclient"], fatal=True)
else:
apt_install(["python3-keystoneclient"], fatal=True)
from keystoneclient.v3 import client
from keystoneclient.auth import token_endpoint
from keystoneclient import session
from keystoneclient.auth.identity import v3
self.api_version = 3
token = kwargs.get("token", None)
if token:
auth = token_endpoint.Token(endpoint=endpoint,
token=token)
sess = session.Session(auth=auth)
else:
def ensure_packages(packages):
"""Install but do not upgrade required plugin packages."""
required = filter_installed_packages(packages)
if required:
apt_install(required, fatal=True)
def ns_query(address):
try:
import dns.resolver
except ImportError:
apt_install('python-dnspython')
import dns.resolver
if isinstance(address, dns.name.Name):
rtype = 'PTR'
elif isinstance(address, six.string_types):
rtype = 'A'
else:
return None
answers = dns.resolver.query(address, rtype)
if answers:
return str(answers[0])
return None
def install_packages():
"""
Install required packages to build the k8s source, and syndicate between
minion nodes. In addition, fetch pip to handle python dependencies
"""
hookenv.log('Installing Debian packages')
# Create the list of packages to install.
apt_packages = ['apache2-utils',
'build-essential',
'git',
'make',
'nginx',
'python-pip', ]
fetch.apt_install(fetch.filter_installed_packages(apt_packages))
def ensure_packages(packages):
"""Install but do not upgrade required plugin packages."""
required = filter_installed_packages(packages)
if required:
apt_install(required, fatal=True)