summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/host_evacuate_live.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/host_evacuate_live.py')
-rw-r--r--novaclient/v2/contrib/host_evacuate_live.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/host_evacuate_live.py b/novaclient/v2/contrib/host_evacuate_live.py
new file mode 100644
index 0000000..276fb2f
--- /dev/null
+++ b/novaclient/v2/contrib/host_evacuate_live.py
@@ -0,0 +1,68 @@
1# Copyright 2014 OpenStack Foundation
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.i18n import _
17from novaclient.openstack.common import cliutils
18from novaclient import utils
19
20
21def _server_live_migrate(cs, server, args):
22 class HostEvacuateLiveResponse(object):
23 def __init__(self, server_uuid, live_migration_accepted,
24 error_message):
25 self.server_uuid = server_uuid
26 self.live_migration_accepted = live_migration_accepted
27 self.error_message = error_message
28 success = True
29 error_message = ""
30 try:
31 cs.servers.live_migrate(server['uuid'], args.target_host,
32 args.block_migrate, args.disk_over_commit)
33 except Exception as e:
34 success = False
35 error_message = _("Error while live migrating instance: %s") % e
36 return HostEvacuateLiveResponse(server['uuid'],
37 success,
38 error_message)
39
40
41@cliutils.arg('host', metavar='<host>', help='Name of host.')
42@cliutils.arg(
43 '--target-host',
44 metavar='<target_host>',
45 default=None,
46 help=_('Name of target host.'))
47@cliutils.arg(
48 '--block-migrate',
49 action='store_true',
50 default=False,
51 help=_('Enable block migration.'))
52@cliutils.arg(
53 '--disk-over-commit',
54 action='store_true',
55 default=False,
56 help=_('Enable disk overcommit.'))
57def do_host_evacuate_live(cs, args):
58 """Live migrate all instances of the specified host
59 to other available hosts.
60 """
61 hypervisors = cs.hypervisors.search(args.host, servers=True)
62 response = []
63 for hyper in hypervisors:
64 for server in getattr(hyper, 'servers', []):
65 response.append(_server_live_migrate(cs, server, args))
66
67 utils.print_list(response, ["Server UUID", "Live Migration Accepted",
68 "Error Message"])