summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/host_servers_migrate.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/host_servers_migrate.py')
-rw-r--r--novaclient/v2/contrib/host_servers_migrate.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/host_servers_migrate.py b/novaclient/v2/contrib/host_servers_migrate.py
new file mode 100644
index 0000000..470f161
--- /dev/null
+++ b/novaclient/v2/contrib/host_servers_migrate.py
@@ -0,0 +1,51 @@
1# Copyright 2013 Rackspace Hosting
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from novaclient import base
17from novaclient.i18n import _
18from novaclient.openstack.common import cliutils
19from novaclient import utils
20
21
22class HostServersMigrateResponse(base.Resource):
23 pass
24
25
26def _server_migrate(cs, server):
27 success = True
28 error_message = ""
29 try:
30 cs.servers.migrate(server['uuid'])
31 except Exception as e:
32 success = False
33 error_message = _("Error while migrating instance: %s") % e
34 return HostServersMigrateResponse(base.Manager,
35 {"server_uuid": server['uuid'],
36 "migration_accepted": success,
37 "error_message": error_message})
38
39
40@cliutils.arg('host', metavar='<host>', help='Name of host.')
41def do_host_servers_migrate(cs, args):
42 """Migrate all instances of the specified host to other available hosts."""
43 hypervisors = cs.hypervisors.search(args.host, servers=True)
44 response = []
45 for hyper in hypervisors:
46 if hasattr(hyper, 'servers'):
47 for server in hyper.servers:
48 response.append(_server_migrate(cs, server))
49
50 utils.print_list(response,
51 ["Server UUID", "Migration Accepted", "Error Message"])