From b5f3307e8013d5817eee5022dd026e06caef792f Mon Sep 17 00:00:00 2001
From: Alessio Ababilov <aababilov@griddynamics.com>
Date: Thu, 10 Jan 2013 20:49:22 +0400
Subject: [PATCH] Update hosts API action calls (startup etc.)

These calls are now implemented as normal
POST os-hosts/{host_name}/action requests.

Change-Id: I8cd401e3b4e552c6787d1f984041ad3c345e6eca
---
 novaclient/v1_1/hosts.py |  5 +++--
 tests/v1_1/fakes.py      | 13 ++-----------
 tests/v1_1/test_hosts.py |  9 +++------
 tests/v1_1/test_shell.py |  6 +++---
 4 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/novaclient/v1_1/hosts.py b/novaclient/v1_1/hosts.py
index a6f5a04a0..3dea7021e 100644
--- a/novaclient/v1_1/hosts.py
+++ b/novaclient/v1_1/hosts.py
@@ -58,8 +58,9 @@ class HostManager(base.ManagerWithFind):
 
     def host_action(self, host, action):
         """Performs an action on a host."""
-        url = "/os-hosts/%s/%s" % (host, action)
-        return self._create(url, None, "host")
+        body = {action: None}
+        url = '/os-hosts/%s/action' % host
+        return self.api.client.post(url, body=body)
 
     def list_all(self, zone=None):
         url = '/os-hosts'
diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py
index 4dd17f6e7..42fdde7c8 100644
--- a/tests/v1_1/fakes.py
+++ b/tests/v1_1/fakes.py
@@ -1159,17 +1159,8 @@ class FakeHTTPClient(base_client.HTTPClient):
                                    'status': 'enabled',
                                    'maintenance_mode': 'on_maintenance'}})
 
-    def post_os_hosts_sample_host_startup(self, **kw):
-        return (200, {}, {'host': {'host_name': 'sample_host',
-                                   'power_action': 'startup'}})
-
-    def post_os_hosts_sample_host_reboot(self, **kw):
-        return (200, {}, {'host': {'host_name': 'sample_host',
-                                   'power_action': 'reboot'}})
-
-    def post_os_hosts_sample_host_shutdown(self, **kw):
-        return (200, {}, {'host': {'host_name': 'sample_host',
-                                   'power_action': 'shutdown'}})
+    def post_os_hosts_sample_host_action(self, **kw):
+        return (202, {}, None)
 
     def put_os_hosts_sample_host(self, body, **kw):
         result = {'host_name': 'dummy'}
diff --git a/tests/v1_1/test_hosts.py b/tests/v1_1/test_hosts.py
index 57c2891a8..28964279d 100644
--- a/tests/v1_1/test_hosts.py
+++ b/tests/v1_1/test_hosts.py
@@ -50,17 +50,14 @@ class HostsTest(utils.TestCase):
     def test_host_startup(self):
         host = cs.hosts.get('sample_host')[0]
         result = host.startup()
-        cs.assert_called('POST', '/os-hosts/sample_host/startup')
-        self.assertTrue(isinstance(result, hosts.Host))
+        cs.assert_called('POST', '/os-hosts/sample_host/action', {'startup': None})
 
     def test_host_reboot(self):
         host = cs.hosts.get('sample_host')[0]
         result = host.reboot()
-        cs.assert_called('POST', '/os-hosts/sample_host/reboot')
-        self.assertTrue(isinstance(result, hosts.Host))
+        cs.assert_called('POST', '/os-hosts/sample_host/action', {'reboot': None})
 
     def test_host_shutdown(self):
         host = cs.hosts.get('sample_host')[0]
         result = host.shutdown()
-        cs.assert_called('POST', '/os-hosts/sample_host/shutdown')
-        self.assertTrue(isinstance(result, hosts.Host))
+        cs.assert_called('POST', '/os-hosts/sample_host/action', {'shutdown': None})
diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py
index 6565f1317..db2647f11 100644
--- a/tests/v1_1/test_shell.py
+++ b/tests/v1_1/test_shell.py
@@ -634,15 +634,15 @@ class ShellTest(utils.TestCase):
 
     def test_host_startup(self):
         self.run_command('host-action sample-host --action startup')
-        self.assert_called('POST', '/os-hosts/sample-host/startup')
+        self.assert_called('POST', '/os-hosts/sample-host/action', {'startup': None})
 
     def test_host_shutdown(self):
         self.run_command('host-action sample-host --action shutdown')
-        self.assert_called('POST', '/os-hosts/sample-host/shutdown')
+        self.assert_called('POST', '/os-hosts/sample-host/action', {'shutdown': None})
 
     def test_host_reboot(self):
         self.run_command('host-action sample-host --action reboot')
-        self.assert_called('POST', '/os-hosts/sample-host/reboot')
+        self.assert_called('POST', '/os-hosts/sample-host/action', {'reboot': None})
 
     def test_coverage_start(self):
         self.run_command('coverage-start')