~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to bin/cinder-manage

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        Falls back to Python shell if unavailable"""
128
128
        self.run('python')
129
129
 
130
 
    @args('--shell', dest="shell", metavar='<bpython|ipython|python >',
131
 
            help='Python shell')
 
130
    @args('--shell', dest="shell",
 
131
          metavar='<bpython|ipython|python >',
 
132
          help='Python shell')
132
133
    def run(self, shell=None):
133
134
        """Runs a Python interactive interpreter."""
134
135
        if not shell:
180
181
 
181
182
 
182
183
class HostCommands(object):
183
 
    """List hosts"""
 
184
    """List hosts."""
184
185
 
185
186
    def list(self, zone=None):
186
187
        """Show a list of all physical hosts. Filter by zone.
206
207
    def __init__(self):
207
208
        pass
208
209
 
209
 
    @args('--version', dest='version', metavar='<version>',
210
 
            help='Database version')
 
210
    @args('--version', dest='version',
 
211
          metavar='<version>',
 
212
          help='Database version')
211
213
    def sync(self, version=None):
212
214
        """Sync the database up to the most recent version."""
213
215
        return migration.db_sync(version)
224
226
        pass
225
227
 
226
228
    def list(self):
227
 
        print _("%(version)s (%(vcs)s)") % \
228
 
                {'version': version.version_string(),
229
 
                 'vcs': version.version_string_with_vcs()}
 
229
        print(
 
230
            _("%(version)s (%(vcs)s)") %
 
231
            {'version': version.version_string(),
 
232
             'vcs': version.version_string_with_vcs()})
230
233
 
231
234
    def __call__(self):
232
235
        self.list()
313
316
            columns = table.columns.keys()
314
317
            for row in src.query(table).all():
315
318
                data = dict([(str(column), getattr(row, column))
316
 
                    for column in columns])
 
319
                             for column in columns])
317
320
                dest.add(new_row(**data))
318
321
            dest.commit()
319
322
 
325
328
            for row in src.query(table).all():
326
329
                if row.resource == 'gigabytes' or row.resource == 'volumes':
327
330
                    data = dict([(str(column), getattr(row, column))
328
 
                        for column in columns])
 
331
                                 for column in columns])
329
332
                    dest.add(new_row(**data))
330
333
                dest.commit()
331
334
 
352
355
        dest_db = '%s/cinder' % dest_db
353
356
        self._import_db(src_db, dest_db, backup_db)
354
357
 
355
 
    @args('--src', dest='src_tgts', metavar='<src tgts>',
356
 
        help='[login@src_host:]/opt/stack/nova/volumes/')
357
 
    @args('--dest', dest='dest_tgts', metavar='<dest tgts>',
358
 
        help='[login@src_host:/opt/stack/cinder/volumes/]')
 
358
    @args('--src',
 
359
          dest='src_tgts',
 
360
          metavar='<src tgts>',
 
361
          help='[login@src_host:]/opt/stack/nova/volumes/')
 
362
    @args('--dest',
 
363
          dest='dest_tgts',
 
364
          metavar='<dest tgts>',
 
365
          help='[login@src_host:/opt/stack/cinder/volumes/]')
359
366
    def copy_ptgt_files(self, src_tgts, dest_tgts=None):
360
367
        """Copy persistent scsi tgt files from nova to cinder.
361
368
 
380
387
 
381
388
 
382
389
class VolumeCommands(object):
383
 
    """Methods for dealing with a cloud in an odd state"""
 
390
    """Methods for dealing with a cloud in an odd state."""
384
391
 
385
 
    @args('--volume', dest='volume_id', metavar='<volume id>',
386
 
            help='Volume ID')
 
392
    @args('--volume',
 
393
          dest='volume_id',
 
394
          metavar='<volume id>',
 
395
          help='Volume ID')
387
396
    def delete(self, volume_id):
388
397
        """Delete a volume, bypassing the check that it
389
398
        must be available."""
407
416
                 {"method": "delete_volume",
408
417
                  "args": {"volume_id": volume['id']}})
409
418
 
410
 
    @args('--volume', dest='volume_id', metavar='<volume id>',
411
 
            help='Volume ID')
 
419
    @args('--volume',
 
420
          dest='volume_id',
 
421
          metavar='<volume id>',
 
422
          help='Volume ID')
412
423
    def reattach(self, volume_id):
413
424
        """Re-attach a volume that has previously been attached
