diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 81f9013..037cb9d 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -40,7 +40,8 @@ from pg_dir_utils import ( fabric_interface_changed, load_iptables, restart_on_change, - director_cluster_ready + director_cluster_ready, + configure_pg_sources ) hooks = Hooks() @@ -135,6 +136,9 @@ def config_changed(): charm_config.changed('iovisor-build')): status_set('maintenance', 'Upgrading apt packages') stop_pg() + if charm_config.changed('install_sources'): + if not configure_pg_sources(): + log('IOError: /etc/apt/sources.list couldn\'t be updated') configure_sources(update=True) pkgs = determine_packages() for pkg in pkgs: diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index 48f462d..4401fc7 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -42,6 +42,7 @@ from charmhelpers.contrib.openstack.utils import ( os_release, ) +SOURCES_LIST = '/etc/apt/sources.list' LXC_CONF = '/etc/libvirt/lxc.conf' TEMPLATES = 'templates/' PG_LXC_DATA_PATH = '/var/lib/libvirt/filesystems/plumgrid-data' @@ -88,6 +89,23 @@ BASE_RESOURCE_MAP = 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 by PLUMgrid director as specified