Skip to content

Commit

Permalink
Merge pull request ceph#56458 from adk3798/rgw-bootstrap-hostnames
Browse files Browse the repository at this point in the history
mgr/cephadm: update rgw zonegroup w/ zonegroup_hostnames from rgw spec

Reviewed-by: Ali Maredia <[email protected]>
  • Loading branch information
adk3798 authored Mar 26, 2024
2 parents 17a4fdb + 3ba8724 commit ae6d67e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/pybind/mgr/cephadm/services/cephadmservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,17 @@ def config(self, spec: RGWSpec) -> None: # type: ignore
'val': cert_data,
})

if spec.zonegroup_hostnames:
zg_update_cmd = {
'prefix': 'rgw zonegroup modify',
'realm_name': spec.rgw_realm,
'zonegroup_name': spec.rgw_zonegroup,
'zone_name': spec.rgw_zone,
'hostnames': spec.zonegroup_hostnames,
}
logger.debug(f'rgw cmd: {zg_update_cmd}')
ret, out, err = self.mgr.check_mon_command(zg_update_cmd)

# TODO: fail, if we don't have a spec
logger.info('Saving service %s spec with placement %s' % (
spec.service_name(), spec.placement.pretty_str()))
Expand Down
18 changes: 15 additions & 3 deletions src/pybind/mgr/rgw/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from typing_extensions import Protocol

class MgrModuleProtocol(Protocol):
def tool_exec(self, args: List[str]) -> Tuple[int, str, str]:
def tool_exec(self, args: List[str], timeout: int = 10, stdin: Optional[bytes] = None) -> Tuple[int, str, str]:
...

def apply_rgw(self, spec: RGWSpec) -> OrchResult[str]:
Expand Down Expand Up @@ -66,9 +66,9 @@ class RGWAMOrchMgr(RGWAMEnvMgr):
def __init__(self, mgr: MgrModuleProtocol):
self.mgr = mgr

def tool_exec(self, prog: str, args: List[str]) -> Tuple[List[str], int, str, str]:
def tool_exec(self, prog: str, args: List[str], stdin: Optional[bytes] = None) -> Tuple[List[str], int, str, str]:
cmd = [prog] + args
rc, stdout, stderr = self.mgr.tool_exec(args=cmd)
rc, stdout, stderr = self.mgr.tool_exec(args=cmd, stdin=stdin)
return cmd, rc, stdout, stderr

