]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-7505] add support for archlinux
authorHacKan <hackan@gmail.com>
Wed, 24 Jan 2018 01:32:05 +0000 (22:32 -0300)
committerHacKan <hackan@gmail.com>
Fri, 26 Jan 2018 03:51:06 +0000 (00:51 -0300)
hosts: add arch based on fedora and add detection for distro.
util: add pacman package manager and archlinux default package.
install: add distro detection and package selection

ceph_deploy/hosts/__init__.py
ceph_deploy/hosts/arch/__init__.py [new file with mode: 0644]
ceph_deploy/hosts/arch/install.py [new file with mode: 0644]
ceph_deploy/hosts/arch/mon/__init__.py [new file with mode: 0644]
ceph_deploy/hosts/arch/uninstall.py [new file with mode: 0644]
ceph_deploy/install.py
ceph_deploy/util/constants.py
ceph_deploy/util/pkg_managers.py
ceph_deploy/util/system.py

index c8605d5d5e39055be7b7c492e799e816dd1bfa41..1df4f5a54ba0b0b18f6d467d2a13feb9ec10509b 100644 (file)
@@ -7,7 +7,7 @@ on the type of distribution/version we are dealing with.
 import logging
 from ceph_deploy import exc
 from ceph_deploy.util import versions
-from ceph_deploy.hosts import debian, centos, fedora, suse, remotes, rhel
+from ceph_deploy.hosts import debian, centos, fedora, suse, remotes, rhel, arch
 from ceph_deploy.connection import get_connection
 
 logger = logging.getLogger()
@@ -69,7 +69,8 @@ def get(hostname,
     module.is_el = module.normalized_name in ['redhat', 'centos', 'fedora', 'scientific', 'oracle', 'virtuozzo']
     module.is_rpm = module.normalized_name in ['redhat', 'centos',
                                                'fedora', 'scientific', 'suse', 'oracle', 'virtuozzo']
-    module.is_deb = not module.is_rpm
+    module.is_deb = module.normalized_name in ['debian', 'ubuntu']
+    module.is_pkgtarxz = module.normalized_name in ['arch']
     module.release = release
     module.codename = codename
     module.conn = conn
@@ -93,11 +94,12 @@ def _get_distro(distro, fallback=None, use_rhceph=False):
         'ubuntu': debian,
         'centos': centos,
         'scientific': centos,
-        'oracle' : centos,
+        'oracle': centos,
         'redhat': centos,
         'fedora': fedora,
         'suse': suse,
-        'virtuozzo' : centos
+        'virtuozzo': centos,
+        'arch': arch
         }
 
     if distro == 'redhat' and use_rhceph:
@@ -122,6 +124,8 @@ def _normalized_distro_name(distro):
         return 'ubuntu'
     elif distro.startswith('virtuozzo'):
         return 'virtuozzo'
+    elif distro.startswith('arch'):
+        return 'arch'
     return distro
 
 
