您的位置:首页 > 其它

ceph-deploy的rgw命令

2017-12-08 14:42 309 查看
ceph-deploy的rgw命令用于将conf_data 和key 写入到远程host中,并启动ceph-radosg和ceph.target
其入口函数为E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\rgw.py 中的make函数
@priority(30)
def make(parser):
"""
Ceph RGW daemon management
"""

rgw_parser = parser.add_subparsers(dest='subcommand')
rgw_parser.required = True
rgw_create = rgw_parser.add_parser(
'create',
help='Create an RGW instance'
)
rgw_create.add_argument(
'rgw',
metavar='HOST[:NAME]',
nargs='+',
type=colon_separated,
help='host (and optionally the daemon name) to deploy on. \
NAME is automatically prefixed with \'rgw.\'',
)
parser.set_defaults(
func=rgw,
)
make 函数为rgw 命令实现一个create的子命令,并指定了一个位置参数rgw,指定了子命令create的处理函数
是rgw
def rgw(args):
if args.subcommand == 'create':
rgw_create(args)
else:
LOG.error('subcommand %s not implemented', args.subcommand)
如果子命令是create的话,则调用rgw_create,否则输出error

def rgw_create(args):
conf_data = conf.ceph.load_raw(args)
LOG.debug(
'Deploying rgw, cluster %s hosts %s',
args.cluster,
' '.join(':'.join(x or '' for x in t) for t in args.rgw),
)

key = get_bootstrap_rgw_key(cluster=args.cluster)

bootstrapped = set()
errors = 0
for hostname, name in args.rgw:
try:
#通过形参args.rgw 中的hostname 得到远程机器的代理distro
distro = hosts.get(hostname, username=args.username)
rlogger = distro.conn.logger
LOG.info(
'Distro info: %s %s %s',
distro.name,
distro.release,
distro.codename
)
LOG.debug('remote host will use %s', distro.init)

if hostname not in bootstrapped:
#这里的bootstrapped 是空的,所以这个条件肯定成立,成立的话,则将conf_data写到远程host的目录中
bootstrapped.add(hostname)
LOG.debug('deploying rgw bootstrap to %s', hostname)
distro.conn.remote_module.write_conf(
args.cluster,
conf_data,
args.overwrite_conf,
)

path = '/var/lib/ceph/bootstrap-rgw/{cluster}.keyring'.format(
cluster=args.cluster,
)

if not distro.conn.remote_module.path_exists(path):
#远程host上不存在path的话,则将key写入远程host的path目录中
rlogger.warning('rgw keyring does not exist yet, creating one')
distro.conn.remote_module.write_keyring(path, key)
#启动ceph-radosg和ceph.target
create_rgw(distro, name, args.cluster, distro.init)
distro.conn.exit()
LOG.info(
('The Ceph Object Gateway (RGW) is now running on host %s and '
'default port %s'),
hostname,
'7480'
)
except RuntimeError as e:
LOG.error(e)
errors += 1

if errors:
raise exc.GenericError('Failed to create %d RGWs' % errors)

def create_rgw(distro, name, cluster, init):
conn = distro.conn
conn.remote_module.touch_file(os.path.join(path, 'done'))
conn.remote_module.touch_file(os.path.join(path, init))
#这里是通过romoto命令来在远程host上启动ceph-radosg和ceph.target
elif init == 'systemd':
remoto.process.run(
conn,
[
'systemctl',
'enable',
'ceph-radosgw@{name}'.format(name=name),
],
timeout=7
)
remoto.process.run(
conn,
[
'systemctl',
'start',
'ceph-radosgw@{name}'.format(name=name),
],
timeout=7
)
remoto.process.run(
conn,
[
'systemctl',
'enable',
'ceph.target',
],
timeout=7
)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: