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