From c2a2100b01a168e356d0f18fbe55ae01a1582cf2 Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Sat, 21 May 2016 17:28:31 +0500 Subject: [PATCH] Configured plumgrid install sources --- hooks/neutron_plumgrid_hooks.py | 4 ++++ hooks/neutron_plumgrid_utils.py | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hooks/neutron_plumgrid_hooks.py b/hooks/neutron_plumgrid_hooks.py index 51658d3..f50e0d8 100755 --- a/hooks/neutron_plumgrid_hooks.py +++ b/hooks/neutron_plumgrid_hooks.py @@ -32,6 +32,7 @@ from neutron_plumgrid_utils import ( restart_map, ensure_files, set_neutron_relation, + configure_pg_sources ) hooks = Hooks() @@ -65,6 +66,9 @@ def config_changed(): charm_config.changed('plumgrid-build') or charm_config.changed('install_keys')): status_set('maintenance', 'Upgrading apt packages') + if charm_config.changed('install_sources'): + if not configure_pg_sources(): + log('IOError: /etc/apt/sources.list couldn\'t be updated') configure_sources() apt_update() pkgs = determine_packages() diff --git a/hooks/neutron_plumgrid_utils.py b/hooks/neutron_plumgrid_utils.py index bac2bf9..797d353 100644 --- a/hooks/neutron_plumgrid_utils.py +++ b/hooks/neutron_plumgrid_utils.py @@ -31,7 +31,7 @@ PG_PACKAGES = [ ] NEUTRON_CONF_DIR = "/etc/neutron" - +SOURCES_LIST = '/etc/apt/sources.list' SU_FILE = '/etc/sudoers.d/neutron_sudoers' PLUMGRID_CONF = '%s/plugins/plumgrid/plumgrid.ini' % NEUTRON_CONF_DIR PGLIB_CONF = '%s/plugins/plumgrid/plumlib.ini' % NEUTRON_CONF_DIR @@ -63,6 +63,23 @@ NETWORKING_PLUMGRID_VERSION = OrderedDict([ ]) +def configure_pg_sources(): + ''' + Returns true if install sources is updated in sources.list file + ''' + try: + with open(SOURCES_LIST, 'r+') as sources: + all_lines = sources.readlines() + sources.seek(0) + for i in (line for line in all_lines if "plumgrid" not in line): + sources.write(i) + sources.truncate() + sources.close() + return True + except IOError: + return False + + def determine_packages(): ''' Returns list of packages required to be installed alongside neutron to