Permalink
Browse files

Admin action to reset states.

Adds support for the new Nova Admin API action which resets the state
of an instance.  This will at least allow easy clean-up from bugs
which corrupt the state of an instance and inhibit the owner of the
instance from deleting it.

Change-Id: I47d1d75e3bd2a07b3b75302b512122b27d5d79d9
  • Loading branch information...
1 parent a2a62a5 commit 3dd0d3be63b4bf35aede852d096deff9be5b63e4 Kevin L. Mitchell committed Jun 20, 2012
Showing with 43 additions and 0 deletions.
  1. +16 −0 novaclient/v1_1/servers.py
  2. +10 −0 novaclient/v1_1/shell.py
  3. +2 −0 tests/v1_1/fakes.py
  4. +7 −0 tests/v1_1/test_servers.py
  5. +8 −0 tests/v1_1/test_shell.py
@@ -252,6 +252,12 @@ def live_migrate(self, host,
block_migration,
disk_over_commit)
+ def reset_state(self, state='error'):
+ """
+ Reset the state of an instance to active or error.
+ """
+ self.manager.reset_state(self, state)
+
class ServerManager(local_base.BootingManagerWithFind):
resource_class = Server
@@ -631,6 +637,16 @@ def live_migrate(self, server, host, block_migration, disk_over_commit):
'block_migration': block_migration,
'disk_over_commit': disk_over_commit})
+ def reset_state(self, server, state='error'):
+ """
+ Reset the state of an instance to active or error.
+
+ :param server: ID of the instance to reset the state of.
+ :param state: Desired state; either 'active' or 'error'.
+ Defaults to 'error'.
+ """
+ self._action('os-resetState', server, dict(state=state))
+
def _action(self, action, server, info=None, **kwargs):
"""
Perform a server "action" -- reboot/rebuild/resize/etc.
@@ -1597,6 +1597,16 @@ def do_live_migration(cs, args):
args.disk_over_commit)
+@utils.arg('server', metavar='<server>', help='Name or ID of server.')
+@utils.arg('--active', action='store_const', dest='state',
+ default='error', const='active',
+ help='Request the instance be reset to "active" state instead '
+ 'of "error" state (the default).')
+def do_reset_state(cs, args):
+ """Reset the state of an instance"""
+ _find_server(cs, args.server).reset_state(args.state)
+
+
@utils.arg('host', metavar='<hostname>', help='Name of host.')
def do_describe_resource(cs, args):
"""Show details about a resource"""
View
@@ -339,6 +339,8 @@ def post_servers_1234_action(self, body, **kw):
assert set(body[action].keys()) == set(['host',
'block_migration',
'disk_over_commit'])
+ elif action == 'os-resetState':
+ assert body[action].keys() == ['state']
else:
raise AssertionError("Unexpected server action: %s" % action)
return (resp, _body)
@@ -303,3 +303,10 @@ def test_live_migrate_server(self):
cs.servers.live_migrate(s, host='hostname', block_migration=False,
disk_over_commit=False)
cs.assert_called('POST', '/servers/1234/action')
+
+ def test_reset_state(self):
+ s = cs.servers.get(1234)
+ s.reset_state('newstate')
+ cs.assert_called('POST', '/servers/1234/action')
+ cs.servers.reset_state(s, 'newstate')
+ cs.assert_called('POST', '/servers/1234/action')
@@ -440,6 +440,14 @@ def test_live_migration(self):
'block_migration': True,
'disk_over_commit': True}})
+ def test_reset_state(self):
+ self.run_command('reset-state sample-server')
+ self.assert_called('POST', '/servers/1234/action',
+ {'os-resetState': {'state': 'error'}})
+ self.run_command('reset-state sample-server --active')
+ self.assert_called('POST', '/servers/1234/action',
+ {'os-resetState': {'state': 'active'}})
+
def test_host_update_status(self):
self.run_command('host-update sample-host_1 --status enabled')
body = {'status': 'enabled'}

0 comments on commit 3dd0d3b

Please sign in to comment.