diff --git a/ceph_deploy/hosts/arch/__init__.py b/ceph_deploy/hosts/arch/__init__.py
new file mode 100644 (file)
index 0000000..2e8c0ab
--- /dev/null
@@ -0,0 +1,26 @@
+from . import mon  # noqa
+from ceph_deploy.hosts.centos.install import repo_install  # noqa
+from .install import install, mirror_install  # noqa
+from .uninstall import uninstall  # noqa
+from ceph_deploy.util import pkg_managers
+
+# Allow to set some information about this distro
+#
+
+distro = None
+release = None
+codename = None
+
+
+def choose_init(module):
+    """
+    Select a init system
+
+    Returns the name of a init system (upstart, sysvinit ...).
+    """
+
+    return 'systemd'
+
+
+def get_packager(module):
+    return pkg_managers.Pacman(module)
diff --git a/ceph_deploy/hosts/arch/install.py b/ceph_deploy/hosts/arch/install.py
new file mode 100644 (file)
index 0000000..7625298
--- /dev/null
@@ -0,0 +1,49 @@
+from ceph_deploy.hosts.centos.install import repo_install, mirror_install  # noqa
+from ceph_deploy.hosts.common import map_components
+from ceph_deploy.util.system import enable_service, start_service
+
+
+NON_SPLIT_PACKAGES = [
+    'ceph-osd',
+    'ceph-radosgw',
+    'ceph-mds',
+    'ceph-mon',
+    'ceph-mgr',
+    'ceph-common',
+    'ceph-test'
+]
+
+SYSTEMD_UNITS = [
+    'ceph.target',
+    'ceph-radosgw.target',
+    'ceph-rbd-mirror.target',
+    'ceph-fuse.target',
+    'ceph-mds.target',
+    'ceph-mon.target',
+    'ceph-mgr.target',
+    'ceph-osd.target',
+]
+SYSTEMD_UNITS_SKIP_START = [
+    'ceph-mgr.target',
+    'ceph-mon.target',
+]
+SYSTEMD_UNITS_SKIP_ENABLE = [
+]
+
+
+def install(distro, version_kind, version, adjust_repos, **kw):
+    packages = map_components(
+        NON_SPLIT_PACKAGES,
+        kw.pop('components', [])
+    )
+
+    distro.packager.install(
+        packages
+    )
+
+    # Start and enable services
+    for unit in SYSTEMD_UNITS:
+        if unit not in SYSTEMD_UNITS_SKIP_START:
+            start_service(distro.conn, unit)
+        if unit not in SYSTEMD_UNITS_SKIP_ENABLE:
+            enable_service(distro.conn, unit)
diff --git a/ceph_deploy/hosts/arch/mon/__init__.py b/ceph_deploy/hosts/arch/mon/__init__.py
new file mode 100644 (file)
index 0000000..f266fb0
--- /dev/null
@@ -0,0 +1,2 @@
+from ceph_deploy.hosts.common import mon_add as add  # noqa
+from ceph_deploy.hosts.common import mon_create as create  # noqa
diff --git a/ceph_deploy/hosts/arch/uninstall.py b/ceph_deploy/hosts/arch/uninstall.py
new file mode 100644 (file)
index 0000000..0787392
--- /dev/null
@@ -0,0 +1,50 @@
+import logging
+
+from ceph_deploy.util.system import disable_service, stop_service
+from ceph_deploy.lib import remoto
+
+
+SYSTEMD_UNITS = [
+    'ceph-mds.target',
+    'ceph-mon.target',
+    'ceph-osd.target',
+    'ceph-radosgw.target',
+    'ceph-fuse.target',
+    'ceph-mgr.target',
+    'ceph-rbd-mirror.target',
+    'ceph.target',
+]
+
+
+def uninstall(distro, purge=False):
+    packages = [
+        'ceph',
+    ]
+
+    hostname = distro.conn.hostname
+    LOG = logging.getLogger(hostname)
+
+    # I need to stop and disable services prior package removal
+    LOG.info('stopping and disabling services on {}'.format(hostname))
+    for unit in SYSTEMD_UNITS:
+        stop_service(distro.conn, unit)
+        disable_service(distro.conn, unit)
+
+    # remoto.process.run(
+    #     distro.conn,
+    #     [
+    #         'systemctl',
+    #         'daemon-reload',
+    #     ]
+    # )
+
+    LOG.info('uninstalling packages on {}'.format(hostname))
+    distro.packager.remove(packages)
+
+    remoto.process.run(
+        distro.conn,
+        [
+            'systemctl',
+            'reset-failed',
+        ]
+    )
index f7b19edba40875a4e28827e21b26000a6c87de93..b0fd6e680da0f87cc248520306a6ebd8fbfc8d18 100644 (file)
@@ -63,6 +63,18 @@ def detect_components(args, distro):
 
     if distro.is_rpm:
         defaults = default_components.rpm
+    elif distro.is_pkgtarxz:
+        # archlinux doesn't have components!
+        flags = {
+            'install_osd': 'ceph',
+            'install_rgw': 'ceph',
+            'install_mds': 'ceph',
+            'install_mon': 'ceph',
+            'install_mgr': 'ceph',
+            'install_common': 'ceph',
+            'install_tests': 'ceph',
+        }
+        defaults = default_components.pkgtarxz
     else:
         defaults = default_components.deb
         # different naming convention for deb than rpm for radosgw
index 65775d9b093655a461d316f90c2b75d0a5032ada..a76dcd632ba831aa85e810eb4b17b0f741d8c026 100644 (file)
@@ -25,11 +25,12 @@ _base_components = [
     'ceph-mon',
 ]
 
-default_components = namedtuple('DefaultComponents', ['rpm', 'deb'])
+default_components = namedtuple('DefaultComponents', ['rpm', 'deb', 'pkgtarxz'])
 
 # the difference here is because RPMs currently name the radosgw differently than DEBs.
 # TODO: This needs to get unified once the packaging naming gets consistent
 default_components.rpm = tuple(_base_components + ['ceph-radosgw'])
 default_components.deb = tuple(_base_components + ['radosgw'])
