@@ -108,6 +108,63 @@ def global_args(parser: Parser) -> None:
108
108
choices = ("auto" , "required" , "true" , "false" ),
109
109
help = ("Perform schema based validation of configuration." ),
110
110
)
111
+ parser .add_argument (
112
+ "--ceph-id" ,
113
+ type = _ceph_id ,
114
+ help = (
115
+ "Specify a user/client ID to ceph libraries"
116
+ "(can also be set in the environment by SAMBACC_CEPH_ID."
117
+ " Ignored if Ceph RADOS libraries are not present or unused."
118
+ " Pass `?` for more details)."
119
+ ),
120
+ )
121
+
122
+
123
+ def _ceph_id (
124
+ value : typing .Union [str , dict [str , typing .Any ]]
125
+ ) -> dict [str , typing .Any ]:
126
+ if not isinstance (value , str ):
127
+ return value
128
+ if value == "?" :
129
+ # A hack to avoid putting tons of ceph specific info in the normal
130
+ # help output. There's probably a better way to do this but it
131
+ # gets the job done for now.
132
+ raise argparse .ArgumentTypeError (
133
+ "requested help:"
134
+ " Specify names in the form"
135
+ " --ceph-id=[key=value][,key=value][,...]."
136
+ ' Valid keys include "name" to set the exact name and "rados_id"'
137
+ ' to specify a name that lacks the "client." prefix (that will'
138
+ "automatically get added)."
139
+ " Alternatively, specify just the name to allow the system to"
140
+ " guess if the name is prefixed already or not."
141
+ )
142
+ result : dict [str , typing .Any ] = {}
143
+ # complex mode
144
+ if "=" in value :
145
+ for part in value .split ("," ):
146
+ if "=" not in part :
147
+ raise argparse .ArgumentTypeError (
148
+ f"unexpected value for ceph-id: { value !r} "
149
+ )
150
+ key , val = part .split ("=" , 1 )
151
+ if key == "name" :
152
+ result ["client_name" ] = val
153
+ result ["full_name" ] = True
154
+ elif key == "rados_id" :
155
+ result ["client_name" ] = val
156
+ result ["full_name" ] = False
157
+ else :
158
+ b = f"unexpected key { key !r} in value for ceph-id: { value !r} "
159
+ raise argparse .ArgumentTypeError (b )
160
+ else :
161
+ # this shorthand is meant mainly for lazy humans (me) when running test
162
+ # images manually. The key-value form above is meant for automation.
163
+ result ["client_name" ] = value
164
+ # assume that if the name starts with client. it's the full name and
165
+ # avoid having the ceph library double up an create client.client.x.
166
+ result ["full_name" ] = value .startswith ("client." )
167
+ return result
111
168
112
169
113
170
def from_env (
@@ -173,6 +230,7 @@ def env_to_cli(cli: typing.Any) -> None:
173
230
from_env (cli , "password" , "INSECURE_JOIN_PASSWORD" )
174
231
from_env (cli , "samba_debug_level" , "SAMBA_DEBUG_LEVEL" )
175
232
from_env (cli , "validate_config" , "SAMBACC_VALIDATE_CONFIG" )
233
+ from_env (cli , "ceph_id" , "SAMBACC_CEPH_ID" , convert_value = _ceph_id )
176
234
177
235
178
236
class CommandContext :
@@ -227,7 +285,11 @@ def pre_action(cli: typing.Any) -> None:
227
285
228
286
# should there be an option to force {en,dis}able openers?
229
287
# Right now we just always try to enable rados when possible.
230
- rados_opener .enable_rados_url_opener (url_opener .URLOpener )
288
+ rados_opener .enable_rados_url_opener (
289
+ url_opener .URLOpener ,
290
+ client_name = cli .ceph_id .get ("client_name" , "" ),
291
+ full_name = cli .ceph_id .get ("full_name" , False ),
292
+ )
231
293
232
294
233
295
def enable_logging (cli : typing .Any ) -> None :
0 commit comments