blob: 9359808e2a358ee550a83f2c302c72c17e288226 [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
Adam Gandelman00682612014-09-02 17:10:36 -070030 def list_nodes(self, **kwargs):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030031 """List all existing nodes."""
Adam Gandelman00682612014-09-02 17:10:36 -070032 return self._list_request('nodes', **kwargs)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030033
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
Adam Gandelman00682612014-09-02 17:10:36 -070040 def list_chassis_nodes(self, chassis_uuid):
41 """List all nodes associated with a chassis."""
42 return self._list_request('/chassis/%s/nodes' % chassis_uuid)
43
44 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040045 def list_ports(self, **kwargs):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030046 """List all existing ports."""
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040047 return self._list_request('ports', **kwargs)
48
49 @base.handle_errors
Adam Gandelman00682612014-09-02 17:10:36 -070050 def list_node_ports(self, uuid):
51 """List all ports associated with the node."""
52 return self._list_request('/nodes/%s/ports' % uuid)
53
54 @base.handle_errors
Mh Raiesfbe54512014-04-08 12:25:15 +053055 def list_nodestates(self, uuid):
56 """List all existing states."""
57 return self._list_request('/nodes/%s/states' % uuid)
58
59 @base.handle_errors
Yuiko Takada3083fca2014-04-25 11:52:33 +000060 def list_ports_detail(self, **kwargs):
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040061 """Details list all existing ports."""
Yuiko Takada3083fca2014-04-25 11:52:33 +000062 return self._list_request('/ports/detail', **kwargs)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030063
64 @base.handle_errors
Mh Raiesb71cb7f2014-03-28 10:51:31 +053065 def list_drivers(self):
66 """List all existing drivers."""
67 return self._list_request('drivers')
68
69 @base.handle_errors
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030070 def show_node(self, uuid):
71 """
72 Gets a specific node.
73
74 :param uuid: Unique identifier of the node in UUID format.
75 :return: Serialized node as a dictionary.
76
77 """
78 return self._show_request('nodes', uuid)
79
80 @base.handle_errors
Adam Gandelman00682612014-09-02 17:10:36 -070081 def show_node_by_instance_uuid(self, instance_uuid):
82 """
83 Gets a node associated with given instance uuid.
84
85 :param uuid: Unique identifier of the node in UUID format.
86 :return: Serialized node as a dictionary.
87
88 """
89 uri = '/nodes/detail?instance_uuid=%s' % instance_uuid
90
91 return self._show_request('nodes',
92 uuid=None,
93 uri=uri)
94
95 @base.handle_errors
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030096 def show_chassis(self, uuid):
97 """
98 Gets a specific chassis.
99
100 :param uuid: Unique identifier of the chassis in UUID format.
101 :return: Serialized chassis as a dictionary.
102
103 """
104 return self._show_request('chassis', uuid)
105
106 @base.handle_errors
107 def show_port(self, uuid):
108 """
109 Gets a specific port.
110
111 :param uuid: Unique identifier of the port in UUID format.
112 :return: Serialized port as a dictionary.
113
114 """
115 return self._show_request('ports', uuid)
116
Yuiko Takada8e2dfca2014-04-24 18:10:52 +0000117 def show_driver(self, driver_name):
118 """
119 Gets a specific driver.
120
121 :param driver_name: Name of driver.
122 :return: Serialized driver as a dictionary.
123 """
124 return self._show_request('drivers', driver_name)
125
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300126 @base.handle_errors
127 def create_node(self, chassis_id, **kwargs):
128 """
129 Create a baremetal node with the specified parameters.
130
131 :param cpu_arch: CPU architecture of the node. Default: x86_64.
132 :param cpu_num: Number of CPUs. Default: 8.
133 :param storage: Disk size. Default: 1024.
134 :param memory: Available RAM. Default: 4096.
135 :param driver: Driver name. Default: "fake"
136 :return: A tuple with the server response and the created node.
137
138 """
139 node = {'chassis_uuid': chassis_id,
140 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'),
141 'cpu_num': kwargs.get('cpu_num', 8),
142 'storage': kwargs.get('storage', 1024),
143 'memory': kwargs.get('memory', 4096)},
144 'driver': kwargs.get('driver', 'fake')}
145
146 return self._create_request('nodes', 'node', node)
147
148 @base.handle_errors
149 def create_chassis(self, **kwargs):
150 """
151 Create a chassis with the specified parameters.
152
153 :param description: The description of the chassis.
154 Default: test-chassis
155 :return: A tuple with the server response and the created chassis.
156
157 """
158 chassis = {'description': kwargs.get('description', 'test-chassis')}
159
160 return self._create_request('chassis', 'chassis', chassis)
161
162 @base.handle_errors
163 def create_port(self, node_id, **kwargs):
164 """
165 Create a port with the specified parameters.
166
167 :param node_id: The ID of the node which owns the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400168 :param address: MAC address of the port.
169 :param extra: Meta data of the port. Default: {'foo': 'bar'}.
170 :param uuid: UUID of the port.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300171 :return: A tuple with the server response and the created port.
172
173 """
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400174 port = {'extra': kwargs.get('extra', {'foo': 'bar'}),
175 'uuid': kwargs['uuid']}
176
177 if node_id is not None:
178 port['node_uuid'] = node_id
179
180 if kwargs['address'] is not None:
181 port['address'] = kwargs['address']
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300182
183 return self._create_request('ports', 'port', port)
184
185 @base.handle_errors
186 def delete_node(self, uuid):
187 """
188 Deletes a node having the specified UUID.
189
190 :param uuid: The unique identifier of the node.
191 :return: A tuple with the server response and the response body.
192
193 """
194 return self._delete_request('nodes', uuid)
195
196 @base.handle_errors
197 def delete_chassis(self, uuid):
198 """
199 Deletes a chassis having the specified UUID.
200
201 :param uuid: The unique identifier of the chassis.
202 :return: A tuple with the server response and the response body.
203
204 """
205 return self._delete_request('chassis', uuid)
206
207 @base.handle_errors
208 def delete_port(self, uuid):
209 """
210 Deletes a port having the specified UUID.
211
212 :param uuid: The unique identifier of the port.
213 :return: A tuple with the server response and the response body.
214
215 """
216 return self._delete_request('ports', uuid)
217
218 @base.handle_errors
219 def update_node(self, uuid, **kwargs):
220 """
221 Update the specified node.
222
223 :param uuid: The unique identifier of the node.
224 :return: A tuple with the server response and the updated node.
225
226 """
227 node_attributes = ('properties/cpu_arch',
228 'properties/cpu_num',
229 'properties/storage',
230 'properties/memory',
Adam Gandelman00682612014-09-02 17:10:36 -0700231 'driver',
232 'instance_uuid')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300233
234 patch = self._make_patch(node_attributes, **kwargs)
235
236 return self._patch_request('nodes', uuid, patch)
237
238 @base.handle_errors
239 def update_chassis(self, uuid, **kwargs):
240 """
241 Update the specified chassis.
242
243 :param uuid: The unique identifier of the chassis.
244 :return: A tuple with the server response and the updated chassis.
245
246 """
247 chassis_attributes = ('description',)
248 patch = self._make_patch(chassis_attributes, **kwargs)
249
250 return self._patch_request('chassis', uuid, patch)
251
252 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400253 def update_port(self, uuid, patch):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300254 """
255 Update the specified port.
256
257 :param uuid: The unique identifier of the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400258 :param patch: List of dicts representing json patches.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300259 :return: A tuple with the server response and the updated port.
260
261 """
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300262
263 return self._patch_request('ports', uuid, patch)
Mh Raiesf8ecf232014-04-17 12:43:55 +0530264
265 @base.handle_errors
266 def set_node_power_state(self, node_uuid, state):
267 """
268 Set power state of the specified node.
269
270 :param node_uuid: The unique identifier of the node.
271 :state: desired state to set (on/off/reboot).
272
273 """
274 target = {'target': state}
275 return self._put_request('nodes/%s/states/power' % node_uuid,
276 target)
raiesmh08e5d84572014-06-23 09:49:03 +0530277
278 @base.handle_errors
279 def validate_driver_interface(self, node_uuid):
280 """
281 Get all driver interfaces of a specific node.
282
283 :param uuid: Unique identifier of the node in UUID format.
284
285 """
286
287 uri = '{pref}/{res}/{uuid}/{postf}'.format(pref=self.uri_prefix,
288 res='nodes',
289 uuid=node_uuid,
290 postf='validate')
291
292 return self._show_request('nodes', node_uuid, uri=uri)
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100293
294 @base.handle_errors
295 def set_node_boot_device(self, node_uuid, boot_device, persistent=False):
296 """
297 Set the boot device of the specified node.
298
299 :param node_uuid: The unique identifier of the node.
300 :param boot_device: The boot device name.
301 :param persistent: Boolean value. True if the boot device will
302 persist to all future boots, False if not.
303 Default: False.
304
305 """
306 request = {'boot_device': boot_device, 'persistent': persistent}
307 resp, body = self._put_request('nodes/%s/management/boot_device' %
308 node_uuid, request)
309 self.expected_success(204, resp.status)
310 return body
311
312 @base.handle_errors
313 def get_node_boot_device(self, node_uuid):
314 """
315 Get the current boot device of the specified node.
316
317 :param node_uuid: The unique identifier of the node.
318
319 """
320 path = 'nodes/%s/management/boot_device' % node_uuid
321 resp, body = self._list_request(path)
322 self.expected_success(200, resp.status)
323 return body
324
325 @base.handle_errors
326 def get_node_supported_boot_devices(self, node_uuid):
327 """
328 Get the supported boot devices of the specified node.
329
330 :param node_uuid: The unique identifier of the node.
331
332 """
333 path = 'nodes/%s/management/boot_device/supported' % node_uuid
334 resp, body = self._list_request(path)
335 self.expected_success(200, resp.status)
336 return body
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900337
338 @base.handle_errors
339 def get_console(self, node_uuid):
340 """
341 Get connection information about the console.
342
343 :param node_uuid: Unique identifier of the node in UUID format.
344
345 """
346
347 resp, body = self._show_request('nodes/states/console', node_uuid)
348 self.expected_success(200, resp.status)
349 return resp, body
350
351 @base.handle_errors
352 def set_console_mode(self, node_uuid, enabled):
353 """
354 Start and stop the node console.
355
356 :param node_uuid: Unique identifier of the node in UUID format.
357 :param enabled: Boolean value; whether to enable or disable the
358 console.
359
360 """
361
362 enabled = {'enabled': enabled}
363 resp, body = self._put_request('nodes/%s/states/console' % node_uuid,
364 enabled)
365 self.expected_success(202, resp.status)
366 return resp, body