summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/cells.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/cells.py')
-rw-r--r--novaclient/v2/contrib/cells.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/cells.py b/novaclient/v2/contrib/cells.py
new file mode 100644
index 0000000..bfc6893
--- /dev/null
+++ b/novaclient/v2/contrib/cells.py
@@ -0,0 +1,74 @@
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 Cell(base.Resource):
23 def __repr__(self):
24 return "<Cell: %s>" % self.name
25
26
27class CellsManager(base.Manager):
28 resource_class = Cell
29
30 def get(self, cell_name):
31 """
32 Get a cell.
33
34 :param cell: Name of the :class:`Cell` to get.
35 :rtype: :class:`Cell`
36 """
37 return self._get("/os-cells/%s" % cell_name, "cell")
38
39 def capacities(self, cell_name=None):
40 """
41 Get capacities for a cell.
42
43 :param cell: Name of the :class:`Cell` to get capacities for.
44 :rtype: :class:`Cell`
45 """
46 path = ["%s/capacities" % cell_name, "capacities"][cell_name is None]
47 return self._get("/os-cells/%s" % path, "cell")
48
49
50@cliutils.arg(
51 'cell',
52 metavar='<cell-name>',
53 help=_('Name of the cell.'))
54def do_cell_show(cs, args):
55 """Show details of a given cell."""
56 cell = cs.cells.get(args.cell)
57 utils.print_dict(cell._info)
58
59
60@cliutils.arg(
61 '--cell',
62 metavar='<cell-name>',
63 help=_("Name of the cell to get the capacities."),
64 default=None)
65def do_cell_capacities(cs, args):
66 """Get cell capacities for all cells or a given cell."""
67 cell = cs.cells.capacities(args.cell)
68 print(_("Ram Available: %s MB") % cell.capacities['ram_free']['total_mb'])
69 utils.print_dict(cell.capacities['ram_free']['units_by_mb'],
70 dict_property='Ram(MB)', dict_value="Units")
71 print(_("\nDisk Available: %s MB") %
72 cell.capacities['disk_free']['total_mb'])
73 utils.print_dict(cell.capacities['disk_free']['units_by_mb'],
74 dict_property='Disk(MB)', dict_value="Units")