]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Add Packager for Zypper (openSUSE / SLES)
authorKristoffer Grönlund <kgronlund@suse.com>
Fri, 21 Feb 2020 13:41:12 +0000 (14:41 +0100)
committerKristoffer Grönlund <kgronlund@suse.com>
Fri, 21 Feb 2020 13:54:09 +0000 (14:54 +0100)
Adds basic support for using zypper as the packager.

Signed-off-by: Kristoffer Grönlund <kgronlund@suse.com>
src/cephadm/cephadm

index afe33a7128085523e0a92ea1d7fd01d8fc4e0e8e..a7fbf79a68225202b38e1256b146c9023b0c2ea7 100755 (executable)
@@ -2950,6 +2950,99 @@ class YumDnf(Packager):
         self.install(['podman'])
 
 
+class Zypper(Packager):
+    DISTRO_NAMES = [
+        'sles',
+        'opensuse-tumbleweed',
+        'opensuse-leap'
+    ]
+
+    def __init__(self, stable, branch, commit,
+                 distro, version):
+        super(Zypper, self).__init__(stable=stable, branch=branch, commit=commit)
+        self.tool = 'zypper'
+        self.distro = 'opensuse'
+        self.version = '15.1'
+        if 'tumbleweed' not in distro and version is not None:
+            self.version = version
+
+    def custom_repo(self, **kw):
+        """
+        See YumDnf for format explanation.
+        """
+        lines = []
+
+        # by using tuples (vs a dict) we preserve the order of what we want to
+        # return, like starting with a [repo name]
+        tmpl = (
+            ('reponame', '[%s]'),
+            ('name', 'name=%s'),
+            ('baseurl', 'baseurl=%s'),
+            ('enabled', 'enabled=%s'),
+            ('gpgcheck', 'gpgcheck=%s'),
+            ('_type', 'type=%s'),
+            ('gpgkey', 'gpgkey=%s'),
+            ('proxy', 'proxy=%s'),
+            ('priority', 'priority=%s'),
+        )
+
+        for line in tmpl:
+            tmpl_key, tmpl_value = line  # key values from tmpl
+
+            # ensure that there is an actual value (not None nor empty string)
+            if tmpl_key in kw and kw.get(tmpl_key) not in (None, ''):
+                lines.append(tmpl_value % kw.get(tmpl_key))
+
+        return '\n'.join(lines)
+
+    def repo_path(self):
+        return '/etc/zypp/repos.d/ceph.repo'
+
+    def repo_baseurl(self):
+        assert self.stable
+        return '%s/rpm-%s/%s' % (args.repo_url, self.stable, self.distro)
+
+    def add_repo(self):
+        if self.stable:
+            content = ''
+            for n, t in {
+                    'Ceph': '$basearch',
+                    'Ceph-noarch': 'noarch',
+                    'Ceph-source': 'SRPMS'}.items():
+                content += '[%s]\n' % (n)
+                content += self.custom_repo(
+                    name='Ceph %s' % t,
+                    baseurl=self.repo_baseurl() + '/' + t,
+                    enabled=1,
+                    gpgcheck=1,
+                    gpgkey=self.repo_gpgkey()[0],
+                )
+                content += '\n\n'
+        else:
+            content = self.query_shaman(self.distro, self.version,
+                                        self.branch,
+                                        self.commit)
+
+        logging.info('Writing repo to %s...' % self.repo_path())
+        with open(self.repo_path(), 'w') as f:
+            f.write(content)
+
+    def rm_repo(self):
+        if os.path.exists(self.repo_path()):
+            os.unlink(self.repo_path())
+
+    def install(self, ls):
+        logger.info('Installing packages %s...' % ls)
+        call_throws([self.tool, 'in', '-y'] + ls)
+
+        if 'chrony' in ls:
+            # ensure chrony service is enabled/started
+            call_throws(['systemctl', 'enable', '--now', 'chronyd'])
+
+    def install_podman(self):
+        self.install(['podman'])
+
+
 def create_packager(stable=None, branch=None, commit=None):
     distro, version, codename = get_distro()
     if distro in YumDnf.DISTRO_NAMES:
@@ -2958,8 +3051,12 @@ def create_packager(stable=None, branch=None, commit=None):
     elif distro in Apt.DISTRO_NAMES:
         return Apt(stable=stable, branch=branch, commit=commit,
                    distro=distro, version=version, codename=codename)
+    elif distro in Zypper.DISTRO_NAMES:
+        return Zypper(stable=stable, branch=branch, commit=commit,
+                      distro=distro, version=version)
     raise Error('Distro %s version %s not supported' % (distro, version))
 
+
 def command_add_repo():
     pkg = create_packager(stable=args.release, branch=args.dev,
                           commit=args.dev_commit)