blob: 91f2001b7b437fc4230cbc7bafe9085a0518db91 [file] [log] [blame]
Vladyslav Drok0cad0442016-12-14 12:48:20 +02001# 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 Goddard56399cc2018-02-16 13:37:25 +000014def get_node(client, node_id=None, instance_uuid=None, api_version=None):
Vladyslav Drok0cad0442016-12-14 12:48:20 +020015 """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 Goddard56399cc2018-02-16 13:37:25 +000022 :param api_version: Ironic API version to use.
Vladyslav Drok0cad0442016-12-14 12:48:20 +020023 :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 Goddard56399cc2018-02-16 13:37:25 +000029 _, body = client.show_node(node_id, api_version=api_version)
Vladyslav Drok0cad0442016-12-14 12:48:20 +020030 return body
31 elif instance_uuid:
Mark Goddard56399cc2018-02-16 13:37:25 +000032 _, body = client.show_node_by_instance_uuid(instance_uuid,
33 api_version=api_version)
Vladyslav Drok0cad0442016-12-14 12:48:20 +020034 if body['nodes']:
35 return body['nodes'][0]