Ejemplo n.º 1
0
def install_kata():
    """
    Install the Kata container runtime.

    :returns: None
    """
    dist = host.lsb_release()
    release = '{}_{}'.format(
        dist['DISTRIB_ID'],
        dist['DISTRIB_RELEASE']
    )

    arch = check_output(['arch']).decode().strip()

    archive = resource_get('kata-archive')

    if not archive or os.path.getsize(archive) == 0:
        status.maintenance('Installing Kata via apt')
        gpg_key = requests.get(
            'http://download.opensuse.org/repositories/home:/katacontainers:/'
            'releases:/{}:/master/x{}/Release.key'.format(arch, release)).text
        import_key(gpg_key)

        with open('/etc/apt/sources.list.d/kata-containers.list', 'w') as f:
            f.write(
                'deb http://download.opensuse.org/repositories/home:/'
                'katacontainers:/releases:/{}:/master/x{}/ /'
                .format(arch, release)
            )

        apt_update()
        apt_install(KATA_PACKAGES)

    else:
        status.maintenance('Installing Kata via resource')
        unpack = '/tmp/kata-debs'

        if not os.path.isdir(unpack):
            os.makedirs(unpack, exist_ok=True)

        check_call(['tar', '-xvf', archive, '-C', unpack])
        check_call('apt-get install -y {}/*.deb'.format(unpack), shell=True)

    status.active('Kata runtime available')
    set_state('kata.installed')
Ejemplo n.º 2
0
def configure_nvidia():
    """
    Based on charm config, install and configure Nivida drivers.

    :return: None
    """
    status.maintenance('Installing Nvidia drivers.')

    dist = host.lsb_release()
    release = '{}{}'.format(dist['DISTRIB_ID'].lower(),
                            dist['DISTRIB_RELEASE'])
    proxies = {"http": config('http_proxy'), "https": config('https_proxy')}
    ncr_gpg_key = requests.get(
        'https://nvidia.github.io/nvidia-container-runtime/gpgkey',
        proxies=proxies).text
    import_key(ncr_gpg_key)
    with open('/etc/apt/sources.list.d/nvidia-container-runtime.list',
              'w') as f:
        f.write('deb '
                'https://nvidia.github.io/libnvidia-container/{}/$(ARCH) /\n'.
                format(release))
        f.write(
            'deb '
            'https://nvidia.github.io/nvidia-container-runtime/{}/$(ARCH) /\n'.
            format(release))

    cuda_gpg_key = requests.get(
        'https://developer.download.nvidia.com/'
        'compute/cuda/repos/{}/x86_64/7fa2af80.pub'.format(
            release.replace('.', '')),
        proxies=proxies).text
    import_key(cuda_gpg_key)
    with open('/etc/apt/sources.list.d/cuda.list', 'w') as f:
        f.write('deb '
                'http://developer.download.nvidia.com/'
                'compute/cuda/repos/{}/x86_64 /\n'.format(
                    release.replace('.', '')))

    apt_update()

    apt_install(NVIDIA_PACKAGES, fatal=True)

    set_state('containerd.nvidia.ready')
    config_changed()
def configure_nvidia():
    """
    Based on charm config, install and configure Nivida drivers.

    :return: None
    """
    status.maintenance('Installing Nvidia drivers.')

    dist = host.lsb_release()
    os_release_id = dist['DISTRIB_ID'].lower()
    os_release_version_id = dist['DISTRIB_RELEASE']
    os_release_version_id_no_dot = os_release_version_id.replace('.', '')
    proxies = {
        "http": config('http_proxy'),
        "https": config('https_proxy')
    }
    key_urls = config('nvidia_apt_key_urls').split()
    for key_url in key_urls:
        formatted_key_url = key_url.format(
            id=os_release_id,
            version_id=os_release_version_id,
            version_id_no_dot=os_release_version_id_no_dot
        )
        gpg_key = requests.get(formatted_key_url, proxies=proxies).text
        import_key(gpg_key)

    sources = config('nvidia_apt_sources').splitlines()
    formatted_sources = [
        source.format(
            id=os_release_id,
            version_id=os_release_version_id,
            version_id_no_dot=os_release_version_id_no_dot
        )
        for source in sources
    ]
    with open('/etc/apt/sources.list.d/nvidia.list', 'w') as f:
        f.write('\n'.join(formatted_sources))

    apt_update()
    packages = config('nvidia_apt_packages').split()
    apt_install(packages, fatal=True)

    set_state('containerd.nvidia.ready')
    config_changed()
Ejemplo n.º 4
0
def configure_nvidia():
    status_set('maintenance', 'Installing Nvidia drivers.')

    dist = host.lsb_release()
    release = '{}{}'.format(dist['DISTRIB_ID'].lower(),
                            dist['DISTRIB_RELEASE'])

    ncr_gpg_key = requests.get(
        'https://nvidia.github.io/nvidia-container-runtime/gpgkey').text
    import_key(ncr_gpg_key)
    with open('/etc/apt/sources.list.d/nvidia-container-runtime.list',
              'w') as f:
        f.write('deb '
                'https://nvidia.github.io/libnvidia-container/{}/$(ARCH) /\n'.
                format(release))
        f.write(
            'deb '
            'https://nvidia.github.io/nvidia-container-runtime/{}/$(ARCH) /\n'.
            format(release))

    cuda_gpg_key = requests.get(
        'https://developer.download.nvidia.com/'
        'compute/cuda/repos/{}/x86_64/7fa2af80.pub'.format(
            release.replace('.', ''))).text
    import_key(cuda_gpg_key)
    with open('/etc/apt/sources.list.d/cuda.list', 'w') as f:
        f.write('deb '
                'http://developer.download.nvidia.com/'
                'compute/cuda/repos/{}/x86_64 /\n'.format(
                    release.replace('.', '')))

    apt_update()

    apt_install([
        'cuda-drivers',
        'nvidia-container-runtime',
    ], fatal=True)

    set_state('containerd.nvidia.ready')