~ntt-pf-lab/nova/lp703037

« back to all changes in this revision

Viewing changes to bin/nova-manage

  • Committer: Hisaharu Ishii
  • Date: 2011-01-21 11:04:02 UTC
  • mfrom: (572.1.25 nova)
  • Revision ID: ishii.hisaharu@lab.ntt.co.jp-20110121110402-29ict0qj0qvdl4dm
Merged with rev597

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
from nova import flags
80
80
from nova import log as logging
81
81
from nova import quota
 
82
from nova import rpc
82
83
from nova import utils
 
84
from nova.api.ec2.cloud import ec2_id_to_id
83
85
from nova.auth import manager
84
86
from nova.cloudpipe import pipelib
 
87
from nova.db import migration
85
88
 
86
89
 
87
90
logging.basicConfig()
94
97
flags.DECLARE('fixed_range_v6', 'nova.network.manager')
95
98
 
96
99
 
 
100
def param2id(object_id):
 
101
    """Helper function to convert various id types to internal id.
 
102
    args: [object_id], e.g. 'vol-0000000a' or 'volume-0000000a' or '10'
 
103
    """
 
104
    if '-' in object_id:
 
105
        return ec2_id_to_id(object_id)
 
106
    else:
 
107
        return int(object_id)
 
108
 
 
109
 
97
110
class VpnCommands(object):
98
111
    """Class for managing VPNs."""
99
112
 
519
532
        print re.sub('#012', "\n", "\n".join(lines))
520
533
 
521
534
 
 
535
class DbCommands(object):
 
536
    """Class for managing the database."""
 
537
 
 
538
    def __init__(self):
 
539
        pass
 
540
 
 
541
    def sync(self, version=None):
 
542
        """Sync the database up to the most recent version."""
 
543
        return migration.db_sync(version)
 
544
 
 
545
    def version(self):
 
546
        """Print the current database version."""
 
547
        print migration.db_version()
 
548
 
 
549
 
 
550
class VolumeCommands(object):
 
551
    """Methods for dealing with a cloud in an odd state"""
 
552
 
 
553
    def delete(self, volume_id):
 
554
        """Delete a volume, bypassing the check that it
 
555
        must be available.
 
556
        args: volume_id_id"""
 
557
        ctxt = context.get_admin_context()
 
558
        volume = db.volume_get(ctxt, param2id(volume_id))
 
559
        host = volume['host']
 
560
        if volume['status'] == 'in-use':
 
561
            print "Volume is in-use."
 
562
            print "Detach volume from instance and then try again."
 
563
            return
 
564
 
 
565
        rpc.cast(ctxt,
 
566
                 db.queue_get_for(ctxt, FLAGS.volume_topic, host),
 
567
                 {"method": "delete_volume",
 
568
                  "args": {"volume_id": volume['id']}})
 
569
 
 
570
    def reattach(self, volume_id):
 
571
        """Re-attach a volume that has previously been attached
 
572
        to an instance.  Typically called after a compute host
 
573
        has been rebooted.
 
574
        args: volume_id_id"""
 
575
        ctxt = context.get_admin_context()
 
576
        volume = db.volume_get(ctxt, param2id(volume_id))
 
577
        if not volume['instance_id']:
 
578
            print "volume is not attached to an instance"
 
579
            return
 
580
        instance = db.instance_get(ctxt, volume['instance_id'])
 
581
        host = instance['host']
 
582
        rpc.cast(ctxt,
 
583
                 db.queue_get_for(ctxt, FLAGS.compute_topic, host),
 
584
                 {"method": "attach_volume",
 
585
                  "args": {"instance_id": instance['id'],
 
586
                           "volume_id": volume['id'],
 
587
                           "mountpoint": volume['mountpoint']}})
 
588
 
 
589
 
522
590
CATEGORIES = [
523
591
    ('user', UserCommands),
524
592
    ('project', ProjectCommands),
528
596
    ('floating', FloatingIpCommands),
529
597
    ('network', NetworkCommands),
530
598
    ('service', ServiceCommands),
531
 
    ('log', LogCommands)]
 
599
    ('log', LogCommands),
 
600
    ('db', DbCommands),
 
601
    ('volume', VolumeCommands)]
532
602
 
533
603
 
534
604
def lazy_match(name, key_value_tuples):