def remove_leftovers(): """ Clean up, remove configuration files, uninstall packages. """ rdebug('storpool-config.stop invoked') reactive.remove_state('l-storpool-config.stop') try: rdebug('about to roll back any txn-installed files') txn.rollback_if_needed() except Exception as e: rdebug('Could not run txn rollback: {e}'.format(e=e)) if not sputils.check_in_lxc(): try: rdebug('about to remove any loaded kernel modules') mods_b = subprocess.check_output(['lsmod']) for module_data in mods_b.decode().split('\n'): module = module_data.split(' ', 1)[0] rdebug('- got module {mod}'.format(mod=module)) if module.startswith('storpool_'): rdebug(' - trying to remove it') subprocess.call(['rmmod', module]) # Any remaining? (not an error, just, well...) rdebug('checking for any remaining StorPool modules') remaining = [] mods_b = subprocess.check_output(['lsmod']) for module_data in mods_b.decode().split('\n'): module = module_data.split(' ', 1)[0] if module.startswith('storpool_'): remaining.append(module) if remaining: rdebug('some modules were left over: {lst}'.format( lst=' '.join(sorted(remaining)))) else: rdebug('looks like we got rid of them all!') rdebug('that is all for the modules') except Exception as e: rdebug('Could not remove kernel modules: {e}'.format(e=e)) rdebug('removing any config-related packages') sprepo.unrecord_packages('storpool-config') rdebug('let the storpool-repo layer know that we are shutting down') reactive.set_state('storpool-repo-add.stop') rdebug('goodbye, weird world!') reactive.set_state('l-storpool-config.stopped') for state in STATES_REDO['set'] + STATES_REDO['unset']: reactive.remove_state(state)
def enable_and_start(): """ Enable and start the `storpool_beacon` service. """ if sputils.check_in_lxc(): rdebug('running in an LXC container, not doing anything more') reactive.set_state('storpool-beacon.beacon-started') return if not sputils.check_cgroups('beacon'): return rdebug('enabling and starting the beacon service') host.service_resume('storpool_beacon') reactive.set_state('storpool-beacon.beacon-started')
def enable_and_start(): """ Start the `storpool_block` service. """ if sputils.check_in_lxc(): rdebug('running in an LXC container, not doing anything more') reactive.set_state('storpool-block.block-started') return if not sputils.check_cgroups('block'): return rdebug('enabling and starting the block service') host.service_resume('storpool_block') if os.path.isfile('/usr/sbin/storpool_stat.bin'): host.service_resume('storpool_stat') reactive.set_state('storpool-block.block-started')
def remove_leftovers(): """ Clean up, disable the service, uninstall the packages. """ rdebug('storpool-beacon.stop invoked') reactive.remove_state('storpool-beacon.stop') if not sputils.check_in_lxc(): rdebug('stopping and disabling the storpool_beacon service') host.service_pause('storpool_beacon') rdebug('uninstalling any beacon-related packages') sprepo.unrecord_packages('storpool-beacon') rdebug('letting storpool-common know') reactive.set_state('storpool-common.stop') reactive.set_state('storpool-beacon.stopped') for state in STATES_REDO['set'] + STATES_REDO['unset']: reactive.remove_state(state)
def remove_leftovers(): """ Remove the installed packages and stop the service. """ rdebug('storpool-block.stop invoked') reactive.remove_state('storpool-block.stop') if not sputils.check_in_lxc(): rdebug('stopping and disabling the storpool_block service') host.service_pause('storpool_block') rdebug('uninstalling any block-related packages') sprepo.unrecord_packages('storpool-block') rdebug('let storpool-beacon know') reactive.set_state('storpool-beacon.stop') reactive.set_state('storpool-block.stopped') for state in STATES_REDO['set'] + STATES_REDO['unset']: reactive.remove_state(state)
def install_package(): """ Install the StorPool block package. """ rdebug('the block repo has become available and the common packages ' 'have been configured') if sputils.check_in_lxc(): rdebug('running in an LXC container, not doing anything more') reactive.set_state('storpool-block.package-installed') return spstatus.npset('maintenance', 'obtaining the requested StorPool version') spver = spconfig.m().get('storpool_version', None) if spver is None or spver == '': rdebug('no storpool_version key in the charm config yet') return spstatus.npset('maintenance', 'installing the StorPool block packages') (err, newly_installed) = sprepo.install_packages({ 'storpool-block': spver, }) if err is not None: rdebug('oof, we could not install packages: {err}'.format(err=err)) rdebug('removing the package-installed state') return if newly_installed: rdebug('it seems we managed to install some packages: {names}'.format( names=newly_installed)) sprepo.record_packages('storpool-block', newly_installed) else: rdebug('it seems that all the packages were installed already') rdebug('setting the package-installed state') reactive.set_state('storpool-block.package-installed') spstatus.npset('maintenance', '')
def setup_interfaces(): """ Set up the IPv4 addresses of some interfaces if requested. """ if sputils.check_in_lxc(): rdebug('running in an LXC container, not setting up interfaces') reactive.set_state('l-storpool-config.config-network') return rdebug('trying to parse the StorPool interface configuration') spstatus.npset('maintenance', 'parsing the StorPool interface configuration') cfg = spconfig.get_dict() ifaces = cfg.get('SP_IFACE', None) if ifaces is None: hookenv.set('error', 'No SP_IFACES in the StorPool config') return rdebug('got interfaces: {ifaces}'.format(ifaces=ifaces)) spcnetwork.fixup_interfaces(ifaces) rdebug('well, looks like it is all done...') reactive.set_state('l-storpool-config.config-network') spstatus.npset('maintenance', '')