-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cephadm: add-repo: add --version #33961
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3237,9 +3237,9 @@ class CustomValidation(argparse.Action): | |
################################## | ||
|
||
def get_distro(): | ||
id_ = None | ||
version = None | ||
codename = None | ||
distro = None | ||
distro_version = None | ||
distro_codename = None | ||
with open('/etc/os-release', 'r') as f: | ||
for line in f.readlines(): | ||
line = line.strip() | ||
|
@@ -3249,20 +3249,21 @@ def get_distro(): | |
if val[0] == '"' and val[-1] == '"': | ||
val = val[1:-1] | ||
if var == 'ID': | ||
id_ = val.lower() | ||
distro = val.lower() | ||
elif var == 'VERSION_ID': | ||
version = val.lower() | ||
distro_version = val.lower() | ||
elif var == 'VERSION_CODENAME': | ||
codename = val.lower() | ||
return id_, version, codename | ||
distro_codename = val.lower() | ||
return distro, distro_version, distro_codename | ||
|
||
class Packager(object): | ||
def __init__(self, stable=None, branch=None, commit=None): | ||
def __init__(self, stable=None, version=None, branch=None, commit=None): | ||
assert \ | ||
(stable and not branch and not commit) or \ | ||
(not stable and branch) or \ | ||
(not stable and not branch and not commit) | ||
(not stable and not version and branch) or \ | ||
(not stable and not version and not branch and not commit) | ||
self.stable = stable | ||
self.version = version | ||
self.branch = branch | ||
self.commit = commit | ||
|
||
|
@@ -3272,13 +3273,13 @@ class Packager(object): | |
def rm_repo(self): | ||
raise NotImplementedError | ||
|
||
def query_shaman(self, distro, version, branch, commit): | ||
def query_shaman(self, distro, distro_version, branch, commit): | ||
# query shaman | ||
logging.info('Fetching repo metadata from shaman and chacra...') | ||
shaman_url = 'https://shaman.ceph.com/api/repos/ceph/{version}/{sha1}/{distro}/{distro_version}/repo/?arch={arch}'.format( | ||
shaman_url = 'https://shaman.ceph.com/api/repos/ceph/{branch}/{sha1}/{distro}/{distro_version}/repo/?arch={arch}'.format( | ||
distro=distro, | ||
distro_version=version, | ||
version=branch, | ||
distro_version=distro_version, | ||
branch=branch, | ||
sha1=commit or 'latest', | ||
arch=get_arch() | ||
) | ||
|
@@ -3316,11 +3317,12 @@ class Apt(Packager): | |
'debian': 'debian', | ||
} | ||
|
||
def __init__(self, stable, branch, commit, | ||
distro, version, codename): | ||
super(Apt, self).__init__(stable=stable, branch=branch, commit=commit) | ||
def __init__(self, stable, version, branch, commit, | ||
distro, distro_version, distro_codename): | ||
super(Apt, self).__init__(stable=stable, version=version, | ||
branch=branch, commit=commit) | ||
self.distro = self.DISTRO_NAMES[distro] | ||
self.codename = codename | ||
self.distro_codename = distro_codename | ||
|
||
def repo_path(self): | ||
return '/etc/apt/sources.list.d/ceph.list' | ||
|
@@ -3339,10 +3341,15 @@ class Apt(Packager): | |
f.write(key) | ||
|
||
if self.stable: | ||
content = 'deb %s/debian-%s/ %s main\n' % ( | ||
args.repo_url, self.stable, self.codename) | ||
if self.version: | ||
content = 'deb %s/debian-%s-%s/ %s main\n' % ( | ||
args.repo_url, self.stable, self.version, | ||
self.distro_codename) | ||
else: | ||
content = 'deb %s/debian-%s/ %s main\n' % ( | ||
args.repo_url, self.stable, self.distro_codename) | ||
else: | ||
content = self.query_shaman(self.distro, self.codename, self.branch, | ||
content = self.query_shaman(self.distro, self.distro_codename, self.branch, | ||
self.commit) | ||
|
||
logging.info('Installing repo file at %s...' % self.repo_path()) | ||
|
@@ -3385,10 +3392,11 @@ class YumDnf(Packager): | |
'fedora': ('fedora', 'fc'), | ||
} | ||
|
||
def __init__(self, stable, branch, commit, | ||
distro, version): | ||
super(YumDnf, self).__init__(stable=stable, branch=branch, commit=commit) | ||
self.major = int(version.split('.')[0]) | ||
def __init__(self, stable, version, branch, commit, | ||
distro, distro_version): | ||
super(YumDnf, self).__init__(stable=stable, version=version, | ||
branch=branch, commit=commit) | ||
self.major = int(distro_version.split('.')[0]) | ||
self.distro_normalized = self.DISTRO_NAMES[distro][0] | ||
self.distro_code = self.DISTRO_NAMES[distro][1] + str(self.major) | ||
if (self.distro_code == 'fc' and self.major >= 30) or \ | ||
|
@@ -3458,7 +3466,13 @@ class YumDnf(Packager): | |
|
||
def repo_baseurl(self): | ||
assert self.stable | ||
return '%s/rpm-%s/%s' % (args.repo_url, self.stable, self.distro_code) | ||
if self.version: | ||
return '%s/rpm-%s-%s/%s' % (args.repo_url, self.stable, | ||
self.version, | ||
self.distro_code) | ||
else: | ||
return '%s/rpm-%s/%s' % (args.repo_url, self.stable, | ||
self.distro_code) | ||
|
||
def add_repo(self): | ||
if self.stable: | ||
|
@@ -3515,14 +3529,15 @@ class Zypper(Packager): | |
'opensuse-leap' | ||
] | ||
|
||
def __init__(self, stable, branch, commit, | ||
distro, version): | ||
super(Zypper, self).__init__(stable=stable, branch=branch, commit=commit) | ||
def __init__(self, stable, version, branch, commit, | ||
distro, distro_version): | ||
super(Zypper, self).__init__(stable=stable, version=version, | ||
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 | ||
self.distro_version = '15.1' | ||
if 'tumbleweed' not in distro and distro_version is not None: | ||
self.distro_version = distro_version | ||
|
||
def custom_repo(self, **kw): | ||
""" | ||
|
@@ -3558,6 +3573,9 @@ class Zypper(Packager): | |
|
||
def repo_baseurl(self): | ||
assert self.stable | ||
if self.version: | ||
return '%s/rpm-%s-%s/%s' % (args.repo_url, self.stable, | ||
self.version, self.distro) | ||
return '%s/rpm-%s/%s' % (args.repo_url, self.stable, self.distro) | ||
|
||
def add_repo(self): | ||
|
@@ -3577,7 +3595,7 @@ class Zypper(Packager): | |
) | ||
content += '\n\n' | ||
else: | ||
content = self.query_shaman(self.distro, self.version, | ||
content = self.query_shaman(self.distro, self.distro_version, | ||
self.branch, | ||
self.commit) | ||
|
||
|
@@ -3597,22 +3615,49 @@ class Zypper(Packager): | |
self.install(['podman']) | ||
|
||
|
||
def create_packager(stable=None, branch=None, commit=None): | ||
distro, version, codename = get_distro() | ||
def create_packager(stable=None, version=None, branch=None, commit=None): | ||
distro, distro_version, distro_codename = get_distro() | ||
if distro in YumDnf.DISTRO_NAMES: | ||
return YumDnf(stable=stable, branch=branch, commit=commit, | ||
distro=distro, version=version) | ||
return YumDnf(stable=stable, version=version, | ||
branch=branch, commit=commit, | ||
distro=distro, distro_version=distro_version) | ||
elif distro in Apt.DISTRO_NAMES: | ||
return Apt(stable=stable, branch=branch, commit=commit, | ||
distro=distro, version=version, codename=codename) | ||
return Apt(stable=stable, version=version, | ||
branch=branch, commit=commit, | ||
distro=distro, distro_version=distro_version, | ||
distro_codename=distro_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)) | ||
return Zypper(stable=stable, version=version, | ||
branch=branch, commit=commit, | ||
distro=distro, distro_version=distro_version) | ||
raise Error('Distro %s version %s not supported' % (distro, distro_version)) | ||
|
||
|
||
def command_add_repo(): | ||
pkg = create_packager(stable=args.release, branch=args.dev, | ||
if args.version and args.release: | ||
raise Error('you can specify either --release or --version but not both') | ||
if args.version: | ||
try: | ||
(x, y, z) = args.version.split('.') | ||
except Exception as e: | ||
raise Error('version must be in the form x.y.z (e.g., 15.2.0)') | ||
relnames = { | ||
'16': 'pacific', | ||
'15': 'octopus', | ||
'14': 'nautilus', | ||
'13': 'mimic', | ||
'12': 'luminous', | ||
'11': 'kraken', | ||
'10': 'jewel', | ||
} | ||
Comment on lines
+3644
to
+3652
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like this, as it requires maintenance. can we live without it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think so as it's part of the URL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, these dirs are new, though, so we could move them to just rpm-X.Y.Z and debian-X.Y.Z |
||
args.release = relnames.get(x, None) | ||
if not args.release: | ||
raise Error('unknown release %s (not in %s)' % ( | ||
x, ' '.join(relnames.values()))) | ||
liewegas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
pkg = create_packager(stable=args.release, | ||
version=args.version, | ||
branch=args.dev, | ||
commit=args.dev_commit) | ||
pkg.add_repo() | ||
|
||
|
@@ -3996,7 +4041,10 @@ def _get_parser(): | |
parser_add_repo.set_defaults(func=command_add_repo) | ||
parser_add_repo.add_argument( | ||
'--release', | ||
help='use specified upstream release') | ||
help='use latest version of a named release (e.g., octopus)') | ||
parser_add_repo.add_argument( | ||
'--version', | ||
help='use specific upstream version (x.y.z)') | ||
parser_add_repo.add_argument( | ||
'--dev', | ||
help='use specified bleeding edge build from git branch or tag') | ||
|
@@ -4008,7 +4056,7 @@ def _get_parser(): | |
help='specify alternative GPG key location') | ||
parser_add_repo.add_argument( | ||
'--repo-url', | ||
default='https://download.ceph.com/', | ||
default='https://download.ceph.com', | ||
help='specify alternative repo location') | ||
# TODO: proxy? | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?