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.

server_groups.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (c) 2014 VMware, Inc.
  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. Server group interface.
  17. """
  18. from novaclient import base
  19. class ServerGroup(base.Resource):
  20. """
  21. A server group.
  22. """
  23. NAME_ATTR = 'server_group_name'
  24. def __repr__(self):
  25. return '<ServerGroup: %s>' % self.id
  26. def delete(self):
  27. self.manager.delete(self.id)
  28. class ServerGroupsManager(base.ManagerWithFind):
  29. """
  30. Manage :class:`ServerGroup` resources.
  31. """
  32. resource_class = ServerGroup
  33. def list(self):
  34. """Get a list of all server groups.
  35. :rtype: list of :class:`ServerGroup`.
  36. """
  37. return self._list('/os-server-groups', 'server_groups')
  38. def get(self, id):
  39. """Get a specific server group.
  40. :param id: The ID of the :class:`ServerGroup` to get.
  41. :rtype: :class:`ServerGroup`
  42. """
  43. return self._get('/os-server-groups/%s' % id,
  44. 'server_group')
  45. def delete(self, id):
  46. """Delete a specific server group.
  47. :param id: The ID of the :class:`ServerGroup` to delete.
  48. """
  49. self._delete('/os-server-groups/%s' % id)
  50. def create(self, **kwargs):
  51. """Create (allocate) a server group.
  52. :rtype: list of :class:`ServerGroup`
  53. """
  54. body = {'server_group': kwargs}
  55. return self._create('/os-server-groups', body, 'server_group')