Пример #1
0
def purge_containerd():
    """
    Purge Containerd from the cluster.

    :return: None
    """
    status.maintenance('Removing containerd from principal')

    host.service_stop('containerd.service')
    apt_unhold(CONTAINERD_PACKAGE)
    apt_purge(CONTAINERD_PACKAGE, fatal=True)

    if is_state('containerd.nvidia.ready'):
        nvidia_packages = config('nvidia_apt_packages').split()
        apt_purge(nvidia_packages, fatal=True)

    sources = ['/etc/apt/sources.list.d/nvidia.list']

    for f in sources:
        if os.path.isfile(f):
            os.remove(f)

    apt_autoremove(purge=True, fatal=True)

    remove_state('containerd.ready')
    remove_state('containerd.installed')
    remove_state('containerd.nvidia.ready')
    remove_state('containerd.nvidia.checked')
    remove_state('containerd.nvidia.available')
    remove_state('containerd.version-published')
Пример #2
0
def unhold_all():
    """
    Unhold Packages.

    :return: None
    """
    for k in docker_packages.keys():
        apt_unhold(docker_packages[k])
def puppet_version_config_changed():
    '''React to pin-puppet version changed
    '''
    p = PuppetConfigs()
    # Reinstall puppet to specified version
    hookenv.status_set('maintenance', 'Re-installing puppet.')
    if config.previous('pin-puppet') != config['pin-puppet']:
        apt_unhold(p.puppet_purge)
        apt_purge(p.puppet_purge)
        PuppetConfigs.install_puppet(p)
Пример #4
0
def toggle_docker_daemon_source():
    """
    A disruptive reaction to config changing that will remove the existing
    docker daemon and install the latest available deb from the upstream PPA,
    Nvidia PPA, or Universe depending on the docker_runtime setting.

    :return: None or False
    """

    # This returns a list of packages not currently installed on the system
    # based on the parameters input. Use this to check if we have taken
    # prior action against a docker deb package.
    installed = []
    for k in docker_packages.keys():
        packages = filter_installed_packages(docker_packages[k])
        if packages == []:
            installed.append(k)

    # None of the docker packages are installed.
    if len(installed) == 0:
        # We have not reached installation phase, return until
        # we can reasonably re-test this scenario.
        hookenv.log('No supported docker runtime is installed. Noop.')
        return

    runtime = determine_apt_source()
    if not docker_packages.get(runtime):
        hookenv.log('Unknown runtime {}'.format(runtime))
        return False

    hookenv.log('Runtime to install {}'.format(runtime))

    # Workaround
    # https://bugs.launchpad.net/ubuntu/+source/docker.io/+bug/1724353.
    if os.path.exists('/var/lib/docker/nuke-graph-directory.sh'):
        hookenv.log('Workaround bug 1724353')
        cmd = "sed -i '1i#!/bin/bash' /var/lib/docker/nuke-graph-directory.sh"
        check_call(split(cmd))

    # The package we want is not installed
    # so we need to uninstall either of the others that are installed
    # and reset the state to forcea reinstall.
    if runtime not in installed:
        host.service_stop('docker')
        for k in docker_packages.keys():
            package_list = " ".join(docker_packages[k])
            hookenv.log('Removing package(s): {}.'.format(package_list))
            apt_unhold(docker_packages[k])
            apt_purge(docker_packages[k])
            remove_state('docker.ready')
            remove_state('docker.available')
    else:
        hookenv.log('Not touching packages.')
Пример #5
0
def remove():
    """
    Remove the docker daemon after
    relation departs.

    :return: None
    """
    host.service_stop('docker')
    for k in docker_packages.keys():
        package_list = " ".join(docker_packages[k])
        hookenv.log('Removing package(s): {}.'.format(package_list))
        apt_unhold(docker_packages[k])
        apt_purge(docker_packages[k])
Пример #6
0
def remove():
    """
    Remove the docker daemon after
    relation departs.

    :return: None
    """
    host.service_stop("docker")
    for k in docker_packages.keys():
        package_list = " ".join(docker_packages[k])
        hookenv.log("Removing package(s): {}.".format(package_list))
        apt_unhold(docker_packages[k])
        apt_purge(docker_packages[k])

    shutil.rmtree("/etc/systemd/system/docker.service.d/", ignore_errors=True)
Пример #7
0
def ensure_package_status():
    '''Hold or unhold packages per the package_status configuration option.

    All packages installed using this module and handlers are affected.

    An mechanism may be added in the future to override this for a
    subset of installed packages.
    '''
    packages = installed()
    if not packages:
        return
    config = hookenv.config()
    package_status = config.get('package_status') or ''
    changed = reactive.helpers.data_changed('apt.package_status',
                                            (package_status, sorted(packages)))
    if changed:
        if package_status == 'hold':
            hookenv.log('Holding packages {}'.format(','.join(packages)))
            fetch.apt_hold(packages)
        else:
            hookenv.log('Unholding packages {}'.format(','.join(packages)))
            fetch.apt_unhold(packages)
    reactive.remove_state('apt.needs_hold')
Пример #8
0
def ensure_package_status():
    '''Hold or unhold packages per the package_status configuration option.

    All packages installed using this module and handlers are affected.

    An mechanism may be added in the future to override this for a
    subset of installed packages.
    '''
    packages = installed()
    if not packages:
        return
    config = hookenv.config()
    package_status = config['package_status']
    changed = reactive.helpers.data_changed('apt.package_status',
                                            (package_status, sorted(packages)))
    if changed:
        if package_status == 'hold':
            hookenv.log('Holding packages {}'.format(','.join(packages)))
            fetch.apt_hold(packages)
        else:
            hookenv.log('Unholding packages {}'.format(','.join(packages)))
            fetch.apt_unhold(packages)
    reactive.remove_state('apt.needs_hold')
Пример #9
0
def unholdall():
    for k in dockerpackages.keys():
        apt_unhold(dockerpackages[k])