summaryrefslogtreecommitdiff
path: root/novaclient/v2/services.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/services.py')
-rw-r--r--novaclient/v2/services.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/novaclient/v2/services.py b/novaclient/v2/services.py
new file mode 100644
index 0000000..d51fa3e
--- /dev/null
+++ b/novaclient/v2/services.py
@@ -0,0 +1,75 @@
1# Copyright 2012 IBM Corp.
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"""
17service interface
18"""
19from novaclient import base
20
21
22class Service(base.Resource):
23 def __repr__(self):
24 return "<Service: %s>" % self.binary
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
32class ServiceManager(base.ManagerWithFind):
33 resource_class = Service
34
35 def list(self, host=None, binary=None):
36 """
37 Describes cpu/memory/hdd info for host.
38
39 :param host: destination host name.
40 """
41 url = "/os-services"
42 filters = []
43 if host:
44 filters.append("host=%s" % host)
45 if binary:
46 filters.append("binary=%s" % binary)
47 if filters:
48 url = "%s?%s" % (url, "&".join(filters))
49 return self._list(url, "services")
50
51 def _update_body(self, host, binary, disabled_reason=None):
52 body = {"host": host,
53 "binary": binary}
54 if disabled_reason is not None:
55 body["disabled_reason"] = disabled_reason
56 return body
57
58 def enable(self, host, binary):
59 """Enable the service specified by hostname and binary."""
60 body = self._update_body(host, binary)
61 return self._update("/os-services/enable", body, "service")
62
63 def disable(self, host, binary):
64 """Disable the service specified by hostname and binary."""
65 body = self._update_body(host, binary)
66 return self._update("/os-services/disable", body, "service")
67
68 def disable_log_reason(self, host, binary, reason):
69 """Disable the service with reason."""
70 body = self._update_body(host, binary, reason)
71 return self._update("/os-services/disable-log-reason", body, "service")
72
73 def delete(self, service_id):
74 """Delete a service."""
75 return self._delete("/os-services/%s" % service_id)