@@ -3225,45 +3225,36 @@ def command_ceph_volume(ctx):
32253225
32263226
32273227@infer_fsid
3228- def command_unit_install (ctx ):
3229- # type: (CephadmContext) -> int
3230- if not getattr (ctx , 'fsid' , None ):
3231- raise Error ('must pass --fsid to specify cluster' )
3232- if not getattr (ctx , 'name' , None ):
3233- raise Error ('daemon name required' )
3234- ident = DaemonIdentity .from_context (ctx )
3228+ def command_unit_install (ctx : CephadmContext ) -> int :
3229+ ident = identify (ctx )
32353230 systemd_unit .update_files (ctx , ident )
32363231 call_throws (ctx , ['systemctl' , 'daemon-reload' ])
32373232 return 0
32383233
32393234
32403235@infer_fsid
3241- def command_unit (ctx ):
3242- # type: (CephadmContext) -> int
3243- if not ctx .fsid :
3244- raise Error ('must pass --fsid to specify cluster' )
3245-
3246- unit_name = lookup_unit_name_by_daemon_name (ctx , ctx .fsid , ctx .name )
3247-
3236+ def command_unit (ctx : CephadmContext ) -> int :
3237+ ident = identify (ctx )
3238+ unit_name = lookup_unit_name_by_daemon_name (
3239+ ctx , ident .fsid , ident .daemon_name
3240+ )
32483241 _ , _ , code = call (
32493242 ctx ,
32503243 ['systemctl' , ctx .command , unit_name ],
32513244 verbosity = CallVerbosity .VERBOSE ,
3252- desc = ''
3245+ desc = '' ,
32533246 )
32543247 return code
32553248
32563249##################################
32573250
32583251
32593252@infer_fsid
3260- def command_logs (ctx ):
3261- # type: (CephadmContext) -> None
3262- if not ctx .fsid :
3263- raise Error ('must pass --fsid to specify cluster' )
3264-
3265- unit_name = lookup_unit_name_by_daemon_name (ctx , ctx .fsid , ctx .name )
3266-
3253+ def command_logs (ctx : CephadmContext ) -> None :
3254+ ident = identify (ctx )
3255+ unit_name = lookup_unit_name_by_daemon_name (
3256+ ctx , ident .fsid , ident .daemon_name
3257+ )
32673258 cmd = [find_program ('journalctl' )]
32683259 cmd .extend (['-u' , unit_name ])
32693260 if ctx .command :
@@ -4496,6 +4487,20 @@ def _add_deploy_parser_args(
44964487 )
44974488
44984489
4490+ def _name_opts (parser : argparse .ArgumentParser ) -> None :
4491+ ng = parser .add_mutually_exclusive_group (required = True )
4492+ ng .add_argument (
4493+ '--name' ,
4494+ '-n' ,
4495+ help = 'daemon name (type.id)' ,
4496+ )
4497+ ng .add_argument (
4498+ '--infer-name' ,
4499+ '-i' ,
4500+ help = 'daemon name search (type[.partial_id])' ,
4501+ )
4502+
4503+
44994504def _get_parser ():
45004505 # type: () -> argparse.ArgumentParser
45014506 parser = argparse .ArgumentParser (
@@ -4764,13 +4769,7 @@ def _get_parser():
47644769 parser_enter .add_argument (
47654770 '--fsid' ,
47664771 help = 'cluster FSID' )
4767- parser_enter_ng = parser_enter .add_mutually_exclusive_group (required = True )
4768- parser_enter_ng .add_argument (
4769- '--name' , '-n' ,
4770- help = 'daemon name (type.id)' )
4771- parser_enter_ng .add_argument (
4772- '--infer-name' , '-i' ,
4773- help = 'daemon name search (type[.partial_id])' )
4772+ _name_opts (parser_enter )
47744773 parser_enter .add_argument (
47754774 'command' , nargs = argparse .REMAINDER ,
47764775 help = 'command' )
@@ -4819,32 +4818,23 @@ def _get_parser():
48194818 parser_unit .add_argument (
48204819 '--fsid' ,
48214820 help = 'cluster FSID' )
4822- parser_unit .add_argument (
4823- '--name' , '-n' ,
4824- required = True ,
4825- help = 'daemon name (type.id)' )
4821+ _name_opts (parser_unit )
48264822
48274823 parser_unit_install = subparsers .add_parser (
48284824 'unit-install' , help = "Install the daemon's systemd unit" )
48294825 parser_unit_install .set_defaults (func = command_unit_install )
48304826 parser_unit_install .add_argument (
48314827 '--fsid' ,
48324828 help = 'cluster FSID' )
4833- parser_unit_install .add_argument (
4834- '--name' , '-n' ,
4835- required = True ,
4836- help = 'daemon name (type.id)' )
4829+ _name_opts (parser_unit_install )
48374830
48384831 parser_logs = subparsers .add_parser (
48394832 'logs' , help = 'print journald logs for a daemon container' )
48404833 parser_logs .set_defaults (func = command_logs )
48414834 parser_logs .add_argument (
48424835 '--fsid' ,
48434836 help = 'cluster FSID' )
4844- parser_logs .add_argument (
4845- '--name' , '-n' ,
4846- required = True ,
4847- help = 'daemon name (type.id)' )
4837+ _name_opts (parser_logs )
48484838 parser_logs .add_argument (
48494839 'command' , nargs = '*' ,
48504840 help = 'additional journalctl args' )
0 commit comments