def apply_rgw(self, spec: RGWSpec) -> None:
Expand Down Expand Up @@ -286,6 +286,18 @@ def update_zone_info(self, realm_name: str, zonegroup_name: str, zone_name: str,
self.log.error('cmd run exception: (%d) %s' % (e.retcode, e.message))
return HandleCommandResult(retval=e.retcode, stdout=e.stdout, stderr=e.stderr)

@CLICommand('rgw zonegroup modify', perm='rw')
def update_zonegroup_info(self, realm_name: str, zonegroup_name: str, zone_name: str, hostnames: List[str]) -> HandleCommandResult:
try:
retval, out, err = RGWAM(self.env).zonegroup_modify(realm_name,
zonegroup_name,
zone_name,
hostnames)
return HandleCommandResult(retval, 'Zonegroup updated successfully', '')
except RGWAMException as e:
self.log.error('cmd run exception: (%d) %s' % (e.retcode, e.message))
return HandleCommandResult(retval=e.retcode, stdout=e.stdout, stderr=e.stderr)

@CLICommand('rgw zone create', perm='rw')
@check_orchestrator
def _cmd_rgw_zone_create(self,
Expand Down
4 changes: 3 additions & 1 deletion src/python-common/ceph/deployment/service_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,10 +1217,11 @@ def __init__(self,
rgw_realm_token: Optional[str] = None,
update_endpoints: Optional[bool] = False,
zone_endpoints: Optional[str] = None, # comma separated endpoints list
zonegroup_hostnames: Optional[str] = None,
rgw_user_counters_cache: Optional[bool] = False,
rgw_user_counters_cache_size: Optional[int] = None,
rgw_bucket_counters_cache: Optional[bool] = False,
rgw_bucket_counters_cache_size: Optional[int] = None
rgw_bucket_counters_cache_size: Optional[int] = None,
):
assert service_type == 'rgw', service_type

Expand Down Expand Up @@ -1260,6 +1261,7 @@ def __init__(self,
self.rgw_realm_token = rgw_realm_token
self.update_endpoints = update_endpoints
self.zone_endpoints = zone_endpoints
self.zonegroup_hostnames = zonegroup_hostnames

#: To track op metrics by user config value rgw_user_counters_cache must be set to true
self.rgw_user_counters_cache = rgw_user_counters_cache
Expand Down
52 changes: 47 additions & 5 deletions src/python-common/ceph/rgw/rgwam_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ def __init__(self, prog, zone_env: ZoneEnv):
opt_arg(self.cmd_suffix, '--rgw-zone', zone_env.zone.name)
opt_arg(self.cmd_suffix, '--zone-id', zone_env.zone.id)

def run(self, cmd):
def run(self, cmd, stdin=None):
args = cmd + self.cmd_suffix
cmd, returncode, stdout, stderr = self.mgr.tool_exec(self.prog, args)
cmd, returncode, stdout, stderr = self.mgr.tool_exec(self.prog, args, stdin)

log.debug('cmd=%s' % str(cmd))
log.debug(f'stdin={stdin}')
log.debug('stdout=%s' % stdout)

if returncode != 0:
Expand All @@ -174,8 +175,8 @@ class RGWAdminJSONCmd(RGWAdminCmd):
def __init__(self, zone_env: ZoneEnv):
super().__init__(zone_env)

def run(self, cmd):
stdout, _ = RGWAdminCmd.run(self, cmd)
def run(self, cmd, stdin=None):
stdout, _ = RGWAdminCmd.run(self, cmd, stdin)

return json.loads(stdout)

Expand Down Expand Up @@ -237,9 +238,13 @@ def list(self):
def get(self, zonegroup: EntityKey = None):
ze = ZoneEnv(self.env)
params = ['zonegroup', 'get']
opt_arg(params, '--rgw-zonegroup', zonegroup)
return RGWAdminJSONCmd(ze).run(params)

def set(self, zonegroup: EntityKey, zg_json: str):
ze = ZoneEnv(self.env)
params = ['zonegroup', 'set']
return RGWAdminJSONCmd(ze).run(params, stdin=zg_json.encode('utf-8'))

def create(self, realm: EntityKey, zg: EntityKey = None, endpoints=None, is_master=True):
ze = ZoneEnv(self.env, realm=realm).init_zg(zg, gen=True)

Expand Down Expand Up @@ -724,6 +729,43 @@ def zone_modify(self, realm_name, zonegroup_name, zone_name, endpoints, realm_to

return (0, success_message, '')

def zonegroup_modify(self, realm_name, zonegroup_name, zone_name, hostnames):
if realm_name is None:
raise RGWAMException('Realm name is a mandatory parameter')
if zone_name is None:
raise RGWAMException('Zone name is a mandatory parameter')
if zonegroup_name is None:
raise RGWAMException('Zonegroup name is a mandatory parameter')

realm = EntityName(realm_name)
zone = EntityName(zone_name)
period_info = self.period_op().get(realm)
period = RGWPeriod(period_info)
logging.info('Period: ' + period.id)
zonegroup = period.find_zonegroup_by_name(zonegroup_name)
if not zonegroup:
raise RGWAMException(f'zonegroup {zonegroup_name} not found')
zg = EntityName(zonegroup.name)
zg_json = self.zonegroup_op().get(zg)

if hostnames:
zg_json['hostnames'] = hostnames

try:
self.zonegroup_op().set(zg, json.dumps(zg_json))
except RGWAMException as e:
raise RGWAMException('failed to set zonegroup', e)

try:
period_info = self.period_op().update(realm, zg, zone, True)
except RGWAMException as e:
raise RGWAMException('failed to update period', e)

period = RGWPeriod(period_info)
logging.debug(period.to_json())

return (0, f'Modified zonegroup {zonegroup_name} of realm {realm_name}', '')

def get_realms_info(self):
realms_info = []
for realm_name in self.realm_op().list():
Expand Down

0 comments on commit ae6d67e

Please sign in to comment.