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.

hosts.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright 2011 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. """
  16. host interface (1.1 extension).
  17. """
  18. from novaclient import base
  19. class Host(base.Resource):
  20. def __repr__(self):
  21. return "<Host: %s>" % self.host
  22. def _add_details(self, info):
  23. dico = 'resource' in info and info['resource'] or info
  24. for (k, v) in dico.items():
  25. setattr(self, k, v)
  26. def update(self, values):
  27. return self.manager.update(self.host, values)
  28. def startup(self):
  29. return self.manager.host_action(self.host, 'startup')
  30. def shutdown(self):
  31. return self.manager.host_action(self.host, 'shutdown')
  32. def reboot(self):
  33. return self.manager.host_action(self.host, 'reboot')
  34. class HostManager(base.ManagerWithFind):
  35. resource_class = Host
  36. def get(self, host):
  37. """
  38. Describes cpu/memory/hdd info for host.
  39. :param host: destination host name.
  40. """
  41. return self._list("/os-hosts/%s" % host, "host")
  42. def update(self, host, values):
  43. """Update status or maintenance mode for the host."""
  44. return self._update("/os-hosts/%s" % host, values)
  45. def host_action(self, host, action):
  46. """Performs an action on a host."""
  47. body = {action: None}
  48. url = '/os-hosts/%s/action' % host
  49. return self.api.client.post(url, body=body)
  50. def list_all(self, zone=None):
  51. url = '/os-hosts'
  52. if zone:
  53. url = '/os-hosts?zone=%s' % zone
  54. return self._list(url, "hosts")