From 5ff9abf77c6bdd1cb6c3414642ed6ab55ba0c2dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristoffer=20Gr=C3=B6nlund?= Date: Fri, 21 Feb 2020 14:41:12 +0100 Subject: [PATCH] cephadm: Add Packager for Zypper (openSUSE / SLES) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Adds basic support for using zypper as the packager. Signed-off-by: Kristoffer Grönlund --- src/cephadm/cephadm | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index afe33a71280..a7fbf79a682 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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) -- 2.39.5