Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [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 | from tempest.services.baremetal import base |
| 14 | |
| 15 | |
| 16 | class 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 Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 24 | def __init__(self, auth_provider): |
| 25 | super(BaremetalClientV1, self).__init__(auth_provider) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 26 | 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 |
| 40 | def list_ports(self): |
| 41 | """List all existing ports.""" |
| 42 | return self._list_request('ports') |
| 43 | |
| 44 | @base.handle_errors |
| 45 | def show_node(self, uuid): |
| 46 | """ |
| 47 | Gets a specific node. |
| 48 | |
| 49 | :param uuid: Unique identifier of the node in UUID format. |
| 50 | :return: Serialized node as a dictionary. |
| 51 | |
| 52 | """ |
| 53 | return self._show_request('nodes', uuid) |
| 54 | |
| 55 | @base.handle_errors |
| 56 | def show_chassis(self, uuid): |
| 57 | """ |
| 58 | Gets a specific chassis. |
| 59 | |
| 60 | :param uuid: Unique identifier of the chassis in UUID format. |
| 61 | :return: Serialized chassis as a dictionary. |
| 62 | |
| 63 | """ |
| 64 | return self._show_request('chassis', uuid) |
| 65 | |
| 66 | @base.handle_errors |
| 67 | def show_port(self, uuid): |
| 68 | """ |
| 69 | Gets a specific port. |
| 70 | |
| 71 | :param uuid: Unique identifier of the port in UUID format. |
| 72 | :return: Serialized port as a dictionary. |
| 73 | |
| 74 | """ |
| 75 | return self._show_request('ports', uuid) |
| 76 | |
| 77 | @base.handle_errors |
| 78 | def create_node(self, chassis_id, **kwargs): |
| 79 | """ |
| 80 | Create a baremetal node with the specified parameters. |
| 81 | |
| 82 | :param cpu_arch: CPU architecture of the node. Default: x86_64. |
| 83 | :param cpu_num: Number of CPUs. Default: 8. |
| 84 | :param storage: Disk size. Default: 1024. |
| 85 | :param memory: Available RAM. Default: 4096. |
| 86 | :param driver: Driver name. Default: "fake" |
| 87 | :return: A tuple with the server response and the created node. |
| 88 | |
| 89 | """ |
| 90 | node = {'chassis_uuid': chassis_id, |
| 91 | 'properties': {'cpu_arch': kwargs.get('cpu_arch', 'x86_64'), |
| 92 | 'cpu_num': kwargs.get('cpu_num', 8), |
| 93 | 'storage': kwargs.get('storage', 1024), |
| 94 | 'memory': kwargs.get('memory', 4096)}, |
| 95 | 'driver': kwargs.get('driver', 'fake')} |
| 96 | |
| 97 | return self._create_request('nodes', 'node', node) |
| 98 | |
| 99 | @base.handle_errors |
| 100 | def create_chassis(self, **kwargs): |
| 101 | """ |
| 102 | Create a chassis with the specified parameters. |
| 103 | |
| 104 | :param description: The description of the chassis. |
| 105 | Default: test-chassis |
| 106 | :return: A tuple with the server response and the created chassis. |
| 107 | |
| 108 | """ |
| 109 | chassis = {'description': kwargs.get('description', 'test-chassis')} |
| 110 | |
| 111 | return self._create_request('chassis', 'chassis', chassis) |
| 112 | |
| 113 | @base.handle_errors |
| 114 | def create_port(self, node_id, **kwargs): |
| 115 | """ |
| 116 | Create a port with the specified parameters. |
| 117 | |
| 118 | :param node_id: The ID of the node which owns the port. |
| 119 | :param address: MAC address of the port. Default: 01:23:45:67:89:0A. |
| 120 | :return: A tuple with the server response and the created port. |
| 121 | |
| 122 | """ |
| 123 | port = {'address': kwargs.get('address', '01:23:45:67:89:0A'), |
| 124 | 'node_uuid': node_id} |
| 125 | |
| 126 | return self._create_request('ports', 'port', port) |
| 127 | |
| 128 | @base.handle_errors |
| 129 | def delete_node(self, uuid): |
| 130 | """ |
| 131 | Deletes a node having the specified UUID. |
| 132 | |
| 133 | :param uuid: The unique identifier of the node. |
| 134 | :return: A tuple with the server response and the response body. |
| 135 | |
| 136 | """ |
| 137 | return self._delete_request('nodes', uuid) |
| 138 | |
| 139 | @base.handle_errors |
| 140 | def delete_chassis(self, uuid): |
| 141 | """ |
| 142 | Deletes a chassis having the specified UUID. |
| 143 | |
| 144 | :param uuid: The unique identifier of the chassis. |
| 145 | :return: A tuple with the server response and the response body. |
| 146 | |
| 147 | """ |
| 148 | return self._delete_request('chassis', uuid) |
| 149 | |
| 150 | @base.handle_errors |
| 151 | def delete_port(self, uuid): |
| 152 | """ |
| 153 | Deletes a port having the specified UUID. |
| 154 | |
| 155 | :param uuid: The unique identifier of the port. |
| 156 | :return: A tuple with the server response and the response body. |
| 157 | |
| 158 | """ |
| 159 | return self._delete_request('ports', uuid) |
| 160 | |
| 161 | @base.handle_errors |
| 162 | def update_node(self, uuid, **kwargs): |
| 163 | """ |
| 164 | Update the specified node. |
| 165 | |
| 166 | :param uuid: The unique identifier of the node. |
| 167 | :return: A tuple with the server response and the updated node. |
| 168 | |
| 169 | """ |
| 170 | node_attributes = ('properties/cpu_arch', |
| 171 | 'properties/cpu_num', |
| 172 | 'properties/storage', |
| 173 | 'properties/memory', |
| 174 | 'driver') |
| 175 | |
| 176 | patch = self._make_patch(node_attributes, **kwargs) |
| 177 | |
| 178 | return self._patch_request('nodes', uuid, patch) |
| 179 | |
| 180 | @base.handle_errors |
| 181 | def update_chassis(self, uuid, **kwargs): |
| 182 | """ |
| 183 | Update the specified chassis. |
| 184 | |
| 185 | :param uuid: The unique identifier of the chassis. |
| 186 | :return: A tuple with the server response and the updated chassis. |
| 187 | |
| 188 | """ |
| 189 | chassis_attributes = ('description',) |
| 190 | patch = self._make_patch(chassis_attributes, **kwargs) |
| 191 | |
| 192 | return self._patch_request('chassis', uuid, patch) |
| 193 | |
| 194 | @base.handle_errors |
| 195 | def update_port(self, uuid, **kwargs): |
| 196 | """ |
| 197 | Update the specified port. |
| 198 | |
| 199 | :param uuid: The unique identifier of the port. |
| 200 | :return: A tuple with the server response and the updated port. |
| 201 | |
| 202 | """ |
| 203 | port_attributes = ('address',) |
| 204 | patch = self._make_patch(port_attributes, **kwargs) |
| 205 | |
| 206 | return self._patch_request('ports', uuid, patch) |