blob: 67c4922fca88284dd7d7f485f08c18c6ff8ac923 [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
14def get_node(client, node_id=None, instance_uuid=None):
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.
22 :returns: the requested node.
23 :raises: AssertionError, if neither node_id nor instance_uuid was provided
24 """
25 assert node_id or instance_uuid, ('Either node or instance identifier '
26 'has to be provided.')
27 if node_id:
28 _, body = client.show_node(node_id)
29 return body
30 elif instance_uuid:
31 _, body = client.show_node_by_instance_uuid(instance_uuid)
32 if body['nodes']:
33 return body['nodes'][0]