@@ -15,6 +15,8 @@ def clicked(self, required=False):
1515# we'll use tests of the -h option in the .travis.yml to ensure that the
1616# .clicked methods work
1717
18+ HELP_MULTIPLE = "; may be used more than once"
19+
1820class Option (AbstractParameter ):
1921 def clicked (self , required = False ): # no-cov
2022 return click .option (* self .args , ** self .kwargs , required = required )
@@ -56,12 +58,23 @@ def get(self, name):
5658
5759
5860class OPSStorageLoadNames (AbstractLoader ):
61+ """Simple loader that expects its input to be a name or index.
62+ """
5963 def __init__ (self , param , store ):
6064 super (OPSStorageLoadNames , self ).__init__ (param )
6165 self .store = store
6266
6367 def get (self , storage , names ):
64- return [getattr (storage , self .store )[name ] for name in names ]
68+ int_corrected = []
69+ for name in names :
70+ try :
71+ name = int (name )
72+ except ValueError :
73+ pass
74+ int_corrected .append (name )
75+
76+ return [getattr (storage , self .store )[name ]
77+ for name in int_corrected ]
6578
6679
6780class OPSStorageLoadSingle (AbstractLoader ):
@@ -181,16 +194,47 @@ def init_snap_fallback(parameter, storage, name):
181194
182195CVS = OPSStorageLoadNames (
183196 param = Option ('--cv' , type = str , multiple = True ,
184- help = 'name of CV; may select more than once' ),
197+ help = 'name of CV' + HELP_MULTIPLE ),
185198 store = 'cvs'
186199)
187200
201+ MULTI_VOLUME = OPSStorageLoadNames (
202+ param = Option ('--volume' , type = str , multiple = True ,
203+ help = 'name or index of volume' + HELP_MULTIPLE ),
204+ store = 'volumes'
205+ ) #TODO:unit tests
206+
207+ MULTI_ENGINE = OPSStorageLoadNames (
208+ param = Option ('--engine' , type = str , multiple = True ,
209+ help = 'name or index of engine' + HELP_MULTIPLE ),
210+ store = 'engines'
211+ )
212+
213+
188214STATES = OPSStorageLoadNames (
189- param = Option ('-s' , '--state' , multiple = True ,
190- help = 'name of state; may select more than once' ),
215+ param = Option ('-s' , '--state' , type = str , multiple = True ,
216+ help = 'name of state' + HELP_MULTIPLE ),
191217 store = 'volumes'
192218)
193219
220+ MULTI_TAG = OPSStorageLoadNames (
221+ param = Option ('--tag' , type = str , multiple = True ,
222+ help = 'tag for object' + HELP_MULTIPLE ),
223+ store = 'tags'
224+ ) # TODO: unit testsA
225+
226+ MULTI_NETWORK = OPSStorageLoadNames (
227+ param = Option ('--network' , type = str , multiple = True ,
228+ help = 'name or index of network' + HELP_MULTIPLE ),
229+ store = 'networks'
230+ ) # TODO: unit tests
231+
232+ MULTI_SCHEME = OPSStorageLoadNames (
233+ param = Option ('--scheme' , type = str , multiple = True ,
234+ help = 'name or index of move scheme' + HELP_MULTIPLE ),
235+ store = 'schemes'
236+ ) # TODO: unit tests
237+
194238INPUT_FILE = StorageLoader (
195239 param = Argument ('input_file' ,
196240 type = click .Path (exists = True , readable = True )),
0 commit comments