def __init__(self, mgr):
self.mgr = mgr
+ def tool_exec(self, prog, args):
+ cmd = [ prog ] + args
+ rc, stdout, stderr = self.mgr.tool_exec(args = cmd)
+ return cmd, rc, stdout, stderr
+
def apply_rgw(self, svc_id, realm_name, zone_name, port = None):
spec = RGWSpec(service_id = svc_id,
rgw_realm = realm_name,
with self.lock:
self.inited = True
- self.env = EnvArgs(RGWAMOrchMgr(self),
- str(self.get_ceph_conf_path()),
- f'mgr.{self.get_mgr_id()}',
- str(self.get_ceph_option('keyring')))
+ self.env = EnvArgs(RGWAMOrchMgr(self))
# set up some members to enable the serve() method and shutdown()
self.run = True
@CLICommand('rgw admin', perm='rw')
def _cmd_rgw_admin(self, params: Sequence[str]):
"""rgw admin"""
- run_cmd = [ './bin/radosgw-admin',
- '-c', str(self.get_ceph_conf_path()),
- '-k', str(self.get_ceph_option('keyring')),
- '-n', f'mgr.{self.get_mgr_id()}' ] + (params or [])
-
- result = subprocess.run(run_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ cmd, returncode, out, err = self.env.mgr.tool_exec('radosgw-admin', params or [])
- # TODO Extend export creation for rgw.
- out = result.stdout.decode('utf-8')
- err = result.stderr.decode('utf-8')
- self.log.error('retcode=%d' % result.returncode)
+ self.log.error('retcode=%d' % returncode)
self.log.error('out=%s' % out)
self.log.error('err=%s' % err)
- return HandleCommandResult(retval=result.returncode, stdout=out, stderr=err)
+ return HandleCommandResult(retval=returncode, stdout=out, stderr=err)
@CLICommand('rgw realm bootstrap', perm='rw')
def _cmd_rgw_realm_bootstrap(self,
class EnvArgs:
- def __init__(self, mgr, ceph_conf, ceph_name, ceph_keyring):
+ def __init__(self, mgr):
self.mgr = mgr
- self.ceph_conf = ceph_conf
- self.ceph_name = ceph_name
- self.ceph_keyring = ceph_keyring
class EntityKey:
def __init__(self, name = None, id = None):
class RGWCmdBase:
def __init__(self, prog, zone_env : ZoneEnv):
- env = zone_env.env
- self.cmd_prefix = [ prog ]
+ self.env = zone_env.env
+ self.mgr = self.env.mgr
+ self.prog = prog
self.cmd_suffix = [ ]
- opt_arg(self.cmd_prefix, '-c', env.ceph_conf )
- opt_arg(self.cmd_prefix, '-n', env.ceph_name )
- opt_arg(self.cmd_prefix, '-k', env.ceph_keyring )
if zone_env.realm:
opt_arg(self.cmd_suffix, '--rgw-realm', zone_env.realm.name )
opt_arg(self.cmd_suffix, '--realm-id', zone_env.realm.id )
opt_arg(self.cmd_suffix, '--zone-id', zone_env.zone.id )
def run(self, cmd):
- run_cmd = self.cmd_prefix + cmd + self.cmd_suffix
- result = subprocess.run(run_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-
- stdout = result.stdout.decode('utf-8')
- stderr = result.stderr.decode('utf-8')
+ args = cmd + self.cmd_suffix
+ cmd, returncode, stdout, stderr = self.mgr.tool_exec(self.prog, args)
log.debug('cmd=%s' % str(cmd))
-
log.debug('stdout=%s' % stdout)
- if result.returncode != 0:
- cmd_str = ' '.join(run_cmd)
- log.error('ERROR: command exited with error status (%d): %s\nstdout=%s\nstderr=%s' % (result.returncode, cmd_str, stdout, stderr))
- raise RGWAMCmdRunException(cmd_str, -result.returncode, stdout, stderr)
+ if returncode != 0:
+ cmd_str = ' '.join(cmd)
+ log.error('ERROR: command exited with error status (%d): %s\nstdout=%s\nstderr=%s' % (returncode, cmd_str, stdout, stderr))
+ raise RGWAMCmdRunException(cmd_str, -returncode, stdout, stderr)
return (stdout, stderr)
self.stderr = stderr
class RGWAMEnvMgr:
+ @abstractmethod
+ def tool_exec(self, prog, args):
+ pass
+
@abstractmethod
def apply_rgw(self, svc_id, realm_name, zone_name, port = None):
pass
from ceph.rgw.types import RGWAMEnvMgr, RGWAMException
class RGWAMCLIMgr(RGWAMEnvMgr):
- def __init__(self):
- pass
+ def __init__(self, common_args):
+ args = []
+
+ if common_args.conf_path:
+ args += [ '-c', common_args.conf_path ]
+
+ if common_args.ceph_name:
+ args += [ '-n', common_args.ceph_name ]
+
+ if common_args.ceph_keyring:
+ args += [ '-k', common_args.ceph_keyring ]
+
+ self.args_prefix = args
+
+ def tool_exec(self, prog, args):
+ run_cmd = [ prog ] + self.args_prefix + args
+
+ result = subprocess.run(run_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ stdout = result.stdout.decode('utf-8')
+ stderr = result.stderr.decode('utf-8')
+
+ return run_cmd, result.returncode, stdout, stderr
def apply_rgw(self, svc_id, realm_name, zone_name, port = None):
return None
(cmd, common_args, args)= TopLevelCommand()._parse()
- env = EnvArgs(RGWAMCLIMgr(),
- common_args.conf_path,
- common_args.ceph_name,
- common_args.ceph_keyring)
+ env = EnvArgs(RGWAMCLIMgr(common_args))
try:
retval, out, err = cmd(env, args)