summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/migrations.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/migrations.py')
-rw-r--r--novaclient/v2/contrib/migrations.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/migrations.py b/novaclient/v2/contrib/migrations.py
new file mode 100644
index 0000000..1595981
--- /dev/null
+++ b/novaclient/v2/contrib/migrations.py
@@ -0,0 +1,91 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13"""
14migration interface
15"""
16
17from six.moves.urllib import parse
18
19from novaclient import base
20from novaclient.i18n import _
21from novaclient.openstack.common import cliutils
22from novaclient import utils
23
24
25class Migration(base.Resource):
26 def __repr__(self):
27 return "<Migration: %s>" % self.id
28
29
30class MigrationManager(base.ManagerWithFind):
31 resource_class = Migration
32
33 def list(self, host=None, status=None, cell_name=None):
34 """
35 Get a list of migrations.
36 :param host: (optional) filter migrations by host name.
37 :param status: (optional) filter migrations by status.
38 :param cell_name: (optional) filter migrations for a cell.
39 """
40 opts = {}
41 if host:
42 opts['host'] = host
43 if status:
44 opts['status'] = status
45 if cell_name:
46 opts['cell_name'] = cell_name
47
48 # Transform the dict to a sequence of two-element tuples in fixed
49 # order, then the encoded string will be consistent in Python 2&3.
50 new_opts = sorted(opts.items(), key=lambda x: x[0])
51
52 query_string = "?%s" % parse.urlencode(new_opts) if new_opts else ""
53
54 return self._list("/os-migrations%s" % query_string, "migrations")
55
56
57@cliutils.arg(
58 '--host',
59 dest='host',
60 metavar='<host>',
61 help=_('Fetch migrations for the given host.'))
62@cliutils.arg(
63 '--status',
64 dest='status',
65 metavar='<status>',
66 help=_('Fetch migrations for the given status.'))
67@cliutils.arg(
68 '--cell_name',
69 dest='cell_name',
70 metavar='<cell_name>',
71 help=_('Fetch migrations for the given cell_name.'))
72def do_migration_list(cs, args):
73 """Print a list of migrations."""
74 _print_migrations(cs.migrations.list(args.host, args.status,
75 args.cell_name))
76
77
78def _print_migrations(migrations):
79 fields = ['Source Node', 'Dest Node', 'Source Compute', 'Dest Compute',
80 'Dest Host', 'Status', 'Instance UUID', 'Old Flavor',
81 'New Flavor', 'Created At', 'Updated At']
82
83 def old_flavor(migration):
84 return migration.old_instance_type_id
85
86 def new_flavor(migration):
87 return migration.new_instance_type_id
88
89 formatters = {'Old Flavor': old_flavor, 'New Flavor': new_flavor}
90
91 utils.print_list(migrations, fields, formatters)