Add compute support server migrate operation

Implements: blueprint add-compute-migrate

Change-Id: I429b7439d933715c10b56a2b686e401969c1602f
Signed-off-by: Yuanbin.Chen <cybing4@gmail.com>
This commit is contained in:
Yuanbin.Chen 2017-05-18 22:21:17 +08:00
parent bc4a0c4066
commit 66e7a7faf2
4 changed files with 28 additions and 0 deletions

View File

@ -61,6 +61,7 @@ Starting, Stopping, etc.
.. automethod:: openstack.compute.v2._proxy.Proxy.rescue_server
.. automethod:: openstack.compute.v2._proxy.Proxy.unrescue_server
.. automethod:: openstack.compute.v2._proxy.Proxy.evacuate_server
.. automethod:: openstack.compute.v2._proxy.Proxy.migrate_server
Modifying a Server
******************

View File

@ -1244,3 +1244,14 @@ class Proxy(proxy2.BaseProxy):
server_id = resource2.Resource._get_id(server)
return self._list(_volume_attachment.VolumeAttachment, paginated=False,
server_id=server_id)
def migrate_server(self, server):
"""Migrate a server from one host to another
:param server: Either the ID of a server or a
:class:`~openstack.compute.v2.server.Server` instance.
:returns: None
"""
server = self._get_resource(_server.Server, server)
server.migrate(self._session)

View File

@ -336,6 +336,10 @@ class Server(resource2.Resource, metadata.MetadataMixin):
body = {"unshelve": None}
self._action(session, body)
def migrate(self, session):
body = {"migrate": None}
self._action(session, body)
class ServerDetail(Server):
base_path = '/servers/detail'

View File

@ -606,3 +606,15 @@ class TestServer(testtools.TestCase):
headers = {'Accept': ''}
self.sess.post.assert_called_with(
url, endpoint_filter=sot.service, json=body, headers=headers)
def test_migrate(self):
sot = server.Server(**EXAMPLE)
res = sot.migrate(self.sess)
self.assertIsNone(res)
url = 'servers/IDENTIFIER/action'
body = {"migrate": None}
headers = {'Accept': ''}
self.sess.post.assert_called_with(
url, endpoint_filter=sot.service, json=body, headers=headers)