Revision d1ceb341

b/snf-tools/snf-admin
183 183
        username = username.decode('utf8')
184 184
        realname = self.realname or username
185 185
        type = self.type or 'USER'
186
        if type not in [x[0] for x in models.SynnefoUser.ACCOUNT_TYPE]:
187
            print 'Invalid type'
186
        types = [x[0] for x in models.SynnefoUser.ACCOUNT_TYPE]
187
        if type not in types:
188
            valid = ', '.join(types)
189
            print 'Invalid type. Must be one of:', valid
188 190
            return
189 191
        
190 192
        user = users._register_user(realname, username, email, type)
......
252 254
    description = 'modify a user'
253 255
    
254 256
    def add_options(self, parser):
257
        types = ', '.join(x[0] for x in models.SynnefoUser.ACCOUNT_TYPE)
258
        
255 259
        parser.add_option('--credit', dest='credit', metavar='VALUE',
256 260
                            help='set user credits')
257 261
        parser.add_option('--invitations', dest='invitations',
......
259 263
        parser.add_option('--realname', dest='realname', metavar='NAME',
260 264
                            help='set real name of user')
261 265
        parser.add_option('--type', dest='type', metavar='TYPE',
262
                            help='set user type')
266
                            help='set user type (%s)' % types)
263 267
        parser.add_option('--uniq', dest='uniq', metavar='ID',
264 268
                            help='set external unique ID')
265 269
        parser.add_option('--username', dest='username', metavar='NAME',
......
277 281
        if self.type:
278 282
            allowed = [x[0] for x in models.SynnefoUser.ACCOUNT_TYPE]
279 283
            if self.type not in allowed:
280
                print 'Invalid type'
284
                valid = ', '.join(allowed)
285
                print 'Invalid type. Must be one of:', valid
281 286
                return
282 287
            user.type = self.type
283 288
        if self.uniq:
......
312 317
class RegisterImage(Command):
313 318
    group = 'image'
314 319
    name = 'register'
315
    syntax = '<name> <backend id>'
320
    syntax = '<name> <backend id> <format>'
316 321
    description = 'register an image'
317 322
    
318 323
    def add_options(self, parser):
......
321 326
        parser.add_option('-u', dest='uid', metavar='UID',
322 327
                            help='assign image to user with id UID')
323 328
    
324
    def main(self, name, backend_id):
329
    def main(self, name, backend_id, format):
330
        formats = [x[0] for x in models.Image.FORMATS]
331
        if format not in formats:
332
            valid = ', '.join(formats)
333
            print 'Invalid format. Must be one of:', valid
334
            return
335
        
325 336
        user = None
326 337
        if self.uid:
327 338
            user = get_user(self.uid)
......
334 345
            state='ACTIVE',
335 346
            owner=user,
336 347
            backend_id=backend_id,
348
            format=format,
337 349
            public=self.public)
338 350
        
339 351
        print_item(image)
......
346 358
    description = 'modify an image'
347 359
    
348 360
    def add_options(self, parser):
361
        states = ', '.join(x[0] for x in models.Image.IMAGE_STATES)
362
        formats = ', '.join(x[0] for x in models.Image.FORMATS)
363

  
349 364
        parser.add_option('-b', dest='backend_id', metavar='BACKEND_ID',
350 365
                            help='set image backend id')
351 366
        parser.add_option('-f', dest='format', metavar='FORMAT',
352
                            help='set image format')
367
                            help='set image format (%s)' % formats)
353 368
        parser.add_option('-n', dest='name', metavar='NAME',
354 369
                            help='set image name')
355 370
        parser.add_option('--public', action='store_true', dest='public',
356 371
                            default=False, help='make image public')
357 372
        parser.add_option('--nopublic', action='store_true', dest='private',
358 373
                            default=False, help='make image private')
359
        parser.add_option('-s', dest='state', metavar='STATE',
360
                            default=False, help='set image state')
374
        parser.add_option('-s', dest='state', metavar='STATE', default=False,
375
                            help='set image state (%s)' % states)
361 376
        parser.add_option('-u', dest='uid', metavar='UID',
362 377
                            help='assign image to user with id UID')
363 378
    
......
373 388
        if self.format:
374 389
            allowed = [x[0] for x in models.Image.FORMATS]
375 390
            if self.format not in allowed:
376
                print 'Invalid format'
391
                valid = ', '.join(allowed)
392
                print 'Invalid format. Must be one of:', valid
377 393
                return
378 394
            image.format = self.format
379 395
        if self.name:
......
385 401
        if self.state:
386 402
            allowed = [x[0] for x in models.Image.IMAGE_STATES]
387 403
            if self.state not in allowed:
388
                print 'Invalid state'
404
                valid = ', '.join(allowed)
405
                print 'Invalid state. Must be one of:', valid
389 406
                return
390 407
            image.state = self.state
391 408
        if self.uid:

Also available in: Unified diff