summaryrefslogtreecommitdiff
path: root/novaclient/v2/hosts.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/hosts.py')
-rw-r--r--novaclient/v2/hosts.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/novaclient/v2/hosts.py b/novaclient/v2/hosts.py
new file mode 100644
index 0000000..af1756a
--- /dev/null
+++ b/novaclient/v2/hosts.py
@@ -0,0 +1,70 @@
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"""
17host interface (1.1 extension).
18"""
19from novaclient import base
20
21
22class Host(base.Resource):
23 def __repr__(self):
24 return "<Host: %s>" % self.host
25
26 def _add_details(self, info):
27 dico = 'resource' in info and info['resource'] or info
28 for (k, v) in dico.items():
29 setattr(self, k, v)
30
31 def update(self, values):
32 return self.manager.update(self.host, values)
33
34 def startup(self):
35 return self.manager.host_action(self.host, 'startup')
36
37 def shutdown(self):
38 return self.manager.host_action(self.host, 'shutdown')
39
40 def reboot(self):
41 return self.manager.host_action(self.host, 'reboot')
42
43
44class HostManager(base.ManagerWithFind):
45 resource_class = Host
46
47 def get(self, host):
48 """
49 Describes cpu/memory/hdd info for host.
50
51 :param host: destination host name.
52 """
53 return self._list("/os-hosts/%s" % host, "host")
54
55 def update(self, host, values):
56 """Update status or maintenance mode for the host."""
57 return self._update("/os-hosts/%s" % host, values)
58
59 def host_action(self, host, action):
60 """Perform an action on a host."""
61 url = '/os-hosts/{0}/{1}'.format(host, action)
62 return self.api.client.get(url)
63
64 def list(self, zone=None):
65 url = '/os-hosts'
66 if zone:
67 url = '/os-hosts?zone=%s' % zone
68 return self._list(url, "hosts")
69
70 list_all = list