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