summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/host_evacuate.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/host_evacuate.py')
-rw-r--r--novaclient/v2/contrib/host_evacuate.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/host_evacuate.py b/novaclient/v2/contrib/host_evacuate.py
new file mode 100644
index 0000000..b08e28c
--- /dev/null
+++ b/novaclient/v2/contrib/host_evacuate.py
@@ -0,0 +1,64 @@
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 EvacuateHostResponse(base.Resource):
23 pass
24
25
26def _server_evacuate(cs, server, args):
27 success = True
28 error_message = ""
29 try:
30 cs.servers.evacuate(server=server['uuid'], host=args.target_host,
31 on_shared_storage=args.on_shared_storage)
32 except Exception as e:
33 success = False
34 error_message = _("Error while evacuating instance: %s") % e
35 return EvacuateHostResponse(base.Manager,
36 {"server_uuid": server['uuid'],
37 "evacuate_accepted": success,
38 "error_message": 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. If no host is specified the scheduler will '
47 'select a target.'))
48@cliutils.arg(
49 '--on-shared-storage',
50 dest='on_shared_storage',
51 action="store_true",
52 default=False,
53 help=_('Specifies whether all instances files are on shared storage'))
54def do_host_evacuate(cs, args):
55 """Evacuate all instances from failed host."""
56 hypervisors = cs.hypervisors.search(args.host, servers=True)
57 response = []
58 for hyper in hypervisors:
59 if hasattr(hyper, 'servers'):
60 for server in hyper.servers:
61 response.append(_server_evacuate(cs, server, args))
62
63 utils.print_list(response,
64 ["Server UUID", "Evacuate Accepted", "Error Message"])