@@ -173,6 +173,68 @@ def take_action(self, parsed_args):
173173 )
174174
175175
176+ class SetMetadefProperty (command .Command ):
177+ _description = _ ("Update metadef namespace property" )
178+
179+ def get_parser (self , prog_name ):
180+ parser = super ().get_parser (prog_name )
181+ parser .add_argument (
182+ "--name" ,
183+ help = _ ("Internal name of the property" ),
184+ )
185+ parser .add_argument (
186+ "--title" ,
187+ help = _ ("Property name displayed to the user" ),
188+ )
189+ parser .add_argument (
190+ "--type" ,
191+ help = _ ("Property type" ),
192+ )
193+ parser .add_argument (
194+ "--schema" ,
195+ help = _ ("Valid JSON schema of the property" ),
196+ )
197+ parser .add_argument (
198+ "namespace_name" ,
199+ help = _ ("Namespace of the namespace to which the property belongs" ),
200+ )
201+ parser .add_argument (
202+ "property_name" ,
203+ help = _ ("Property to update" ),
204+ )
205+ return parser
206+
207+ def take_action (self , parsed_args ):
208+ image_client = self .app .client_manager .image
209+
210+ # We need to pass the values for *all* attributes as kwargs to
211+ # update_metadef_property(), otherwise the attributes that are not
212+ # listed will be reset.
213+ data = image_client .get_metadef_property (
214+ parsed_args .property_name , parsed_args .namespace_name
215+ )
216+ kwargs = _format_property (data )
217+ for key in ['name' , 'title' , 'type' ]:
218+ argument = getattr (parsed_args , key , None )
219+ if argument is not None :
220+ kwargs [key ] = argument
221+
222+ if parsed_args .schema :
223+ try :
224+ kwargs .update (json .loads (parsed_args .schema ))
225+ except json .JSONDecodeError as e :
226+ raise exceptions .CommandError (
227+ _ ("Failed to load JSON schema: %(e)s" )
228+ % {
229+ 'e' : e ,
230+ }
231+ )
232+
233+ image_client .update_metadef_property (
234+ parsed_args .property_name , parsed_args .namespace_name , ** kwargs
235+ )
236+
237+
176238class ShowMetadefProperty (command .ShowOne ):
177239 _description = _ ("Describe a specific property from a namespace" )
178240
0 commit comments