blob: ede0d905f042a9e665c092e7f084c120b22132e9 [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
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000016class BaremetalClient(base.BaremetalClient):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000017 """Base Tempest REST client for Ironic API v1."""
Ken'ichi Ohmichi1f88ece2015-01-23 03:33:11 +000018 version = '1'
19 uri_prefix = 'v1'
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030020
21 @base.handle_errors
Adam Gandelman00682612014-09-02 17:10:36 -070022 def list_nodes(self, **kwargs):
Lv Fumei2edbc3c2016-07-08 14:36:25 +080023 """List all existing nodes.
24
25 Available params: see http://developer.openstack.org/api-ref/
26 baremetal/index.html#list-nodes
27 """
Adam Gandelman00682612014-09-02 17:10:36 -070028 return self._list_request('nodes', **kwargs)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030029
30 @base.handle_errors
31 def list_chassis(self):
32 """List all existing chassis."""
33 return self._list_request('chassis')
34
35 @base.handle_errors
Adam Gandelman00682612014-09-02 17:10:36 -070036 def list_chassis_nodes(self, chassis_uuid):
37 """List all nodes associated with a chassis."""
38 return self._list_request('/chassis/%s/nodes' % chassis_uuid)
39
40 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040041 def list_ports(self, **kwargs):
Lv Fumei2edbc3c2016-07-08 14:36:25 +080042 """List all existing ports.
43
44 Available params: see http://developer.openstack.org/api-ref/
45 baremetal/index.html?expanded=#list-ports
46 """
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):
Lv Fumei2edbc3c2016-07-08 14:36:25 +080061 """Details list all existing ports.
62
63 Available params: see http://developer.openstack.org/api-ref/baremetal/
64 index.html?expanded=#list-detailed-ports
65 """
Yuiko Takada3083fca2014-04-25 11:52:33 +000066 return self._list_request('/ports/detail', **kwargs)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030067
68 @base.handle_errors
Mh Raiesb71cb7f2014-03-28 10:51:31 +053069 def list_drivers(self):
70 """List all existing drivers."""
71 return self._list_request('drivers')
72
73 @base.handle_errors
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030074 def show_node(self, uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000075 """Gets a specific node.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030076
77 :param uuid: Unique identifier of the node in UUID format.
78 :return: Serialized node as a dictionary.
79
80 """
81 return self._show_request('nodes', uuid)
82
83 @base.handle_errors
Adam Gandelman00682612014-09-02 17:10:36 -070084 def show_node_by_instance_uuid(self, instance_uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000085 """Gets a node associated with given instance uuid.
Adam Gandelman00682612014-09-02 17:10:36 -070086
87 :param uuid: Unique identifier of the node in UUID format.
88 :return: Serialized node as a dictionary.
89
90 """
91 uri = '/nodes/detail?instance_uuid=%s' % instance_uuid
92
93 return self._show_request('nodes',
94 uuid=None,
95 uri=uri)
96
97 @base.handle_errors
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030098 def show_chassis(self, uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +000099 """Gets a specific chassis.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300100
101 :param uuid: Unique identifier of the chassis in UUID format.
102 :return: Serialized chassis as a dictionary.
103
104 """
105 return self._show_request('chassis', uuid)
106
107 @base.handle_errors
108 def show_port(self, uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000109 """Gets a specific port.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300110
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
Kan3fd5d892015-01-26 01:36:01 -0800117 @base.handle_errors
118 def show_port_by_address(self, address):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000119 """Gets a specific port by address.
Kan3fd5d892015-01-26 01:36:01 -0800120
121 :param address: MAC address of the port.
122 :return: Serialized port as a dictionary.
123
124 """
125 uri = '/ports/detail?address=%s' % address
126
127 return self._show_request('ports', uuid=None, uri=uri)
128
Yuiko Takada8e2dfca2014-04-24 18:10:52 +0000129 def show_driver(self, driver_name):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000130 """Gets a specific driver.
Yuiko Takada8e2dfca2014-04-24 18:10:52 +0000131
132 :param driver_name: Name of driver.
133 :return: Serialized driver as a dictionary.
134 """
135 return self._show_request('drivers', driver_name)
136
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300137 @base.handle_errors
Adam Gandelman118cd392015-03-09 14:41:36 -0700138 def create_node(self, chassis_id=None, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000139 """Create a baremetal node with the specified parameters.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300140
141 :param cpu_arch: CPU architecture of the node. Default: x86_64.
Adam Gandelman3ea1eb82015-02-18 19:13:25 -0800142 :param cpus: Number of CPUs. Default: 8.
143 :param local_gb: Disk size. Default: 1024.
144 :param memory_mb: Available RAM. Default: 4096.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300145 :param driver: Driver name. Default: "fake"
146 :return: A tuple with the server response and the created node.
147
148 """
149 node = {'chassis_uuid': chassis_id,
150 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'),
Adam Gandelman3ea1eb82015-02-18 19:13:25 -0800151 'cpus': kwargs.get('cpus', 8),
152 'local_gb': kwargs.get('local_gb', 1024),
153 'memory_mb': kwargs.get('memory_mb', 4096)},
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300154 'driver': kwargs.get('driver', 'fake')}
155
Ken'ichi Ohmichi19b6ff52015-01-23 02:45:50 +0000156 return self._create_request('nodes', node)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300157
158 @base.handle_errors
159 def create_chassis(self, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000160 """Create a chassis with the specified parameters.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300161
162 :param description: The description of the chassis.
163 Default: test-chassis
164 :return: A tuple with the server response and the created chassis.
165
166 """
167 chassis = {'description': kwargs.get('description', 'test-chassis')}
168
Ken'ichi Ohmichi19b6ff52015-01-23 02:45:50 +0000169 return self._create_request('chassis', chassis)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300170
171 @base.handle_errors
172 def create_port(self, node_id, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000173 """Create a port with the specified parameters.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300174
175 :param node_id: The ID of the node which owns the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400176 :param address: MAC address of the port.
177 :param extra: Meta data of the port. Default: {'foo': 'bar'}.
178 :param uuid: UUID of the port.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300179 :return: A tuple with the server response and the created port.
180
181 """
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400182 port = {'extra': kwargs.get('extra', {'foo': 'bar'}),
183 'uuid': kwargs['uuid']}
184
185 if node_id is not None:
186 port['node_uuid'] = node_id
187
188 if kwargs['address'] is not None:
189 port['address'] = kwargs['address']
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300190
Ken'ichi Ohmichi19b6ff52015-01-23 02:45:50 +0000191 return self._create_request('ports', port)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300192
193 @base.handle_errors
194 def delete_node(self, uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000195 """Deletes a node having the specified UUID.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300196
197 :param uuid: The unique identifier of the node.
198 :return: A tuple with the server response and the response body.
199
200 """
201 return self._delete_request('nodes', uuid)
202
203 @base.handle_errors
204 def delete_chassis(self, uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000205 """Deletes a chassis having the specified UUID.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300206
207 :param uuid: The unique identifier of the chassis.
208 :return: A tuple with the server response and the response body.
209
210 """
211 return self._delete_request('chassis', uuid)
212
213 @base.handle_errors
214 def delete_port(self, uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000215 """Deletes a port having the specified UUID.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300216
217 :param uuid: The unique identifier of the port.
218 :return: A tuple with the server response and the response body.
219
220 """
221 return self._delete_request('ports', uuid)
222
223 @base.handle_errors
224 def update_node(self, uuid, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000225 """Update the specified node.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300226
227 :param uuid: The unique identifier of the node.
228 :return: A tuple with the server response and the updated node.
229
230 """
231 node_attributes = ('properties/cpu_arch',
Adam Gandelman3ea1eb82015-02-18 19:13:25 -0800232 'properties/cpus',
233 'properties/local_gb',
234 'properties/memory_mb',
Adam Gandelman00682612014-09-02 17:10:36 -0700235 'driver',
236 'instance_uuid')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300237
238 patch = self._make_patch(node_attributes, **kwargs)
239
240 return self._patch_request('nodes', uuid, patch)
241
242 @base.handle_errors
243 def update_chassis(self, uuid, **kwargs):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000244 """Update the specified chassis.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300245
246 :param uuid: The unique identifier of the chassis.
247 :return: A tuple with the server response and the updated chassis.
248
249 """
250 chassis_attributes = ('description',)
251 patch = self._make_patch(chassis_attributes, **kwargs)
252
253 return self._patch_request('chassis', uuid, patch)
254
255 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400256 def update_port(self, uuid, patch):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000257 """Update the specified port.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300258
259 :param uuid: The unique identifier of the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400260 :param patch: List of dicts representing json patches.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300261 :return: A tuple with the server response and the updated port.
262
263 """
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300264
265 return self._patch_request('ports', uuid, patch)
Mh Raiesf8ecf232014-04-17 12:43:55 +0530266
267 @base.handle_errors
268 def set_node_power_state(self, node_uuid, state):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000269 """Set power state of the specified node.
Mh Raiesf8ecf232014-04-17 12:43:55 +0530270
271 :param node_uuid: The unique identifier of the node.
272 :state: desired state to set (on/off/reboot).
273
274 """
275 target = {'target': state}
276 return self._put_request('nodes/%s/states/power' % node_uuid,
277 target)
raiesmh08e5d84572014-06-23 09:49:03 +0530278
279 @base.handle_errors
280 def validate_driver_interface(self, node_uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000281 """Get all driver interfaces of a specific node.
raiesmh08e5d84572014-06-23 09:49:03 +0530282
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):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000296 """Set the boot device of the specified node.
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100297
298 :param node_uuid: The unique identifier of the node.
299 :param boot_device: The boot device name.
300 :param persistent: Boolean value. True if the boot device will
301 persist to all future boots, False if not.
302 Default: False.
303
304 """
305 request = {'boot_device': boot_device, 'persistent': persistent}
306 resp, body = self._put_request('nodes/%s/management/boot_device' %
307 node_uuid, request)
308 self.expected_success(204, resp.status)
309 return body
310
311 @base.handle_errors
312 def get_node_boot_device(self, node_uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000313 """Get the current boot device of the specified node.
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100314
315 :param node_uuid: The unique identifier of the node.
316
317 """
318 path = 'nodes/%s/management/boot_device' % node_uuid
319 resp, body = self._list_request(path)
320 self.expected_success(200, resp.status)
321 return body
322
323 @base.handle_errors
324 def get_node_supported_boot_devices(self, node_uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000325 """Get the supported boot devices of the specified node.
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100326
327 :param node_uuid: The unique identifier of the node.
328
329 """
330 path = 'nodes/%s/management/boot_device/supported' % node_uuid
331 resp, body = self._list_request(path)
332 self.expected_success(200, resp.status)
333 return body
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900334
335 @base.handle_errors
336 def get_console(self, node_uuid):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000337 """Get connection information about the console.
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900338
339 :param node_uuid: Unique identifier of the node in UUID format.
340
341 """
342
343 resp, body = self._show_request('nodes/states/console', node_uuid)
344 self.expected_success(200, resp.status)
345 return resp, body
346
347 @base.handle_errors
348 def set_console_mode(self, node_uuid, enabled):
Ken'ichi Ohmichib2790842015-11-17 11:46:13 +0000349 """Start and stop the node console.
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900350
351 :param node_uuid: Unique identifier of the node in UUID format.
352 :param enabled: Boolean value; whether to enable or disable the
353 console.
354
355 """
356
357 enabled = {'enabled': enabled}
358 resp, body = self._put_request('nodes/%s/states/console' % node_uuid,
359 enabled)
360 self.expected_success(202, resp.status)
361 return resp, body