Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
| 2 | # Copyright 2013 Hewlett-Packard Development Company, L.P. |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
| 17 | import copy |
| 18 | |
| 19 | from oslo_serialization import jsonutils as json |
| 20 | from six.moves.urllib import parse as urllib |
| 21 | |
| 22 | from tempest.lib.api_schema.response.compute.v2_1 import servers as schema |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 23 | from tempest.lib.api_schema.response.compute.v2_19 import servers as schemav219 |
| 24 | from tempest.lib.api_schema.response.compute.v2_9 import servers as schemav29 |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 25 | from tempest.lib.common import rest_client |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 26 | from tempest.lib.services.compute import base_compute_client |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 27 | |
| 28 | |
Ghanshyam | ee9af30 | 2016-02-25 06:12:43 +0900 | [diff] [blame] | 29 | class ServersClient(base_compute_client.BaseComputeClient): |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 30 | schema_versions_info = [ |
| 31 | {'min': None, 'max': '2.8', 'schema': schema}, |
| 32 | {'min': '2.9', 'max': '2.18', 'schema': schemav29}, |
| 33 | {'min': '2.19', 'max': None, 'schema': schemav219}] |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 34 | |
| 35 | def __init__(self, auth_provider, service, region, |
| 36 | enable_instance_password=True, **kwargs): |
| 37 | super(ServersClient, self).__init__( |
| 38 | auth_provider, service, region, **kwargs) |
| 39 | self.enable_instance_password = enable_instance_password |
| 40 | |
| 41 | def create_server(self, **kwargs): |
| 42 | """Create server. |
| 43 | |
| 44 | Available params: see http://developer.openstack.org/ |
| 45 | api-ref-compute-v2.1.html#createServer |
| 46 | |
| 47 | Most parameters except the following are passed to the API without |
| 48 | any changes. |
| 49 | :param disk_config: The name is changed to OS-DCF:diskConfig |
| 50 | :param scheduler_hints: The name is changed to os:scheduler_hints and |
| 51 | the parameter is set in the same level as the parameter 'server'. |
| 52 | """ |
| 53 | body = copy.deepcopy(kwargs) |
| 54 | if body.get('disk_config'): |
| 55 | body['OS-DCF:diskConfig'] = body.pop('disk_config') |
| 56 | |
| 57 | hints = None |
| 58 | if body.get('scheduler_hints'): |
| 59 | hints = {'os:scheduler_hints': body.pop('scheduler_hints')} |
| 60 | |
| 61 | post_body = {'server': body} |
| 62 | |
| 63 | if hints: |
Jordan Pittier | 81c427d | 2016-04-25 17:02:58 +0200 | [diff] [blame] | 64 | post_body.update(hints) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 65 | |
| 66 | post_body = json.dumps(post_body) |
| 67 | resp, body = self.post('servers', post_body) |
| 68 | |
| 69 | body = json.loads(body) |
| 70 | # NOTE(maurosr): this deals with the case of multiple server create |
| 71 | # with return reservation id set True |
| 72 | if 'reservation_id' in body: |
| 73 | return rest_client.ResponseBody(resp, body) |
| 74 | if self.enable_instance_password: |
| 75 | create_schema = schema.create_server_with_admin_pass |
| 76 | else: |
| 77 | create_schema = schema.create_server |
| 78 | self.validate_response(create_schema, resp, body) |
| 79 | return rest_client.ResponseBody(resp, body) |
| 80 | |
| 81 | def update_server(self, server_id, **kwargs): |
| 82 | """Update server. |
| 83 | |
| 84 | Available params: see http://developer.openstack.org/ |
| 85 | api-ref-compute-v2.1.html#updateServer |
| 86 | |
| 87 | Most parameters except the following are passed to the API without |
| 88 | any changes. |
| 89 | :param disk_config: The name is changed to OS-DCF:diskConfig |
| 90 | """ |
| 91 | if kwargs.get('disk_config'): |
| 92 | kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config') |
| 93 | |
| 94 | post_body = json.dumps({'server': kwargs}) |
| 95 | resp, body = self.put("servers/%s" % server_id, post_body) |
| 96 | body = json.loads(body) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 97 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 98 | self.validate_response(schema.update_server, resp, body) |
| 99 | return rest_client.ResponseBody(resp, body) |
| 100 | |
| 101 | def show_server(self, server_id): |
| 102 | """Get server details.""" |
| 103 | resp, body = self.get("servers/%s" % server_id) |
| 104 | body = json.loads(body) |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 105 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 106 | self.validate_response(schema.get_server, resp, body) |
| 107 | return rest_client.ResponseBody(resp, body) |
| 108 | |
| 109 | def delete_server(self, server_id): |
| 110 | """Delete server.""" |
| 111 | resp, body = self.delete("servers/%s" % server_id) |
| 112 | self.validate_response(schema.delete_server, resp, body) |
| 113 | return rest_client.ResponseBody(resp, body) |
| 114 | |
| 115 | def list_servers(self, detail=False, **params): |
| 116 | """List servers. |
| 117 | |
| 118 | Available params: see http://developer.openstack.org/ |
| 119 | api-ref-compute-v2.1.html#listServers |
| 120 | and http://developer.openstack.org/ |
| 121 | api-ref-compute-v2.1.html#listDetailServers |
| 122 | """ |
| 123 | |
| 124 | url = 'servers' |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 125 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 126 | _schema = schema.list_servers |
| 127 | |
| 128 | if detail: |
| 129 | url += '/detail' |
| 130 | _schema = schema.list_servers_detail |
| 131 | if params: |
| 132 | url += '?%s' % urllib.urlencode(params) |
| 133 | |
| 134 | resp, body = self.get(url) |
| 135 | body = json.loads(body) |
| 136 | self.validate_response(_schema, resp, body) |
| 137 | return rest_client.ResponseBody(resp, body) |
| 138 | |
| 139 | def list_addresses(self, server_id): |
| 140 | """Lists all addresses for a server.""" |
| 141 | resp, body = self.get("servers/%s/ips" % server_id) |
| 142 | body = json.loads(body) |
| 143 | self.validate_response(schema.list_addresses, resp, body) |
| 144 | return rest_client.ResponseBody(resp, body) |
| 145 | |
| 146 | def list_addresses_by_network(self, server_id, network_id): |
| 147 | """Lists all addresses of a specific network type for a server.""" |
| 148 | resp, body = self.get("servers/%s/ips/%s" % |
| 149 | (server_id, network_id)) |
| 150 | body = json.loads(body) |
| 151 | self.validate_response(schema.list_addresses_by_network, resp, body) |
| 152 | return rest_client.ResponseBody(resp, body) |
| 153 | |
| 154 | def action(self, server_id, action_name, |
| 155 | schema=schema.server_actions_common_schema, |
| 156 | **kwargs): |
| 157 | post_body = json.dumps({action_name: kwargs}) |
| 158 | resp, body = self.post('servers/%s/action' % server_id, |
| 159 | post_body) |
| 160 | if body: |
| 161 | body = json.loads(body) |
| 162 | self.validate_response(schema, resp, body) |
| 163 | return rest_client.ResponseBody(resp, body) |
| 164 | |
| 165 | def create_backup(self, server_id, **kwargs): |
| 166 | """Backup a server instance. |
| 167 | |
| 168 | Available params: see http://developer.openstack.org/ |
| 169 | api-ref-compute-v2.1.html#createBackup |
| 170 | """ |
| 171 | return self.action(server_id, "createBackup", **kwargs) |
| 172 | |
| 173 | def change_password(self, server_id, **kwargs): |
| 174 | """Change the root password for the server. |
| 175 | |
| 176 | Available params: see http://developer.openstack.org/ |
| 177 | api-ref-compute-v2.1.html#changePassword |
| 178 | """ |
| 179 | return self.action(server_id, 'changePassword', **kwargs) |
| 180 | |
| 181 | def show_password(self, server_id): |
| 182 | resp, body = self.get("servers/%s/os-server-password" % |
| 183 | server_id) |
| 184 | body = json.loads(body) |
| 185 | self.validate_response(schema.show_password, resp, body) |
| 186 | return rest_client.ResponseBody(resp, body) |
| 187 | |
| 188 | def delete_password(self, server_id): |
| 189 | """Removes the encrypted server password from the metadata server |
| 190 | |
| 191 | Note that this does not actually change the instance server |
| 192 | password. |
| 193 | """ |
| 194 | resp, body = self.delete("servers/%s/os-server-password" % |
| 195 | server_id) |
| 196 | self.validate_response(schema.server_actions_delete_password, |
| 197 | resp, body) |
| 198 | return rest_client.ResponseBody(resp, body) |
| 199 | |
| 200 | def reboot_server(self, server_id, **kwargs): |
| 201 | """Reboot a server. |
| 202 | |
| 203 | Available params: http://developer.openstack.org/ |
| 204 | api-ref-compute-v2.1.html#reboot |
| 205 | """ |
| 206 | return self.action(server_id, 'reboot', **kwargs) |
| 207 | |
| 208 | def rebuild_server(self, server_id, image_ref, **kwargs): |
| 209 | """Rebuild a server with a new image. |
| 210 | |
| 211 | Available params: http://developer.openstack.org/ |
| 212 | api-ref-compute-v2.1.html#rebuild |
| 213 | |
| 214 | Most parameters except the following are passed to the API without |
| 215 | any changes. |
| 216 | :param disk_config: The name is changed to OS-DCF:diskConfig |
| 217 | """ |
| 218 | kwargs['imageRef'] = image_ref |
| 219 | if 'disk_config' in kwargs: |
| 220 | kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config') |
lanoux | 2746ba0 | 2016-03-16 17:41:01 +0900 | [diff] [blame] | 221 | schema = self.get_schema(self.schema_versions_info) |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 222 | if self.enable_instance_password: |
| 223 | rebuild_schema = schema.rebuild_server_with_admin_pass |
| 224 | else: |
| 225 | rebuild_schema = schema.rebuild_server |
| 226 | return self.action(server_id, 'rebuild', |
| 227 | rebuild_schema, **kwargs) |
| 228 | |
| 229 | def resize_server(self, server_id, flavor_ref, **kwargs): |
| 230 | """Change the flavor of a server. |
| 231 | |
| 232 | Available params: http://developer.openstack.org/ |
| 233 | api-ref-compute-v2.1.html#resize |
| 234 | |
| 235 | Most parameters except the following are passed to the API without |
| 236 | any changes. |
| 237 | :param disk_config: The name is changed to OS-DCF:diskConfig |
| 238 | """ |
| 239 | kwargs['flavorRef'] = flavor_ref |
| 240 | if 'disk_config' in kwargs: |
| 241 | kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config') |
| 242 | return self.action(server_id, 'resize', **kwargs) |
| 243 | |
| 244 | def confirm_resize_server(self, server_id, **kwargs): |
| 245 | """Confirm the flavor change for a server. |
| 246 | |
| 247 | Available params: see http://developer.openstack.org/ |
| 248 | api-ref-compute-v2.1.html#confirmResize |
| 249 | """ |
| 250 | return self.action(server_id, 'confirmResize', |
| 251 | schema.server_actions_confirm_resize, |
| 252 | **kwargs) |
| 253 | |
| 254 | def revert_resize_server(self, server_id, **kwargs): |
| 255 | """Revert a server back to its original flavor. |
| 256 | |
| 257 | Available params: see http://developer.openstack.org/ |
| 258 | api-ref-compute-v2.1.html#revertResize |
| 259 | """ |
| 260 | return self.action(server_id, 'revertResize', **kwargs) |
| 261 | |
| 262 | def list_server_metadata(self, server_id): |
| 263 | resp, body = self.get("servers/%s/metadata" % server_id) |
| 264 | body = json.loads(body) |
| 265 | self.validate_response(schema.list_server_metadata, resp, body) |
| 266 | return rest_client.ResponseBody(resp, body) |
| 267 | |
| 268 | def set_server_metadata(self, server_id, meta, no_metadata_field=False): |
| 269 | if no_metadata_field: |
| 270 | post_body = "" |
| 271 | else: |
| 272 | post_body = json.dumps({'metadata': meta}) |
| 273 | resp, body = self.put('servers/%s/metadata' % server_id, |
| 274 | post_body) |
| 275 | body = json.loads(body) |
| 276 | self.validate_response(schema.set_server_metadata, resp, body) |
| 277 | return rest_client.ResponseBody(resp, body) |
| 278 | |
| 279 | def update_server_metadata(self, server_id, meta): |
| 280 | post_body = json.dumps({'metadata': meta}) |
| 281 | resp, body = self.post('servers/%s/metadata' % server_id, |
| 282 | post_body) |
| 283 | body = json.loads(body) |
| 284 | self.validate_response(schema.update_server_metadata, |
| 285 | resp, body) |
| 286 | return rest_client.ResponseBody(resp, body) |
| 287 | |
| 288 | def show_server_metadata_item(self, server_id, key): |
| 289 | resp, body = self.get("servers/%s/metadata/%s" % (server_id, key)) |
| 290 | body = json.loads(body) |
| 291 | self.validate_response(schema.set_show_server_metadata_item, |
| 292 | resp, body) |
| 293 | return rest_client.ResponseBody(resp, body) |
| 294 | |
| 295 | def set_server_metadata_item(self, server_id, key, meta): |
| 296 | post_body = json.dumps({'meta': meta}) |
| 297 | resp, body = self.put('servers/%s/metadata/%s' % (server_id, key), |
| 298 | post_body) |
| 299 | body = json.loads(body) |
| 300 | self.validate_response(schema.set_show_server_metadata_item, |
| 301 | resp, body) |
| 302 | return rest_client.ResponseBody(resp, body) |
| 303 | |
| 304 | def delete_server_metadata_item(self, server_id, key): |
| 305 | resp, body = self.delete("servers/%s/metadata/%s" % |
| 306 | (server_id, key)) |
| 307 | self.validate_response(schema.delete_server_metadata_item, |
| 308 | resp, body) |
| 309 | return rest_client.ResponseBody(resp, body) |
| 310 | |
| 311 | def stop_server(self, server_id, **kwargs): |
| 312 | return self.action(server_id, 'os-stop', **kwargs) |
| 313 | |
| 314 | def start_server(self, server_id, **kwargs): |
| 315 | return self.action(server_id, 'os-start', **kwargs) |
| 316 | |
| 317 | def attach_volume(self, server_id, **kwargs): |
zhufl | ff6d0da | 2016-06-12 17:27:12 +0800 | [diff] [blame] | 318 | """Attaches a volume to a server instance. |
| 319 | |
| 320 | Available params: see http://developer.openstack.org/ |
| 321 | api-ref-compute-v2.1.html#attachVolume |
| 322 | """ |
Matthew Treinish | 9e26ca8 | 2016-02-23 11:43:20 -0500 | [diff] [blame] | 323 | post_body = json.dumps({'volumeAttachment': kwargs}) |
| 324 | resp, body = self.post('servers/%s/os-volume_attachments' % server_id, |
| 325 | post_body) |
| 326 | body = json.loads(body) |
| 327 | self.validate_response(schema.attach_volume, resp, body) |
| 328 | return rest_client.ResponseBody(resp, body) |
| 329 | |
| 330 | def update_attached_volume(self, server_id, attachment_id, **kwargs): |
| 331 | """Swaps a volume attached to an instance for another volume""" |
| 332 | post_body = json.dumps({'volumeAttachment': kwargs}) |
| 333 | resp, body = self.put('servers/%s/os-volume_attachments/%s' % |
| 334 | (server_id, attachment_id), |
| 335 | post_body) |
| 336 | self.validate_response(schema.update_attached_volume, resp, body) |
| 337 | return rest_client.ResponseBody(resp, body) |
| 338 | |
| 339 | def detach_volume(self, server_id, volume_id): # noqa |
| 340 | """Detaches a volume from a server instance.""" |
| 341 | resp, body = self.delete('servers/%s/os-volume_attachments/%s' % |
| 342 | (server_id, volume_id)) |
| 343 | self.validate_response(schema.detach_volume, resp, body) |
| 344 | return rest_client.ResponseBody(resp, body) |
| 345 | |
| 346 | def show_volume_attachment(self, server_id, volume_id): |
| 347 | """Return details about the given volume attachment.""" |
| 348 | resp, body = self.get('servers/%s/os-volume_attachments/%s' % ( |
| 349 | server_id, volume_id)) |
| 350 | body = json.loads(body) |
| 351 | self.validate_response(schema.show_volume_attachment, resp, body) |
| 352 | return rest_client.ResponseBody(resp, body) |
| 353 | |
| 354 | def list_volume_attachments(self, server_id): |
| 355 | """Returns the list of volume attachments for a given instance.""" |
| 356 | resp, body = self.get('servers/%s/os-volume_attachments' % ( |
| 357 | server_id)) |
| 358 | body = json.loads(body) |
| 359 | self.validate_response(schema.list_volume_attachments, resp, body) |
| 360 | return rest_client.ResponseBody(resp, body) |
| 361 | |
| 362 | def add_security_group(self, server_id, **kwargs): |
| 363 | """Add a security group to the server. |
| 364 | |
| 365 | Available params: TODO |
| 366 | """ |
| 367 | # TODO(oomichi): The api-site doesn't contain this API description. |
| 368 | # So the above should be changed to the api-site link after |
| 369 | # adding the description on the api-site. |
| 370 | # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524199 |
| 371 | return self.action(server_id, 'addSecurityGroup', **kwargs) |
| 372 | |
| 373 | def remove_security_group(self, server_id, **kwargs): |
| 374 | """Remove a security group from the server. |
| 375 | |
| 376 | Available params: TODO |
| 377 | """ |
| 378 | # TODO(oomichi): The api-site doesn't contain this API description. |
| 379 | # So the above should be changed to the api-site link after |
| 380 | # adding the description on the api-site. |
| 381 | # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524199 |
| 382 | return self.action(server_id, 'removeSecurityGroup', **kwargs) |
| 383 | |
| 384 | def live_migrate_server(self, server_id, **kwargs): |
| 385 | """This should be called with administrator privileges. |
| 386 | |
| 387 | Available params: http://developer.openstack.org/ |
| 388 | api-ref-compute-v2.1.html#migrateLive |
| 389 | """ |
| 390 | return self.action(server_id, 'os-migrateLive', **kwargs) |
| 391 | |
| 392 | def migrate_server(self, server_id, **kwargs): |
| 393 | """Migrate a server to a new host. |
| 394 | |
| 395 | Available params: http://developer.openstack.org/ |
| 396 | api-ref-compute-v2.1.html#migrate |
| 397 | """ |
| 398 | return self.action(server_id, 'migrate', **kwargs) |
| 399 | |
| 400 | def lock_server(self, server_id, **kwargs): |
| 401 | """Lock the given server. |
| 402 | |
| 403 | Available params: http://developer.openstack.org/ |
| 404 | api-ref-compute-v2.1.html#lock |
| 405 | """ |
| 406 | return self.action(server_id, 'lock', **kwargs) |
| 407 | |
| 408 | def unlock_server(self, server_id, **kwargs): |
| 409 | """UNlock the given server. |
| 410 | |
| 411 | Available params: http://developer.openstack.org/ |
| 412 | api-ref-compute-v2.1.html#unlock |
| 413 | """ |
| 414 | return self.action(server_id, 'unlock', **kwargs) |
| 415 | |
| 416 | def suspend_server(self, server_id, **kwargs): |
| 417 | """Suspend the provided server. |
| 418 | |
| 419 | Available params: http://developer.openstack.org/ |
| 420 | api-ref-compute-v2.1.html#suspend |
| 421 | """ |
| 422 | return self.action(server_id, 'suspend', **kwargs) |
| 423 | |
| 424 | def resume_server(self, server_id, **kwargs): |
| 425 | """Un-suspend the provided server. |
| 426 | |
| 427 | Available params: http://developer.openstack.org/ |
| 428 | api-ref-compute-v2.1.html#resume |
| 429 | """ |
| 430 | return self.action(server_id, 'resume', **kwargs) |
| 431 | |
| 432 | def pause_server(self, server_id, **kwargs): |
| 433 | """Pause the provided server. |
| 434 | |
| 435 | Available params: http://developer.openstack.org/ |
| 436 | api-ref-compute-v2.1.html#pause |
| 437 | """ |
| 438 | return self.action(server_id, 'pause', **kwargs) |
| 439 | |
| 440 | def unpause_server(self, server_id, **kwargs): |
| 441 | """Un-pause the provided server. |
| 442 | |
| 443 | Available params: http://developer.openstack.org/ |
| 444 | api-ref-compute-v2.1.html#unpause |
| 445 | """ |
| 446 | return self.action(server_id, 'unpause', **kwargs) |
| 447 | |
| 448 | def reset_state(self, server_id, **kwargs): |
| 449 | """Reset the state of a server to active/error. |
| 450 | |
| 451 | Available params: http://developer.openstack.org/ |
| 452 | api-ref-compute-v2.1.html#resetState |
| 453 | """ |
| 454 | return self.action(server_id, 'os-resetState', **kwargs) |
| 455 | |
| 456 | def shelve_server(self, server_id, **kwargs): |
| 457 | """Shelve the provided server. |
| 458 | |
| 459 | Available params: http://developer.openstack.org/ |
| 460 | api-ref-compute-v2.1.html#shelve |
| 461 | """ |
| 462 | return self.action(server_id, 'shelve', **kwargs) |
| 463 | |
| 464 | def unshelve_server(self, server_id, **kwargs): |
| 465 | """Un-shelve the provided server. |
| 466 | |
| 467 | Available params: http://developer.openstack.org/ |
| 468 | api-ref-compute-v2.1.html#unshelve |
| 469 | """ |
| 470 | return self.action(server_id, 'unshelve', **kwargs) |
| 471 | |
| 472 | def shelve_offload_server(self, server_id, **kwargs): |
| 473 | """Shelve-offload the provided server. |
| 474 | |
| 475 | Available params: http://developer.openstack.org/ |
| 476 | api-ref-compute-v2.1.html#shelveOffload |
| 477 | """ |
| 478 | return self.action(server_id, 'shelveOffload', **kwargs) |
| 479 | |
| 480 | def get_console_output(self, server_id, **kwargs): |
| 481 | """Get console output. |
| 482 | |
| 483 | Available params: http://developer.openstack.org/ |
| 484 | api-ref-compute-v2.1.html#getConsoleOutput |
| 485 | """ |
| 486 | return self.action(server_id, 'os-getConsoleOutput', |
| 487 | schema.get_console_output, **kwargs) |
| 488 | |
| 489 | def list_virtual_interfaces(self, server_id): |
| 490 | """List the virtual interfaces used in an instance.""" |
| 491 | resp, body = self.get('/'.join(['servers', server_id, |
| 492 | 'os-virtual-interfaces'])) |
| 493 | body = json.loads(body) |
| 494 | self.validate_response(schema.list_virtual_interfaces, resp, body) |
| 495 | return rest_client.ResponseBody(resp, body) |
| 496 | |
| 497 | def rescue_server(self, server_id, **kwargs): |
| 498 | """Rescue the provided server. |
| 499 | |
| 500 | Available params: http://developer.openstack.org/ |
| 501 | api-ref-compute-v2.1.html#rescue |
| 502 | """ |
| 503 | return self.action(server_id, 'rescue', schema.rescue_server, **kwargs) |
| 504 | |
| 505 | def unrescue_server(self, server_id): |
| 506 | """Unrescue the provided server.""" |
| 507 | return self.action(server_id, 'unrescue') |
| 508 | |
| 509 | def show_server_diagnostics(self, server_id): |
| 510 | """Get the usage data for a server.""" |
| 511 | resp, body = self.get("servers/%s/diagnostics" % server_id) |
| 512 | return rest_client.ResponseBody(resp, json.loads(body)) |
| 513 | |
| 514 | def list_instance_actions(self, server_id): |
| 515 | """List the provided server action.""" |
| 516 | resp, body = self.get("servers/%s/os-instance-actions" % |
| 517 | server_id) |
| 518 | body = json.loads(body) |
| 519 | self.validate_response(schema.list_instance_actions, resp, body) |
| 520 | return rest_client.ResponseBody(resp, body) |
| 521 | |
| 522 | def show_instance_action(self, server_id, request_id): |
| 523 | """Returns the action details of the provided server.""" |
| 524 | resp, body = self.get("servers/%s/os-instance-actions/%s" % |
| 525 | (server_id, request_id)) |
| 526 | body = json.loads(body) |
| 527 | self.validate_response(schema.show_instance_action, resp, body) |
| 528 | return rest_client.ResponseBody(resp, body) |
| 529 | |
| 530 | def force_delete_server(self, server_id, **kwargs): |
| 531 | """Force delete a server. |
| 532 | |
| 533 | Available params: http://developer.openstack.org/ |
| 534 | api-ref-compute-v2.1.html#forceDelete |
| 535 | """ |
| 536 | return self.action(server_id, 'forceDelete', **kwargs) |
| 537 | |
| 538 | def restore_soft_deleted_server(self, server_id, **kwargs): |
| 539 | """Restore a soft-deleted server. |
| 540 | |
| 541 | Available params: http://developer.openstack.org/ |
| 542 | api-ref-compute-v2.1.html#restore |
| 543 | """ |
| 544 | return self.action(server_id, 'restore', **kwargs) |
| 545 | |
| 546 | def reset_network(self, server_id, **kwargs): |
| 547 | """Reset the Network of a server. |
| 548 | |
| 549 | Available params: http://developer.openstack.org/ |
| 550 | api-ref-compute-v2.1.html#resetNetwork |
| 551 | """ |
| 552 | return self.action(server_id, 'resetNetwork', **kwargs) |
| 553 | |
| 554 | def inject_network_info(self, server_id, **kwargs): |
| 555 | """Inject the Network Info into server. |
| 556 | |
| 557 | Available params: http://developer.openstack.org/ |
| 558 | api-ref-compute-v2.1.html#injectNetworkInfo |
| 559 | """ |
| 560 | return self.action(server_id, 'injectNetworkInfo', **kwargs) |
| 561 | |
| 562 | def get_vnc_console(self, server_id, **kwargs): |
| 563 | """Get URL of VNC console. |
| 564 | |
| 565 | Available params: http://developer.openstack.org/ |
| 566 | api-ref-compute-v2.1.html#getVNCConsole |
| 567 | """ |
| 568 | return self.action(server_id, "os-getVNCConsole", |
| 569 | schema.get_vnc_console, **kwargs) |
| 570 | |
| 571 | def add_fixed_ip(self, server_id, **kwargs): |
| 572 | """Add a fixed IP to server instance. |
| 573 | |
| 574 | Available params: http://developer.openstack.org/ |
| 575 | api-ref-compute-v2.1.html#addFixedIp |
| 576 | """ |
| 577 | return self.action(server_id, 'addFixedIp', **kwargs) |
| 578 | |
| 579 | def remove_fixed_ip(self, server_id, **kwargs): |
| 580 | """Remove input fixed IP from input server instance. |
| 581 | |
| 582 | Available params: http://developer.openstack.org/ |
| 583 | api-ref-compute-v2.1.html#removeFixedIp |
| 584 | """ |
| 585 | return self.action(server_id, 'removeFixedIp', **kwargs) |