Vladyslav Drok | 0cad044 | 2016-12-14 12:48:20 +0200 | [diff] [blame] | 1 | # 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 | |
| 13 | |
Mark Goddard | 56399cc | 2018-02-16 13:37:25 +0000 | [diff] [blame] | 14 | def get_node(client, node_id=None, instance_uuid=None, api_version=None): |
Vladyslav Drok | 0cad044 | 2016-12-14 12:48:20 +0200 | [diff] [blame] | 15 | """Get a node by its identifier or instance UUID. |
| 16 | |
| 17 | If both node_id and instance_uuid specified, node_id will be used. |
| 18 | |
| 19 | :param client: an instance of tempest plugin BaremetalClient. |
| 20 | :param node_id: identifier (UUID or name) of the node. |
| 21 | :param instance_uuid: UUID of the instance. |
Mark Goddard | 56399cc | 2018-02-16 13:37:25 +0000 | [diff] [blame] | 22 | :param api_version: Ironic API version to use. |
Vladyslav Drok | 0cad044 | 2016-12-14 12:48:20 +0200 | [diff] [blame] | 23 | :returns: the requested node. |
| 24 | :raises: AssertionError, if neither node_id nor instance_uuid was provided |
| 25 | """ |
| 26 | assert node_id or instance_uuid, ('Either node or instance identifier ' |
| 27 | 'has to be provided.') |
| 28 | if node_id: |
Mark Goddard | 56399cc | 2018-02-16 13:37:25 +0000 | [diff] [blame] | 29 | _, body = client.show_node(node_id, api_version=api_version) |
Vladyslav Drok | 0cad044 | 2016-12-14 12:48:20 +0200 | [diff] [blame] | 30 | return body |
| 31 | elif instance_uuid: |
Mark Goddard | 56399cc | 2018-02-16 13:37:25 +0000 | [diff] [blame] | 32 | _, body = client.show_node_by_instance_uuid(instance_uuid, |
| 33 | api_version=api_version) |
Vladyslav Drok | 0cad044 | 2016-12-14 12:48:20 +0200 | [diff] [blame] | 34 | if body['nodes']: |
| 35 | return body['nodes'][0] |