From f4af28760a6a6401b84107eb73d7746dd312d1a0 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Mon, 17 Sep 2012 21:05:49 -0600 Subject: [PATCH] Fix volume id conversion in nova-manage volume The nova-manage volume commands weren't updated when the switch from int volume-id's to uuid's was made. This updates the param2id method to call the appropriate conversion, and doesn't attempt to cast the value to an int. There is an additional issue with the nova-manage commands with the introduction of Cinder. The calls in nova-manage are direct to the nova database which when using Cinder is not valid. Add an error message when trying to use delete or re-attach commands as they don't work. This change deprecates the nova-manage delete function as it's now implemented as an admin extension (nova commit id: If795599d and cinder commit id: I29f4b892). The reattach command is only valid for nova-volumes, a similar extension will need to be added to cover cinder at which time the nova-manage volume reattach can be deprecated as well. Partial fix for bug #1051603 Change-Id: I666d4e627dee4a2025f7135560ee36c40f4bf17a --- bin/nova-manage | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 790e1c0b6..56855fad4 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -91,7 +91,6 @@ from nova import quota from nova.scheduler import rpcapi as scheduler_rpcapi from nova import utils from nova import version -from nova.volume import volume_types FLAGS = flags.FLAGS flags.DECLARE('flat_network_bridge', 'nova.network.manager') @@ -115,13 +114,13 @@ def args(*args, **kwargs): def param2id(object_id): - """Helper function to convert various id types to internal id. + """Helper function to convert various volume id types to internal id. args: [object_id], e.g. 'vol-0000000a' or 'volume-0000000a' or '10' """ if '-' in object_id: - return ec2utils.ec2_id_to_id(object_id) + return ec2utils.ec2_vol_id_to_uuid(object_id) else: - return int(object_id) + return object_id class VpnCommands(object): @@ -782,8 +781,17 @@ class VolumeCommands(object): @args('--volume', dest='volume_id', metavar='', help='Volume ID') def delete(self, volume_id): - """Delete a volume, bypassing the check that it + """WARNING: This method is deprecated and will be removed. + Delete a volume, bypassing the check that it must be available.""" + + print(_("\"nova-manage volume delete\" is deprecated; use" + " the os-reset_status os-admin-actions extension instead.")) + if 'cinder' in FLAGS.volume_api_class: + print(_("\"nova-manage volume delete\" only valid " + "when using nova-volume service")) + sys.exit(1) + ctxt = context.get_admin_context() volume = db.volume_get(ctxt, param2id(volume_id)) host = volume['host'] @@ -791,7 +799,7 @@ class VolumeCommands(object): if not host: print "Volume not yet assigned to host." print "Deleting volume from database and skipping rpc." - db.volume_destroy(ctxt, param2id(volume_id)) + db.volume_destroy(ctxt, volume_id) return if volume['status'] == 'in-use': @@ -810,8 +818,15 @@ class VolumeCommands(object): """Re-attach a volume that has previously been attached to an instance. Typically called after a compute host has been rebooted.""" + + if 'cinder' in FLAGS.volume_api_class: + print(_("\"nova-manage volume reattach\" only valid " + "when using nova-volume service")) + sys.exit(1) + ctxt = context.get_admin_context() volume = db.volume_get(ctxt, param2id(volume_id)) + if not volume['instance_id']: print "volume is not attached to an instance" return