summaryrefslogtreecommitdiff
path: root/novaclient/v2/hypervisors.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/hypervisors.py')
-rw-r--r--novaclient/v2/hypervisors.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/novaclient/v2/hypervisors.py b/novaclient/v2/hypervisors.py
new file mode 100644
index 0000000..b1bfcb4
--- /dev/null
+++ b/novaclient/v2/hypervisors.py
@@ -0,0 +1,92 @@
1# Copyright 2012 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"""
17Hypervisors interface (1.1 extension).
18"""
19
20from six.moves.urllib import parse
21
22from novaclient import base
23
24
25class Hypervisor(base.Resource):
26 NAME_ATTR = 'hypervisor_hostname'
27
28 def __repr__(self):
29 return "<Hypervisor: %s>" % self.id
30
31
32class HypervisorManager(base.ManagerWithFind):
33 resource_class = Hypervisor
34
35 def list(self, detailed=True):
36 """
37 Get a list of hypervisors.
38 """
39 detail = ""
40 if detailed:
41 detail = "/detail"
42 return self._list('/os-hypervisors%s' % detail, 'hypervisors')
43
44 def search(self, hypervisor_match, servers=False):
45 """
46 Get a list of matching hypervisors.
47
48 :param servers: If True, server information is also retrieved.
49 """
50 target = 'servers' if servers else 'search'
51 url = ('/os-hypervisors/%s/%s' %
52 (parse.quote(hypervisor_match, safe=''), target))
53 return self._list(url, 'hypervisors')
54
55 def get(self, hypervisor):
56 """
57 Get a specific hypervisor.
58 """
59 return self._get("/os-hypervisors/%s" % base.getid(hypervisor),
60 "hypervisor")
61
62 def uptime(self, hypervisor):
63 """
64 Get the uptime for a specific hypervisor.
65 """
66 return self._get("/os-hypervisors/%s/uptime" % base.getid(hypervisor),
67 "hypervisor")
68
69 def statistics(self):
70 """
71 Get hypervisor statistics over all compute nodes.
72
73 Kept for backwards compatibility, new code should call
74 hypervisor_stats.statistics() instead of hypervisors.statistics()
75 """
76 return self.api.hypervisor_stats.statistics()
77
78
79class HypervisorStats(base.Resource):
80 def __repr__(self):
81 return ("<HypervisorStats: %d Hypervisor%s>" %
82 (self.count, "s" if self.count != 1 else ""))
83
84
85class HypervisorStatsManager(base.Manager):
86 resource_class = HypervisorStats
87
88 def statistics(self):
89 """
90 Get hypervisor statistics over all compute nodes.
91 """
92 return self._get("/os-hypervisors/statistics", "hypervisor_statistics")