1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Resource class and its manager for services in Compute API v2
18 """
19
20 from yakumo import base
21 from yakumo.constant import UNDEF
22 from yakumo import mapper
23 from yakumo import utils
24
25
26 ATTRIBUTE_MAPPING = [
27 ('id', 'id', mapper.Noop),
28 ('host', 'host', mapper.Noop),
29 ('binary', 'binary', mapper.Noop),
30 ('state', 'state', mapper.Noop),
31 ('status', 'status', mapper.Noop),
32 ('updated_at', 'updated_at', mapper.DateTime),
33 ('availability_zone', 'zone',
34 mapper.Resource('nova.availability_zone')),
35 ('disabled_reason', 'disabled_reason', mapper.Noop),
36 ]
37
38
40 """Resource class for services in Compute API v2"""
41
43 """
44 Enable a service on a host
45
46 @rtype: None
47 """
48 self._manager.enable(host=self.host, binary=self.binary)
49
51 """
52 Disable a service on a host
53
54 @rtype: None
55 """
56 self._manager.disable(host=self.host, binary=self.binary)
57
59 """
60 Set disabled reason for a service on a host
61
62 @keyword reason: Description
63 @type reason: str
64 @rtype: None
65 """
66 self._manager.set_disabled_reason(host=self.host, binary=self.binary,
67 reason=reason)
68
70 """
71 Create a host aggregate
72
73 @keyword name: name of the host aggregate
74 @type name: str
75 @keyword availability_zone: name of availability zone
76 @type availability_zone: str
77 @rtype: None
78 """
79 super(Resource, self).update(
80 name=name,
81 availability_zone=availability_zone)
82
83
85 """Manager class for services in Compute API v2"""
86
87 resource_class = Resource
88 service_type = 'compute'
89 _attr_mapping = ATTRIBUTE_MAPPING
90 _hidden_methods = ["create"]
91 _json_resource_key = 'service'
92 _json_resources_key = 'services'
93 _url_resource_path = '/os-services'
94
95 - def enable(self, host=None, binary=None):
96 """
97 Enable a service on a host
98
99 @keyword host: host name (required)
100 @type host: str
101 @keyword binary: binary name (required)
102 @type binary: str
103 @rtype: None
104 """
105 self._http.put(self._url_resource_path, "enable",
106 data=dict(host=host, binary=binary))
107
108 - def disable(self, host=None, binary=None):
109 """
110 Disable a service on a host
111
112 @keyword host: host name (required)
113 @type host: str
114 @keyword binary: binary name (required)
115 @type binary: str
116 @rtype: None
117 """
118 self._http.put(self._url_resource_path, "disable",
119 data=dict(host=host, binary=binary))
120
122 """
123 Set disabled reason for a service on a host
124
125 @keyword host: host name (required)
126 @type host: str
127 @keyword binary: binary name (required)
128 @type binary: str
129 @keyword reason: description (required)
130 @type reason: str
131 @rtype: None
132 """
133 self._http.put(self._url_resource_path, "disable-log-reason",
134 data=dict(host=host, binary=binary,
135 disabled_reason=reason))
136