OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cells.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. from novaclient import base
  16. from novaclient.i18n import _
  17. from novaclient.openstack.common import cliutils
  18. from novaclient import utils
  19. class Cell(base.Resource):
  20. def __repr__(self):
  21. return "<Cell: %s>" % self.name
  22. class CellsManager(base.Manager):
  23. resource_class = Cell
  24. def get(self, cell_name):
  25. """
  26. Get a cell.
  27. :param cell: Name of the :class:`Cell` to get.
  28. :rtype: :class:`Cell`
  29. """
  30. return self._get("/os-cells/%s" % cell_name, "cell")
  31. def capacities(self, cell_name=None):
  32. """
  33. Get capacities for a cell.
  34. :param cell: Name of the :class:`Cell` to get capacities for.
  35. :rtype: :class:`Cell`
  36. """
  37. path = ["%s/capacities" % cell_name, "capacities"][cell_name is None]
  38. return self._get("/os-cells/%s" % path, "cell")
  39. @cliutils.arg(
  40. 'cell',
  41. metavar='<cell-name>',
  42. help=_('Name of the cell.'))
  43. def do_cell_show(cs, args):
  44. """Show details of a given cell."""
  45. cell = cs.cells.get(args.cell)
  46. utils.print_dict(cell._info)
  47. @cliutils.arg(
  48. '--cell',
  49. metavar='<cell-name>',
  50. help=_("Name of the cell to get the capacities."),
  51. default=None)
  52. def do_cell_capacities(cs, args):
  53. """Get cell capacities for all cells or a given cell."""
  54. cell = cs.cells.capacities(args.cell)
  55. print(_("Ram Available: %s MB") % cell.capacities['ram_free']['total_mb'])
  56. utils.print_dict(cell.capacities['ram_free']['units_by_mb'],
  57. dict_property='Ram(MB)', dict_value="Units")
  58. print(_("\nDisk Available: %s MB") %
  59. cell.capacities['disk_free']['total_mb'])
  60. utils.print_dict(cell.capacities['disk_free']['units_by_mb'],
  61. dict_property='Disk(MB)', dict_value="Units")