blob: 032e1da7fb6dbf2e58f371a37b78f0402686083a [file] [log] [blame]
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +03001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from tempest.services.baremetal import base
14
15
16class BaremetalClientV1(base.BaremetalClient):
17 """
18 Base Tempest REST client for Ironic API v1.
19
20 Specific implementations must implement serialize and deserialize
21 methods in order to send requests to Ironic.
22
23 """
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000024 def __init__(self, auth_provider):
25 super(BaremetalClientV1, self).__init__(auth_provider)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030026 self.version = '1'
27 self.uri_prefix = 'v%s' % self.version
28
29 @base.handle_errors
30 def list_nodes(self):
31 """List all existing nodes."""
32 return self._list_request('nodes')
33
34 @base.handle_errors
35 def list_chassis(self):
36 """List all existing chassis."""
37 return self._list_request('chassis')
38
39 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040040 def list_ports(self, **kwargs):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030041 """List all existing ports."""
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040042 return self._list_request('ports', **kwargs)
43
44 @base.handle_errors
Mh Raiesfbe54512014-04-08 12:25:15 +053045 def list_nodestates(self, uuid):
46 """List all existing states."""
47 return self._list_request('/nodes/%s/states' % uuid)
48
49 @base.handle_errors
Yuiko Takada3083fca2014-04-25 11:52:33 +000050 def list_ports_detail(self, **kwargs):
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040051 """Details list all existing ports."""
Yuiko Takada3083fca2014-04-25 11:52:33 +000052 return self._list_request('/ports/detail', **kwargs)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030053
54 @base.handle_errors
Mh Raiesb71cb7f2014-03-28 10:51:31 +053055 def list_drivers(self):
56 """List all existing drivers."""
57 return self._list_request('drivers')
58
59 @base.handle_errors
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030060 def show_node(self, uuid):
61 """
62 Gets a specific node.
63
64 :param uuid: Unique identifier of the node in UUID format.
65 :return: Serialized node as a dictionary.
66
67 """
68 return self._show_request('nodes', uuid)
69
70 @base.handle_errors
71 def show_chassis(self, uuid):
72 """
73 Gets a specific chassis.
74
75 :param uuid: Unique identifier of the chassis in UUID format.
76 :return: Serialized chassis as a dictionary.
77
78 """
79 return self._show_request('chassis', uuid)
80
81 @base.handle_errors
82 def show_port(self, uuid):
83 """
84 Gets a specific port.
85
86 :param uuid: Unique identifier of the port in UUID format.
87 :return: Serialized port as a dictionary.
88
89 """
90 return self._show_request('ports', uuid)
91
Yuiko Takada8e2dfca2014-04-24 18:10:52 +000092 def show_driver(self, driver_name):
93 """
94 Gets a specific driver.
95
96 :param driver_name: Name of driver.
97 :return: Serialized driver as a dictionary.
98 """
99 return self._show_request('drivers', driver_name)
100
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300101 @base.handle_errors
102 def create_node(self, chassis_id, **kwargs):
103 """
104 Create a baremetal node with the specified parameters.
105
106 :param cpu_arch: CPU architecture of the node. Default: x86_64.
107 :param cpu_num: Number of CPUs. Default: 8.
108 :param storage: Disk size. Default: 1024.
109 :param memory: Available RAM. Default: 4096.
110 :param driver: Driver name. Default: "fake"
111 :return: A tuple with the server response and the created node.
112
113 """
114 node = {'chassis_uuid': chassis_id,
115 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'),
116 'cpu_num': kwargs.get('cpu_num', 8),
117 'storage': kwargs.get('storage', 1024),
118 'memory': kwargs.get('memory', 4096)},
119 'driver': kwargs.get('driver', 'fake')}
120
121 return self._create_request('nodes', 'node', node)
122
123 @base.handle_errors
124 def create_chassis(self, **kwargs):
125 """
126 Create a chassis with the specified parameters.
127
128 :param description: The description of the chassis.
129 Default: test-chassis
130 :return: A tuple with the server response and the created chassis.
131
132 """
133 chassis = {'description': kwargs.get('description', 'test-chassis')}
134
135 return self._create_request('chassis', 'chassis', chassis)
136
137 @base.handle_errors
138 def create_port(self, node_id, **kwargs):
139 """
140 Create a port with the specified parameters.
141
142 :param node_id: The ID of the node which owns the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400143 :param address: MAC address of the port.
144 :param extra: Meta data of the port. Default: {'foo': 'bar'}.
145 :param uuid: UUID of the port.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300146 :return: A tuple with the server response and the created port.
147
148 """
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400149 port = {'extra': kwargs.get('extra', {'foo': 'bar'}),
150 'uuid': kwargs['uuid']}
151
152 if node_id is not None:
153 port['node_uuid'] = node_id
154
155 if kwargs['address'] is not None:
156 port['address'] = kwargs['address']
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300157
158 return self._create_request('ports', 'port', port)
159
160 @base.handle_errors
161 def delete_node(self, uuid):
162 """
163 Deletes a node having the specified UUID.
164
165 :param uuid: The unique identifier of the node.
166 :return: A tuple with the server response and the response body.
167
168 """
169 return self._delete_request('nodes', uuid)
170
171 @base.handle_errors
172 def delete_chassis(self, uuid):
173 """
174 Deletes a chassis having the specified UUID.
175
176 :param uuid: The unique identifier of the chassis.
177 :return: A tuple with the server response and the response body.
178
179 """
180 return self._delete_request('chassis', uuid)
181
182 @base.handle_errors
183 def delete_port(self, uuid):
184 """
185 Deletes a port having the specified UUID.
186
187 :param uuid: The unique identifier of the port.
188 :return: A tuple with the server response and the response body.
189
190 """
191 return self._delete_request('ports', uuid)
192
193 @base.handle_errors
194 def update_node(self, uuid, **kwargs):
195 """
196 Update the specified node.
197
198 :param uuid: The unique identifier of the node.
199 :return: A tuple with the server response and the updated node.
200
201 """
202 node_attributes = ('properties/cpu_arch',
203 'properties/cpu_num',
204 'properties/storage',
205 'properties/memory',
206 'driver')
207
208 patch = self._make_patch(node_attributes, **kwargs)
209
210 return self._patch_request('nodes', uuid, patch)
211
212 @base.handle_errors
213 def update_chassis(self, uuid, **kwargs):
214 """
215 Update the specified chassis.
216
217 :param uuid: The unique identifier of the chassis.
218 :return: A tuple with the server response and the updated chassis.
219
220 """
221 chassis_attributes = ('description',)
222 patch = self._make_patch(chassis_attributes, **kwargs)
223
224 return self._patch_request('chassis', uuid, patch)
225
226 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400227 def update_port(self, uuid, patch):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300228 """
229 Update the specified port.
230
231 :param uuid: The unique identifier of the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400232 :param patch: List of dicts representing json patches.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300233 :return: A tuple with the server response and the updated port.
234
235 """
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300236
237 return self._patch_request('ports', uuid, patch)
Mh Raiesf8ecf232014-04-17 12:43:55 +0530238
239 @base.handle_errors
240 def set_node_power_state(self, node_uuid, state):
241 """
242 Set power state of the specified node.
243
244 :param node_uuid: The unique identifier of the node.
245 :state: desired state to set (on/off/reboot).
246
247 """
248 target = {'target': state}
249 return self._put_request('nodes/%s/states/power' % node_uuid,
250 target)
raiesmh08e5d84572014-06-23 09:49:03 +0530251
252 @base.handle_errors
253 def validate_driver_interface(self, node_uuid):
254 """
255 Get all driver interfaces of a specific node.
256
257 :param uuid: Unique identifier of the node in UUID format.
258
259 """
260
261 uri = '{pref}/{res}/{uuid}/{postf}'.format(pref=self.uri_prefix,
262 res='nodes',
263 uuid=node_uuid,
264 postf='validate')
265
266 return self._show_request('nodes', node_uuid, uri=uri)
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100267
268 @base.handle_errors
269 def set_node_boot_device(self, node_uuid, boot_device, persistent=False):
270 """
271 Set the boot device of the specified node.
272
273 :param node_uuid: The unique identifier of the node.
274 :param boot_device: The boot device name.
275 :param persistent: Boolean value. True if the boot device will
276 persist to all future boots, False if not.
277 Default: False.
278
279 """
280 request = {'boot_device': boot_device, 'persistent': persistent}
281 resp, body = self._put_request('nodes/%s/management/boot_device' %
282 node_uuid, request)
283 self.expected_success(204, resp.status)
284 return body
285
286 @base.handle_errors
287 def get_node_boot_device(self, node_uuid):
288 """
289 Get the current boot device of the specified node.
290
291 :param node_uuid: The unique identifier of the node.
292
293 """
294 path = 'nodes/%s/management/boot_device' % node_uuid
295 resp, body = self._list_request(path)
296 self.expected_success(200, resp.status)
297 return body
298
299 @base.handle_errors
300 def get_node_supported_boot_devices(self, node_uuid):
301 """
302 Get the supported boot devices of the specified node.
303
304 :param node_uuid: The unique identifier of the node.
305
306 """
307 path = 'nodes/%s/management/boot_device/supported' % node_uuid
308 resp, body = self._list_request(path)
309 self.expected_success(200, resp.status)
310 return body
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900311
312 @base.handle_errors
313 def get_console(self, node_uuid):
314 """
315 Get connection information about the console.
316
317 :param node_uuid: Unique identifier of the node in UUID format.
318
319 """
320
321 resp, body = self._show_request('nodes/states/console', node_uuid)
322 self.expected_success(200, resp.status)
323 return resp, body
324
325 @base.handle_errors
326 def set_console_mode(self, node_uuid, enabled):
327 """
328 Start and stop the node console.
329
330 :param node_uuid: Unique identifier of the node in UUID format.
331 :param enabled: Boolean value; whether to enable or disable the
332 console.
333
334 """
335
336 enabled = {'enabled': enabled}
337 resp, body = self._put_request('nodes/%s/states/console' % node_uuid,
338 enabled)
339 self.expected_success(202, resp.status)
340 return resp, body