From 739f4f6ac6038b5c5529d3368c7cd9bfd77f1d74 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 18 Jan 2011 13:46:06 -0800 Subject: [PATCH 1/3] fixes related to #701749. Also, added nova-manage commands to recover from certain states: # Delete a volume that is in an error state nova-manage cleanup delete_volume vol-id # reattach a volume. this is typically required after a host reboot nova-manage cleanup reattach_volume vol-id --- bin/nova-manage | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/bin/nova-manage b/bin/nova-manage index 1ad3120b..f8523f18 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -80,7 +80,9 @@ from nova import exception from nova import flags from nova import log as logging from nova import quota +from nova import rpc from nova import utils +from nova.api.ec2.cloud import ec2_id_to_id from nova.auth import manager from nova import rpc from nova.cloudpipe import pipelib @@ -597,6 +599,45 @@ class LogCommands(object): print re.sub('#012', "\n", "\n".join(lines)) +class CleanupCommands(object): + """Methods for dealing with a cloud in an odd state""" + + def delete_volume(self, volume_id): + """Delete a volume, bypassing the check that it + must be available. + args: volume_id_id""" + ctxt = context.get_admin_context() + volume = db.volume_get(ctxt, ec2_id_to_id(volume_id)) + host = volume['host'] + if volume['status'] == 'in-use': + print "Volume is in-use." + print "Detach volume from instance and then try again." + return + + rpc.cast(ctxt, + db.queue_get_for(ctxt, FLAGS.volume_topic, host), + {"method": "delete_volume", + "args": {"volume_id": volume['id']}}) + + def reattach_volume(self, volume_id): + """Re-attach a volume that has previously been attached + to an instance. Typically called after a compute host + has been rebooted. + args: volume_id_id""" + ctxt = context.get_admin_context() + volume = db.volume_get(ctxt, ec2_id_to_id(volume_id)) + if not volume['instance_id']: + print "volume is not attached to an instance" + return + instance = db.instance_get(ctxt, volume['instance_id']) + host = instance['host'] + rpc.cast(ctxt, + db.queue_get_for(ctxt, FLAGS.compute_topic, host), + {"method": "attach_volume", + "args": {"instance_id": instance['id'], + "volume_id": volume['id'], + "mountpoint": volume['mountpoint']}}) + CATEGORIES = [ ('user', UserCommands), ('project', ProjectCommands), @@ -608,7 +649,8 @@ CATEGORIES = [ ('instance', InstanceCommands), ('host', HostCommands), ('service', ServiceCommands), - ('log', LogCommands)] + ('log', LogCommands), + ('cleanup', CleanupCommands)] def lazy_match(name, key_value_tuples): From 16233256b984864b77c892654753d64959a6c34f Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 18 Jan 2011 14:17:54 -0800 Subject: [PATCH 2/3] s/cleanup/volume. volume commands will need their own ns in the long run --- bin/nova-manage | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index f8523f18..3e4f28fe 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -599,10 +599,10 @@ class LogCommands(object): print re.sub('#012', "\n", "\n".join(lines)) -class CleanupCommands(object): +class VolumeCommands(object): """Methods for dealing with a cloud in an odd state""" - def delete_volume(self, volume_id): + def delete(self, volume_id): """Delete a volume, bypassing the check that it must be available. args: volume_id_id""" @@ -619,7 +619,7 @@ class CleanupCommands(object): {"method": "delete_volume", "args": {"volume_id": volume['id']}}) - def reattach_volume(self, volume_id): + def reattach(self, volume_id): """Re-attach a volume that has previously been attached to an instance. Typically called after a compute host has been rebooted. @@ -650,7 +650,7 @@ CATEGORIES = [ ('host', HostCommands), ('service', ServiceCommands), ('log', LogCommands), - ('cleanup', CleanupCommands)] + ('volume', VolumeCommands)] def lazy_match(name, key_value_tuples): From 4d29e234f300079132dbf5aff3d58aa1070ef239 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 18 Jan 2011 16:12:52 -0800 Subject: [PATCH 3/3] per vish's feedback, allow admin to specify volume id in any of the acceptable manners (vol-, volume-, and int) Also, have manager only attempt to export volumes that are in-use or available --- bin/nova-manage | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 3e4f28fe..654a1382 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -98,6 +98,16 @@ flags.DECLARE('vpn_start', 'nova.network.manager') flags.DECLARE('fixed_range_v6', 'nova.network.manager') +def param2id(object_id): + """Helper function to convert various id types to internal id. + args: [object_id], e.g. 'vol-0000000a' or 'volume-0000000a' or '10' + """ + if '-' in object_id: + return ec2_id_to_id(object_id) + else: + return int(object_id) + + class VpnCommands(object): """Class for managing VPNs.""" @@ -607,7 +617,7 @@ class VolumeCommands(object): must be available. args: volume_id_id""" ctxt = context.get_admin_context() - volume = db.volume_get(ctxt, ec2_id_to_id(volume_id)) + volume = db.volume_get(ctxt, param2id(volume_id)) host = volume['host'] if volume['status'] == 'in-use': print "Volume is in-use." @@ -625,7 +635,7 @@ class VolumeCommands(object): has been rebooted. args: volume_id_id""" ctxt = context.get_admin_context() - volume = db.volume_get(ctxt, ec2_id_to_id(volume_id)) + volume = db.volume_get(ctxt, param2id(volume_id)) if not volume['instance_id']: print "volume is not attached to an instance" return