from ceph_deploy.lib import remoto
from ceph_deploy.hosts.centos.install import repo_install, mirror_install  # noqa
from ceph_deploy.hosts.util import install_yum_priorities
from ceph_deploy.util.paths import gpg


def install(distro, version_kind, version, adjust_repos, **kw):
    # note: when split packages for ceph land for Fedora,
    # `kw['components']` will have those. Unused for now.
    logger = distro.conn.logger
    release = distro.release
    machine = distro.machine_type

    if version_kind in ['stable', 'testing']:
        key = 'release'
    else:
        key = 'autobuild'

    if adjust_repos:
        install_yum_priorities(distro)
        distro.conn.remote_module.enable_yum_priority_obsoletes()
        logger.warning('check_obsoletes has been enabled for Yum priorities plugin')

        if version_kind != 'dev':
            remoto.process.run(
                distro.conn,
                [
                    'rpm',
                    '--import',
                    gpg.url(key)
                ]
            )

            if version_kind == 'stable':
                url = 'http://ceph.com/rpm-{version}/fc{release}/'.format(
                    version=version,
                    release=release,
                    )
            elif version_kind == 'testing':
                url = 'http://ceph.com/rpm-testing/fc{release}'.format(
                    release=release,
                    )

            remoto.process.run(
                distro.conn,
                [
                    'rpm',
                    '-Uvh',
                    '--replacepkgs',
                    '--force',
                    '--quiet',
                    '{url}noarch/ceph-release-1-0.fc{release}.noarch.rpm'.format(
                        url=url,
                        release=release,
                        ),
                ]
            )

        if version_kind == 'dev':
            logger.info('skipping install of ceph-release package')
            logger.info('repo file will be created manually')
            mirror_install(
                distro,
                'http://gitbuilder.ceph.com/ceph-rpm-fc{release}-{machine}-basic/ref/{version}/'.format(
                    release=release.split(".", 1)[0],
                    machine=machine,
                    version=version),
                gpg.url(key),
                adjust_repos=True,
                extra_installs=False
            )

        # set the right priority
        logger.warning('ensuring that /etc/yum.repos.d/ceph.repo contains a high priority')
        distro.conn.remote_module.set_repo_priority(['Ceph', 'Ceph-noarch', 'ceph-source'])
        logger.warning('altered ceph.repo priorities to contain: priority=1')

    remoto.process.run(
        distro.conn,
        [
            'yum',
            '-y',
            '-q',
            'install',
            'ceph',
            'ceph-radosgw',
        ],
    )

@@ -207,16 +207,58 @@
 ort gpg%0A
+from ceph_deploy.util import pkg_managers%0A
 %0A%0Adef in
@@ -527,16 +527,165 @@
 e_type%0A%0A
+    if distro.normalized_release.int_major %3E= 22:%0A        packager = pkg_managers.DNF(distro)%0A    else:%0A        packager = pkg_managers.Yum(distro)%0A%0A
     if v
@@ -2941,136 +2941,35 @@
     
-remoto.process.run(%0A        distro.conn,%0A        %5B%0A            'yum',%0A            '-y',%0A            '-q',%0A            'install',
+packager.install(%0A        %5B
 %0A   
@@ -3011,17 +3011,16 @@
 radosgw'
-,
 %0A       
@@ -3021,16 +3021,15 @@
        %5D
-,
 %0A    )%0A

Use DNF by default for Fedora >=22