+default_components.pkgtarxz = tuple(['ceph'])
 
 gpg_key_base_url = "download.ceph.com/keys/"
index bc20eb112efd1fb2724da3b12472fc329fcb8097..afd08429b640778c05f56a3dc9ad344e9ad912ae 100644 (file)
@@ -325,3 +325,55 @@ class Zypper(PackageManager):
     def clean(self):
         cmd = self.executable + ['refresh']
         return self._run(cmd)
+
+
+class Pacman(PackageManager):
+    """
+    Pacman package management
+    """
+
+    executable = [
+        'pacman',
+        '--noconfirm',
+    ]
+    name = 'pacman'
+
+    def install(self, packages, **kw):
+        if isinstance(packages, str):
+            packages = [packages]
+
+        extra_flags = kw.pop('extra_install_flags', None)
+        cmd = self.executable + [
+            '-Sy',
+        ]
+
+        if extra_flags:
+            if isinstance(extra_flags, str):
+                extra_flags = [extra_flags]
+            cmd.extend(extra_flags)
+        cmd.extend(packages)
+        return self._run(cmd)
+
+    def remove(self, packages, **kw):
+        if isinstance(packages, str):
+            packages = [packages]
+
+        extra_flags = kw.pop('extra_remove_flags', None)
+        cmd = self.executable + [
+            '-R'
+        ]
+        if extra_flags:
+            if isinstance(extra_flags, str):
+                extra_flags = [extra_flags]
+            cmd.extend(extra_flags)
+
+        cmd.extend(packages)
+        return self._run(cmd)
+
+    def clean(self):
+        cmd = self.executable + ['-Syy']
+        return self._run(cmd)
+
+    def add_repo_gpg_key(self, url):
+        cmd = ['pacman-key', '-a', url]
+        self._run(cmd)
index 05ee5297eb490b8548c4d8371dd490c2629e046d..cff13059c1959d375dae980c8f928f9af0e51311 100644 (file)
@@ -86,3 +86,95 @@ def enable_service(conn, service='ceph'):
                 'on',
             ]
         )
+
+
+def disable_service(conn, service='ceph'):
+    """
+    Disable a service on a remote host depending on the type of init system.
+    Obviously, this should be done for RHEL/Fedora/CentOS systems.
+
+    This function does not do any kind of detection.
+    """
+    if is_systemd(conn):
+        # Without the check, an error is raised trying to disable an
+        # already disabled service
+        if is_systemd_service_enabled(conn, service):
+            remoto.process.run(
+                conn,
+                [
+                    'systemctl',
+                    'disable',
+                    '{service}'.format(service=service),
+                ]
+            )
+
+
+def stop_service(conn, service='ceph'):
+    """
+    Stop a service on a remote host depending on the type of init system.
+    Obviously, this should be done for RHEL/Fedora/CentOS systems.
+
+    This function does not do any kind of detection.
+    """
+    if is_systemd(conn):
+        # Without the check, an error is raised trying to stop an
+        # already stopped service
+        if is_systemd_service_active(conn, service):
+            remoto.process.run(
+                conn,
+                [
+                    'systemctl',
+                    'stop',
+                    '{service}'.format(service=service),
+                ]
+            )
+
+
+def start_service(conn, service='ceph'):
+    """
+    Stop a service on a remote host depending on the type of init system.
+    Obviously, this should be done for RHEL/Fedora/CentOS systems.
+
+    This function does not do any kind of detection.
+    """
+    if is_systemd(conn):
+        remoto.process.run(
+            conn,
+            [
+                'systemctl',
+                'start',
+                '{service}'.format(service=service),
+            ]
+        )
+
+
+def is_systemd_service_active(conn, service='ceph'):
+    """
+    Detects if a systemd service is active or not.
+    """
+    _, _, returncode = remoto.process.check(
+        conn,
+        [
+            'systemctl',
+            'is-active',
+            '--quiet',
+            '{service}'.format(service=service),
+        ]
+    )
+    return returncode == 0
+
+
+def is_systemd_service_enabled(conn, service='ceph'):
+    """
+    Detects if a systemd service is enabled or not.
+    """
+    _, _, returncode = remoto.process.check(
+        conn,
+        [
+            'systemctl',
+            'is-enabled',
+            '--quiet',
+            '{service}'.format(service=service),
+        ]
+    )
+    return returncode == 0