414
425
        to an instance.  Typically called after a compute host
429
440
 
430
441
 
431
442
class StorageManagerCommands(object):
432
 
    """Class for mangaging Storage Backends and Flavors"""
 
443
    """Class for mangaging Storage Backends and Flavors."""
433
444
 
434
445
    def flavor_list(self, flavor=None):
435
446
        ctxt = context.get_admin_context()
449
460
 
450
461
        for flav in flavors:
451
462
            print "%-18s\t%-20s\t%s" % (
452
 
                    flav['id'],
453
 
                    flav['label'],
454
 
                    flav['description'])
 
463
                flav['id'],
 
464
                flav['label'],
 
465
                flav['description'])
455
466
 
456
467
    def flavor_create(self, label, desc):
457
468
        # TODO(renukaapte) flavor name must be unique
487
498
            sys.exit(2)
488
499
 
489
500
        print "%-5s\t%-10s\t%-40s\t%-10s\t%s" % (_('id'),
490
 
                                                      _('Flavor id'),
491
 
                                                      _('SR UUID'),
492
 
                                                      _('SR Type'),
493
 
                                                      _('Config Parameters'),)
 
501
                                                 _('Flavor id'),
 
502
                                                 _('SR UUID'),
 
503
                                                 _('SR Type'),
 
504
                                                 _('Config Parameters'),)
494
505
 
495
506
        for b in backends:
496
507
            print "%-5s\t%-10s\t%-40s\t%-10s\t%s" % (b['id'],
516
527
            print "error: %s" % ex
517
528
            sys.exit(2)
518
529
 
519
 
        config_params = " ".join(['%s=%s' %
520
 
                               (key, params[key]) for key in params])
 
530
        config_params = " ".join(
 
531
            ['%s=%s' % (key, params[key]) for key in params])
521
532
 
522
533
        if 'sr_uuid' in params:
523
534
            sr_uuid = params['sr_uuid']
532
543
                c = raw_input('Proceed? (y/n) ')
533
544
                if c == 'y' or c == 'Y':
534
545
                    try:
535
 
                        db.sm_backend_conf_update(ctxt, backend['id'],
536
 
                                        dict(created=False,
537
 
                                             flavor_id=flavors['id'],
538
 
                                             sr_type=sr_type,
539
 
                                             config_params=config_params))
 
546
                        db.sm_backend_conf_update(
 
547
                            ctxt, backend['id'],
 
548
                            dict(created=False,
 
549
                                 flavor_id=flavors['id'],
 
550
                                 sr_type=sr_type,
 
551
                                 config_params=config_params))
540
552
                    except exception.DBError, e:
541
553
                        _db_error(e)
542
554
                return
578
590
 
579
591
 
580
592
class GetLogCommands(object):
581
 
    """Get logging information"""
 
593
    """Get logging information."""
582
594
 
583
595
    def errors(self):
584
 
        """Get all of the errors from the log files"""
 
596
        """Get all of the errors from the log files."""
585
597
        error_found = 0
586
598
        if FLAGS.logdir:
587
599
            logs = [x for x in os.listdir(FLAGS.logdir) if x.endswith('.log')]
601
613
            print "No errors in logfiles!"
602
614
 
603
615
    def syslog(self, num_entries=10):
604
 
        """Get <num_entries> of the cinder syslog events"""
 
616
        """Get <num_entries> of the cinder syslog events."""
605
617
        entries = int(num_entries)
606
618
        count = 0
607
619
        log_file = ''
692
704
    script_name = argv.pop(0)
693
705
    if len(argv) < 1:
694
706
        print _("\nOpenStack Cinder version: %(version)s (%(vcs)s)\n") % \
695
 
                {'version': version.version_string(),
696
 
                 'vcs': version.version_string_with_vcs()}
 
707
            {'version': version.version_string(),
 
708
             'vcs': version.version_string_with_vcs()}
697
709
        print script_name + " category action [<args>]"
698
710
        print _("Available categories:")
699
711
        for k, _v in CATEGORIES: