blob: ec531a197c4559f4c4592ba702262814488329f3 [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
30 def list_nodes(self):
31 """List all existing nodes."""
32 return self._list_request('nodes')
33
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
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040040 def list_ports(self, **kwargs):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030041 """List all existing ports."""
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040042 return self._list_request('ports', **kwargs)
43
44 @base.handle_errors
45 def list_ports_detail(self):
46 """Details list all existing ports."""
47 return self._list_request('/ports/detail')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030048
49 @base.handle_errors
50 def show_node(self, uuid):
51 """
52 Gets a specific node.
53
54 :param uuid: Unique identifier of the node in UUID format.
55 :return: Serialized node as a dictionary.
56
57 """
58 return self._show_request('nodes', uuid)
59
60 @base.handle_errors
61 def show_chassis(self, uuid):
62 """
63 Gets a specific chassis.
64
65 :param uuid: Unique identifier of the chassis in UUID format.
66 :return: Serialized chassis as a dictionary.
67
68 """
69 return self._show_request('chassis', uuid)
70
71 @base.handle_errors
72 def show_port(self, uuid):
73 """
74 Gets a specific port.
75
76 :param uuid: Unique identifier of the port in UUID format.
77 :return: Serialized port as a dictionary.
78
79 """
80 return self._show_request('ports', uuid)
81
82 @base.handle_errors
83 def create_node(self, chassis_id, **kwargs):
84 """
85 Create a baremetal node with the specified parameters.
86
87 :param cpu_arch: CPU architecture of the node. Default: x86_64.
88 :param cpu_num: Number of CPUs. Default: 8.
89 :param storage: Disk size. Default: 1024.
90 :param memory: Available RAM. Default: 4096.
91 :param driver: Driver name. Default: "fake"
92 :return: A tuple with the server response and the created node.
93
94 """
95 node = {'chassis_uuid': chassis_id,
96 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'),
97 'cpu_num': kwargs.get('cpu_num', 8),
98 'storage': kwargs.get('storage', 1024),
99 'memory': kwargs.get('memory', 4096)},
100 'driver': kwargs.get('driver', 'fake')}
101
102 return self._create_request('nodes', 'node', node)
103
104 @base.handle_errors
105 def create_chassis(self, **kwargs):
106 """
107 Create a chassis with the specified parameters.
108
109 :param description: The description of the chassis.
110 Default: test-chassis
111 :return: A tuple with the server response and the created chassis.
112
113 """
114 chassis = {'description': kwargs.get('description', 'test-chassis')}
115
116 return self._create_request('chassis', 'chassis', chassis)
117
118 @base.handle_errors
119 def create_port(self, node_id, **kwargs):
120 """
121 Create a port with the specified parameters.
122
123 :param node_id: The ID of the node which owns the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400124 :param address: MAC address of the port.
125 :param extra: Meta data of the port. Default: {'foo': 'bar'}.
126 :param uuid: UUID of the port.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300127 :return: A tuple with the server response and the created port.
128
129 """
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400130 port = {'extra': kwargs.get('extra', {'foo': 'bar'}),
131 'uuid': kwargs['uuid']}
132
133 if node_id is not None:
134 port['node_uuid'] = node_id
135
136 if kwargs['address'] is not None:
137 port['address'] = kwargs['address']
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300138
139 return self._create_request('ports', 'port', port)
140
141 @base.handle_errors
142 def delete_node(self, uuid):
143 """
144 Deletes a node having the specified UUID.
145
146 :param uuid: The unique identifier of the node.
147 :return: A tuple with the server response and the response body.
148
149 """
150 return self._delete_request('nodes', uuid)
151
152 @base.handle_errors
153 def delete_chassis(self, uuid):
154 """
155 Deletes a chassis having the specified UUID.
156
157 :param uuid: The unique identifier of the chassis.
158 :return: A tuple with the server response and the response body.
159
160 """
161 return self._delete_request('chassis', uuid)
162
163 @base.handle_errors
164 def delete_port(self, uuid):
165 """
166 Deletes a port having the specified UUID.
167
168 :param uuid: The unique identifier of the port.
169 :return: A tuple with the server response and the response body.
170
171 """
172 return self._delete_request('ports', uuid)
173
174 @base.handle_errors
175 def update_node(self, uuid, **kwargs):
176 """
177 Update the specified node.
178
179 :param uuid: The unique identifier of the node.
180 :return: A tuple with the server response and the updated node.
181
182 """
183 node_attributes = ('properties/cpu_arch',
184 'properties/cpu_num',
185 'properties/storage',
186 'properties/memory',
187 'driver')
188
189 patch = self._make_patch(node_attributes, **kwargs)
190
191 return self._patch_request('nodes', uuid, patch)
192
193 @base.handle_errors
194 def update_chassis(self, uuid, **kwargs):
195 """
196 Update the specified chassis.
197
198 :param uuid: The unique identifier of the chassis.
199 :return: A tuple with the server response and the updated chassis.
200
201 """
202 chassis_attributes = ('description',)
203 patch = self._make_patch(chassis_attributes, **kwargs)
204
205 return self._patch_request('chassis', uuid, patch)
206
207 @base.handle_errors
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400208 def update_port(self, uuid, patch):
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300209 """
210 Update the specified port.
211
212 :param uuid: The unique identifier of the port.
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400213 :param patch: List of dicts representing json patches.
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300214 :return: A tuple with the server response and the updated port.
215
216 """
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300217
218 return self._patch_request('ports', uuid, patch)