/
install.py
670 lines (574 loc) · 19.8 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
import argparse
import logging
import os
from ceph_deploy import hosts
from ceph_deploy.cliutil import priority
from ceph_deploy.lib import remoto
from ceph_deploy.util.constants import default_components
from ceph_deploy.util.paths import gpg
LOG = logging.getLogger(__name__)
def sanitize_args(args):
"""
args may need a bunch of logic to set proper defaults that argparse is
not well suited for.
"""
if args.release is None:
args.release = 'mimic'
args.default_release = True
# XXX This whole dance is because --stable is getting deprecated
if args.stable is not None:
LOG.warning('the --stable flag is deprecated, use --release instead')
args.release = args.stable
# XXX Tango ends here.
return args
def detect_components(args, distro):
"""
Since the package split, now there are various different Ceph components to
install like:
* ceph
* ceph-mon
* ceph-mgr
* ceph-osd
* ceph-mds
This helper function should parse the args that may contain specifics about
these flags and return the default if none are passed in (which is, install
everything)
"""
# the flag that prevents all logic here is the `--repo` flag which is used
# when no packages should be installed, just the repo files, so check for
# that here and return an empty list (which is equivalent to say 'no
# packages should be installed')
if args.repo:
return []
flags = {
'install_osd': 'ceph-osd',
'install_rgw': 'ceph-radosgw',
'install_mds': 'ceph-mds',
'install_mon': 'ceph-mon',
'install_mgr': 'ceph-mgr',
'install_common': 'ceph-common',
'install_tests': 'ceph-test',
}
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
flags['install_rgw'] = 'radosgw'
if args.install_all:
return defaults
else:
components = []
for k, v in flags.items():
if getattr(args, k, False):
components.append(v)
# if we have some components selected from flags then return that,
# otherwise return defaults because no flags and no `--repo` means we
# should get all of them by default
return components or defaults
def install(args):
args = sanitize_args(args)
if args.repo:
return install_repo(args)
gpgcheck = 0 if args.nogpgcheck else 1
if args.version_kind == 'stable':
version = args.release
else:
version = getattr(args, args.version_kind)
version_str = args.version_kind
if version:
version_str += ' version {version}'.format(version=version)
LOG.debug(
'Installing %s on cluster %s hosts %s',
version_str,
args.cluster,
' '.join(args.host),
)
for hostname in args.host:
LOG.debug('Detecting platform for host %s ...', hostname)
distro = hosts.get(
hostname,
username=args.username,
# XXX this should get removed once ceph packages are split for
# upstream. If default_release is True, it means that the user is
# trying to install on a RHEL machine and should expect to get RHEL
# packages. Otherwise, it will need to specify either a specific
# version, or repo, or a development branch. Other distro users
# should not see any differences.
use_rhceph=args.default_release,
)
LOG.info(
'Distro info: %s %s %s',
distro.name,
distro.release,
distro.codename
)
components = detect_components(args, distro)
if distro.init == 'sysvinit' and args.cluster != 'ceph':
LOG.error('refusing to install on host: %s, with custom cluster name: %s' % (
hostname,
args.cluster,
)
)
LOG.error('custom cluster names are not supported on sysvinit hosts')
continue
rlogger = logging.getLogger(hostname)
rlogger.info('installing Ceph on %s' % hostname)
cd_conf = getattr(args, 'cd_conf', None)
# custom repo arguments
repo_url = os.environ.get('CEPH_DEPLOY_REPO_URL') or args.repo_url
gpg_url = os.environ.get('CEPH_DEPLOY_GPG_URL') or args.gpg_url
gpg_fallback = gpg.url('release')
if gpg_url is None and repo_url:
LOG.warning('--gpg-url was not used, will fallback')
LOG.warning('using GPG fallback: %s', gpg_fallback)
gpg_url = gpg_fallback
if args.local_mirror:
if args.username:
hostname = "%s@%s" % (args.username, hostname)
remoto.rsync(hostname, args.local_mirror, '/opt/ceph-deploy/repo', distro.conn.logger, sudo=True)
repo_url = 'file:///opt/ceph-deploy/repo'
gpg_url = 'file:///opt/ceph-deploy/repo/release.asc'
if repo_url: # triggers using a custom repository
# the user used a custom repo url, this should override anything
# we can detect from the configuration, so warn about it
if cd_conf:
if cd_conf.get_default_repo():
rlogger.warning('a default repo was found but it was \
overridden on the CLI')
if args.release in cd_conf.get_repos():
rlogger.warning('a custom repo was found but it was \
overridden on the CLI')
rlogger.info('using custom repository location: %s', repo_url)
distro.mirror_install(
distro,
repo_url,
gpg_url,
args.adjust_repos,
components=components,
gpgcheck=gpgcheck,
args=args
)
# Detect and install custom repos here if needed
elif should_use_custom_repo(args, cd_conf, repo_url):
LOG.info('detected valid custom repositories from config file')
custom_repo(distro, args, cd_conf, rlogger)
else: # otherwise a normal installation
distro.install(
distro,
args.version_kind,
version,
args.adjust_repos,
components=components,
gpgcheck = gpgcheck,
args=args
)
# Check the ceph version we just installed
hosts.common.ceph_version(distro.conn)
distro.conn.exit()
def should_use_custom_repo(args, cd_conf, repo_url):
"""
A boolean to determine the logic needed to proceed with a custom repo
installation instead of cramming everything nect to the logic operator.
"""
if repo_url:
# repo_url signals a CLI override, return False immediately
return False
if cd_conf:
if cd_conf.has_repos:
has_valid_release = args.release in cd_conf.get_repos()
has_default_repo = cd_conf.get_default_repo()
if has_valid_release or has_default_repo:
return True
return False
def custom_repo(distro, args, cd_conf, rlogger, install_ceph=None):
"""
A custom repo install helper that will go through config checks to retrieve
repos (and any extra repos defined) and install those
``cd_conf`` is the object built from argparse that holds the flags and
information needed to determine what metadata from the configuration to be
used.
"""
default_repo = cd_conf.get_default_repo()
components = detect_components(args, distro)
if args.release in cd_conf.get_repos():
LOG.info('will use repository from conf: %s' % args.release)
default_repo = args.release
elif default_repo:
LOG.info('will use default repository: %s' % default_repo)
# At this point we know there is a cd_conf and that it has custom
# repos make sure we were able to detect and actual repo
if not default_repo:
LOG.warning('a ceph-deploy config was found with repos \
but could not default to one')
else:
options = dict(cd_conf.items(default_repo))
options['install_ceph'] = False if install_ceph is False else True
extra_repos = cd_conf.get_list(default_repo, 'extra-repos')
rlogger.info('adding custom repository file')
try:
distro.repo_install(
distro,
default_repo,
options.pop('baseurl'),
options.pop('gpgkey'),
components=components,
**options
)
except KeyError as err:
raise RuntimeError('missing required key: %s in config section: %s' % (err, default_repo))
for xrepo in extra_repos:
rlogger.info('adding extra repo file: %s.repo' % xrepo)
options = dict(cd_conf.items(xrepo))
try:
distro.repo_install(
distro,
xrepo,
options.pop('baseurl'),
options.pop('gpgkey'),
components=components,
**options
)
except KeyError as err:
raise RuntimeError('missing required key: %s in config section: %s' % (err, xrepo))
def install_repo(args):
"""
For a user that only wants to install the repository only (and avoid
installing Ceph and its dependencies).
"""
cd_conf = getattr(args, 'cd_conf', None)
for hostname in args.host:
LOG.debug('Detecting platform for host %s ...', hostname)
distro = hosts.get(
hostname,
username=args.username,
# XXX this should get removed once Ceph packages are split for
# upstream. If default_release is True, it means that the user is
# trying to install on a RHEL machine and should expect to get RHEL
# packages. Otherwise, it will need to specify either a specific
# version, or repo, or a development branch. Other distro users should
# not see any differences.
use_rhceph=args.default_release,
)
rlogger = logging.getLogger(hostname)
LOG.info(
'Distro info: %s %s %s',
distro.name,
distro.release,
distro.codename
)
custom_repo(distro, args, cd_conf, rlogger, install_ceph=False)
def remove(args, purge):
LOG.info('note that some dependencies *will not* be removed because they can cause issues with qemu-kvm')
LOG.info('like: librbd1 and librados2')
remove_action = 'Uninstalling'
if purge:
remove_action = 'Purging'
LOG.debug(
'%s on cluster %s hosts %s',
remove_action,
args.cluster,
' '.join(args.host),
)
for hostname in args.host:
LOG.debug('Detecting platform for host %s ...', hostname)
distro = hosts.get(
hostname,
username=args.username,
use_rhceph=True)
LOG.info('Distro info: %s %s %s', distro.name, distro.release, distro.codename)
rlogger = logging.getLogger(hostname)
rlogger.info('%s Ceph on %s' % (remove_action, hostname))
distro.uninstall(distro, purge=purge)
distro.conn.exit()
def uninstall(args):
remove(args, False)
def purge(args):
remove(args, True)
def purgedata(args):
LOG.debug(
'Purging data from cluster %s hosts %s',
args.cluster,
' '.join(args.host),
)
installed_hosts = []
for hostname in args.host:
distro = hosts.get(hostname, username=args.username)
ceph_is_installed = distro.conn.remote_module.which('ceph')
if ceph_is_installed:
installed_hosts.append(hostname)
distro.conn.exit()
if installed_hosts:
LOG.error("Ceph is still installed on: %s", installed_hosts)
raise RuntimeError("refusing to purge data while Ceph is still installed")
for hostname in args.host:
distro = hosts.get(hostname, username=args.username)
LOG.info(
'Distro info: %s %s %s',
distro.name,
distro.release,
distro.codename
)
rlogger = logging.getLogger(hostname)
rlogger.info('purging data on %s' % hostname)
# Try to remove the contents of /var/lib/ceph first, don't worry
# about errors here, we deal with them later on
remoto.process.check(
distro.conn,
[
'rm', '-rf', '--one-file-system', '--', '/var/lib/ceph',
]
)
# If we failed in the previous call, then we probably have OSDs
# still mounted, so we unmount them here
if distro.conn.remote_module.path_exists('/var/lib/ceph'):
rlogger.warning(
'OSDs may still be mounted, trying to unmount them'
)
remoto.process.run(
distro.conn,
[
'find', '/var/lib/ceph',
'-mindepth', '1',
'-maxdepth', '2',
'-type', 'd',
'-exec', 'umount', '{}', ';',
]
)
# And now we try again to remove the contents, since OSDs should be
# unmounted, but this time we do check for errors
remoto.process.run(
distro.conn,
[
'rm', '-rf', '--one-file-system', '--', '/var/lib/ceph',
]
)
remoto.process.run(
distro.conn,
[
'rm', '-rf', '--one-file-system', '--', '/etc/ceph/',
]
)
distro.conn.exit()
class StoreVersion(argparse.Action):
"""
Like ``"store"`` but also remember which one of the exclusive
options was set.
There are three kinds of versions: stable, testing and dev.
This sets ``version_kind`` to be the right one of the above.
This kludge essentially lets us differentiate explicitly set
values from defaults.
"""
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values)
if self.dest == 'release':
self.dest = 'stable'
namespace.version_kind = self.dest
@priority(20)
def make(parser):
"""
Install Ceph packages on remote hosts.
"""
version = parser.add_mutually_exclusive_group()
# XXX deprecated in favor of release
version.add_argument(
'--stable',
nargs='?',
action=StoreVersion,
metavar='CODENAME',
help='[DEPRECATED] install a release known as CODENAME\
(done by default) (default: %(default)s)',
)
version.add_argument(
'--release',
nargs='?',
action=StoreVersion,
metavar='CODENAME',
help='install a release known as CODENAME\
(done by default) (default: %(default)s)',
)
version.add_argument(
'--testing',
nargs=0,
action=StoreVersion,
help='install the latest development release',
)
version.add_argument(
'--dev',
nargs='?',
action=StoreVersion,
const='master',
metavar='BRANCH_OR_TAG',
help='install a bleeding edge build from Git branch\
or tag (default: %(default)s)',
)
parser.add_argument(
'--dev-commit',
nargs='?',
action=StoreVersion,
metavar='COMMIT',
help='install a bleeding edge build from Git commit (defaults to master branch)',
)
version.set_defaults(
stable=None, # XXX deprecated in favor of release
release=None, # Set the default release in sanitize_args()
dev='master',
version_kind='stable',
)
parser.add_argument(
'--mon',
dest='install_mon',
action='store_true',
help='install the mon component only',
)
parser.add_argument(
'--mgr',
dest='install_mgr',
action='store_true',
help='install the mgr component only',
)
parser.add_argument(
'--mds',
dest='install_mds',
action='store_true',
help='install the mds component only',
)
parser.add_argument(
'--rgw',
dest='install_rgw',
action='store_true',
help='install the rgw component only',
)
parser.add_argument(
'--osd',
dest='install_osd',
action='store_true',
help='install the osd component only',
)
parser.add_argument(
'--tests',
dest='install_tests',
action='store_true',
help='install the testing components',
)
parser.add_argument(
'--cli', '--common',
dest='install_common',
action='store_true',
help='install the common component only',
)
parser.add_argument(
'--all',
dest='install_all',
action='store_true',
help='install all Ceph components (mon, osd, mds, rgw) except tests. This is the default',
)
repo = parser.add_mutually_exclusive_group()
repo.add_argument(
'--adjust-repos',
dest='adjust_repos',
action='store_true',
help='install packages modifying source repos',
)
repo.add_argument(
'--no-adjust-repos',
dest='adjust_repos',
action='store_false',
help='install packages without modifying source repos',
)
repo.add_argument(
'--repo',
action='store_true',
help='install repo files only (skips package installation)',
)
repo.set_defaults(
adjust_repos=True,
)
parser.add_argument(
'host',
metavar='HOST',
nargs='+',
help='hosts to install on',
)
parser.add_argument(
'--local-mirror',
nargs='?',
const='PATH',
default=None,
help='Fetch packages and push them to hosts for a local repo mirror',
)
parser.add_argument(
'--repo-url',
nargs='?',
dest='repo_url',
help='specify a repo URL that mirrors/contains Ceph packages',
)
parser.add_argument(
'--gpg-url',
nargs='?',
dest='gpg_url',
help='specify a GPG key URL to be used with custom repos\
(defaults to ceph.com)'
)
parser.add_argument(
'--nogpgcheck',
action='store_true',
help='install packages without gpgcheck',
)
parser.set_defaults(
func=install,
)
@priority(80)
def make_uninstall(parser):
"""
Remove Ceph packages from remote hosts.
"""
parser.add_argument(
'host',
metavar='HOST',
nargs='+',
help='hosts to uninstall Ceph from',
)
parser.set_defaults(
func=uninstall,
)
@priority(80)
def make_purge(parser):
"""
Remove Ceph packages from remote hosts and purge all data.
"""
parser.add_argument(
'host',
metavar='HOST',
nargs='+',
help='hosts to purge Ceph from',
)
parser.set_defaults(
func=purge,
)
@priority(80)
def make_purge_data(parser):
"""
Purge (delete, destroy, discard, shred) any Ceph data from /var/lib/ceph
"""
parser.add_argument(
'host',
metavar='HOST',
nargs='+',
help='hosts to purge Ceph data from',
)
parser.set_defaults(
func=purgedata,
)