ceph-daemon: add mons with 'deploy mon.x ...'

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2019-09-27 11:41:32 -05:00
parent 944867d015
commit e40fb1a787
2 changed files with 77 additions and 6 deletions

View File

@ -169,12 +169,55 @@ def extract_uid_gid():
def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid,
config=None, keyring=None):
# dirs, conf, keyring
create_daemon_dirs(
fsid, daemon_type, daemon_id,
uid, gid,
config, keyring)
if daemon_type == 'mon':
# tmp keyring file
tmp_keyring = tempfile.NamedTemporaryFile(mode='w')
os.fchmod(tmp_keyring.fileno(), 0o600)
os.fchown(tmp_keyring.fileno(), uid, gid)
tmp_keyring.write(keyring)
tmp_keyring.flush()
# tmp config file
tmp_config = tempfile.NamedTemporaryFile(mode='w')
os.fchmod(tmp_config.fileno(), 0o600)
os.fchown(tmp_config.fileno(), uid, gid)
tmp_config.write(config)
tmp_config.flush()
# --mkfs
create_daemon_dirs(fsid, daemon_type, daemon_id, uid, gid)
mon_dir = get_data_dir(args.data_dir, fsid, 'mon', daemon_id)
log_dir = get_log_dir(args.log_dir, fsid)
out = CephContainer(
image=args.image,
entrypoint='ceph-mon',
args=['--mkfs',
'-i', daemon_id,
'--fsid', fsid,
'-c', '/tmp/config',
'--keyring', '/tmp/keyring',
] + get_daemon_args(fsid, 'mon', daemon_id),
volume_mounts={
log_dir: '/var/log/ceph:z',
mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % (daemon_id),
tmp_keyring.name: '/tmp/keyring:z',
tmp_config.name: '/tmp/config:z',
},
).run()
# write conf
with open(mon_dir + '/conf', 'w') as f:
f.write(config)
else:
# dirs, conf, keyring
create_daemon_dirs(
fsid, daemon_type, daemon_id,
uid, gid,
config, keyring)
deploy_daemon_units(fsid, daemon_type, daemon_id, c)
def deploy_daemon_units(fsid, daemon_type, daemon_id, c):
# cmd
data_dir = get_data_dir(args.data_dir, fsid, daemon_type, daemon_id)
with open(data_dir + '/cmd', 'w') as f:
@ -418,7 +461,7 @@ def command_bootstrap():
f.write(config)
mon_c = get_container(fsid, 'mon', mon_id)
deploy_daemon(fsid, 'mon', mon_id, mon_c, uid, gid)
deploy_daemon_units(fsid, 'mon', mon_id, mon_c)
# create mgr
mgr_keyring = '[mgr.%s]\n\tkey = %s\n' % (mgr_id, mgr_key)
@ -446,6 +489,11 @@ def command_deploy():
if daemon_type not in ['mon', 'mgr', 'mds', 'osd', 'rgw']:
raise RuntimeError('daemon type %s not recognized' % daemon_type)
(config, keyring) = get_config_and_keyring()
if daemon_type == 'mon':
if args.mon_ip:
config += '[mon.%s]\n\tpublic_addr = %s\n' % (daemon_id, args.mon_ip)
else:
raise RuntimeError('must specify --mon-ip')
(uid, gid) = extract_uid_gid()
c = get_container(args.fsid, daemon_type, daemon_id)
deploy_daemon(args.fsid, daemon_type, daemon_id, c, uid, gid,
@ -668,6 +716,9 @@ parser_deploy.add_argument(
parser_deploy.add_argument(
'--conf-and-key',
help='JSON file with config and key')
parser_deploy.add_argument(
'--mon-ip',
help='mon IP')
args = parser.parse_args()

View File

@ -5,10 +5,30 @@ fsid=0a464092-dfd0-11e9-b903-002590e526e8
../src/ceph-daemon rm-cluster --fsid $fsid --force
../src/ceph-daemon bootstrap \
--mon-id a \
--mgr-id x \
--fsid $fsid \
--mon-ip 10.3.64.23 \
--output-keyring k \
--output-conf c
chmod 644 k c
# mon.b
../src/ceph-daemon deploy --name mon.b \
--fsid $fsid \
--mon-ip 10.3.64.27 \
--keyring /var/lib/ceph/$fsid/mon.a/keyring \
--conf c
# mgr.b
bin/ceph -c c -k k auth get-or-create mgr.y \
mon 'allow profile mgr' \
osd 'allow *' \
mds 'allow *' > k-mgr.y
../src/ceph-daemon deploy --name mgr.y \
--fsid $fsid \
--keyring k-mgr.y \
--conf c
bin/ceph -c c -k k -s