blob: d5902e1b38fe2c69d05721f18780b3c602c51452 [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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
17import copy
18
19from oslo_serialization import jsonutils as json
20from six.moves.urllib import parse as urllib
21
22from tempest.lib.api_schema.response.compute.v2_1 import servers as schema
Eli Qiaoe07eacc2016-03-03 13:49:37 +080023from tempest.lib.api_schema.response.compute.v2_16 import servers as schemav216
lanoux2746ba02016-03-16 17:41:01 +090024from tempest.lib.api_schema.response.compute.v2_19 import servers as schemav219
Matt Riedemann3e4a46a2016-07-27 14:41:32 -040025from tempest.lib.api_schema.response.compute.v2_26 import servers as schemav226
Eli Qiaoe07eacc2016-03-03 13:49:37 +080026from tempest.lib.api_schema.response.compute.v2_3 import servers as schemav23
lanoux2746ba02016-03-16 17:41:01 +090027from tempest.lib.api_schema.response.compute.v2_9 import servers as schemav29
Matthew Treinish9e26ca82016-02-23 11:43:20 -050028from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090029from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050030
31
Ghanshyamee9af302016-02-25 06:12:43 +090032class ServersClient(base_compute_client.BaseComputeClient):
lanoux2746ba02016-03-16 17:41:01 +090033 schema_versions_info = [
Eli Qiaoe07eacc2016-03-03 13:49:37 +080034 {'min': None, 'max': '2.2', 'schema': schema},
35 {'min': '2.3', 'max': '2.8', 'schema': schemav23},
36 {'min': '2.9', 'max': '2.15', 'schema': schemav29},
37 {'min': '2.16', 'max': '2.18', 'schema': schemav216},
Matt Riedemann3e4a46a2016-07-27 14:41:32 -040038 {'min': '2.19', 'max': '2.25', 'schema': schemav219},
39 {'min': '2.26', 'max': None, 'schema': schemav226}]
Matthew Treinish9e26ca82016-02-23 11:43:20 -050040
41 def __init__(self, auth_provider, service, region,
42 enable_instance_password=True, **kwargs):
43 super(ServersClient, self).__init__(
44 auth_provider, service, region, **kwargs)
45 self.enable_instance_password = enable_instance_password
46
47 def create_server(self, **kwargs):
48 """Create server.
49
Ken'ichi Ohmichid9bafc02016-09-09 09:35:21 -070050 For a full list of available parameters, please refer to the official
51 API reference:
52 http://developer.openstack.org/api-ref/compute/#create-server
53
54 :param name: Server name
55 :param imageRef: Image reference (UUID)
56 :param flavorRef: Flavor reference (UUID or full URL)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050057
58 Most parameters except the following are passed to the API without
59 any changes.
60 :param disk_config: The name is changed to OS-DCF:diskConfig
61 :param scheduler_hints: The name is changed to os:scheduler_hints and
62 the parameter is set in the same level as the parameter 'server'.
63 """
64 body = copy.deepcopy(kwargs)
65 if body.get('disk_config'):
66 body['OS-DCF:diskConfig'] = body.pop('disk_config')
67
68 hints = None
69 if body.get('scheduler_hints'):
70 hints = {'os:scheduler_hints': body.pop('scheduler_hints')}
71
72 post_body = {'server': body}
73
74 if hints:
Jordan Pittier81c427d2016-04-25 17:02:58 +020075 post_body.update(hints)
Matthew Treinish9e26ca82016-02-23 11:43:20 -050076
77 post_body = json.dumps(post_body)
78 resp, body = self.post('servers', post_body)
79
80 body = json.loads(body)
81 # NOTE(maurosr): this deals with the case of multiple server create
82 # with return reservation id set True
83 if 'reservation_id' in body:
84 return rest_client.ResponseBody(resp, body)
85 if self.enable_instance_password:
86 create_schema = schema.create_server_with_admin_pass
87 else:
88 create_schema = schema.create_server
89 self.validate_response(create_schema, resp, body)
90 return rest_client.ResponseBody(resp, body)
91
92 def update_server(self, server_id, **kwargs):
93 """Update server.
94
95 Available params: see http://developer.openstack.org/
96 api-ref-compute-v2.1.html#updateServer
97
98 Most parameters except the following are passed to the API without
99 any changes.
100 :param disk_config: The name is changed to OS-DCF:diskConfig
101 """
102 if kwargs.get('disk_config'):
103 kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')
104
105 post_body = json.dumps({'server': kwargs})
106 resp, body = self.put("servers/%s" % server_id, post_body)
107 body = json.loads(body)
lanoux2746ba02016-03-16 17:41:01 +0900108 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500109 self.validate_response(schema.update_server, resp, body)
110 return rest_client.ResponseBody(resp, body)
111
112 def show_server(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800113 """Get server details.
114
115 Available params: see http://developer.openstack.org/
116 api-ref-compute-v2.1.html#showServer
117 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500118 resp, body = self.get("servers/%s" % server_id)
119 body = json.loads(body)
lanoux2746ba02016-03-16 17:41:01 +0900120 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500121 self.validate_response(schema.get_server, resp, body)
122 return rest_client.ResponseBody(resp, body)
123
124 def delete_server(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800125 """Delete server.
126
127 Available params: see http://developer.openstack.org/
128 api-ref-compute-v2.1.html#deleteServer
129 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500130 resp, body = self.delete("servers/%s" % server_id)
131 self.validate_response(schema.delete_server, resp, body)
132 return rest_client.ResponseBody(resp, body)
133
134 def list_servers(self, detail=False, **params):
135 """List servers.
136
137 Available params: see http://developer.openstack.org/
138 api-ref-compute-v2.1.html#listServers
139 and http://developer.openstack.org/
140 api-ref-compute-v2.1.html#listDetailServers
141 """
142
143 url = 'servers'
lanoux2746ba02016-03-16 17:41:01 +0900144 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500145 _schema = schema.list_servers
146
147 if detail:
148 url += '/detail'
149 _schema = schema.list_servers_detail
150 if params:
151 url += '?%s' % urllib.urlencode(params)
152
153 resp, body = self.get(url)
154 body = json.loads(body)
155 self.validate_response(_schema, resp, body)
156 return rest_client.ResponseBody(resp, body)
157
158 def list_addresses(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800159 """Lists all addresses for a server.
160
161 Available params: see http://developer.openstack.org/
162 api-ref-compute-v2.1.html#list-ips
163 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500164 resp, body = self.get("servers/%s/ips" % server_id)
165 body = json.loads(body)
166 self.validate_response(schema.list_addresses, resp, body)
167 return rest_client.ResponseBody(resp, body)
168
169 def list_addresses_by_network(self, server_id, network_id):
170 """Lists all addresses of a specific network type for a server."""
171 resp, body = self.get("servers/%s/ips/%s" %
172 (server_id, network_id))
173 body = json.loads(body)
174 self.validate_response(schema.list_addresses_by_network, resp, body)
175 return rest_client.ResponseBody(resp, body)
176
177 def action(self, server_id, action_name,
178 schema=schema.server_actions_common_schema,
179 **kwargs):
180 post_body = json.dumps({action_name: kwargs})
181 resp, body = self.post('servers/%s/action' % server_id,
182 post_body)
183 if body:
184 body = json.loads(body)
185 self.validate_response(schema, resp, body)
186 return rest_client.ResponseBody(resp, body)
187
188 def create_backup(self, server_id, **kwargs):
189 """Backup a server instance.
190
191 Available params: see http://developer.openstack.org/
192 api-ref-compute-v2.1.html#createBackup
193 """
194 return self.action(server_id, "createBackup", **kwargs)
195
196 def change_password(self, server_id, **kwargs):
197 """Change the root password for the server.
198
199 Available params: see http://developer.openstack.org/
200 api-ref-compute-v2.1.html#changePassword
201 """
202 return self.action(server_id, 'changePassword', **kwargs)
203
204 def show_password(self, server_id):
205 resp, body = self.get("servers/%s/os-server-password" %
206 server_id)
207 body = json.loads(body)
208 self.validate_response(schema.show_password, resp, body)
209 return rest_client.ResponseBody(resp, body)
210
211 def delete_password(self, server_id):
212 """Removes the encrypted server password from the metadata server
213
214 Note that this does not actually change the instance server
215 password.
216 """
217 resp, body = self.delete("servers/%s/os-server-password" %
218 server_id)
219 self.validate_response(schema.server_actions_delete_password,
220 resp, body)
221 return rest_client.ResponseBody(resp, body)
222
223 def reboot_server(self, server_id, **kwargs):
224 """Reboot a server.
225
226 Available params: http://developer.openstack.org/
227 api-ref-compute-v2.1.html#reboot
228 """
229 return self.action(server_id, 'reboot', **kwargs)
230
231 def rebuild_server(self, server_id, image_ref, **kwargs):
232 """Rebuild a server with a new image.
233
234 Available params: http://developer.openstack.org/
235 api-ref-compute-v2.1.html#rebuild
236
237 Most parameters except the following are passed to the API without
238 any changes.
239 :param disk_config: The name is changed to OS-DCF:diskConfig
240 """
241 kwargs['imageRef'] = image_ref
242 if 'disk_config' in kwargs:
243 kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')
lanoux2746ba02016-03-16 17:41:01 +0900244 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500245 if self.enable_instance_password:
246 rebuild_schema = schema.rebuild_server_with_admin_pass
247 else:
248 rebuild_schema = schema.rebuild_server
249 return self.action(server_id, 'rebuild',
250 rebuild_schema, **kwargs)
251
252 def resize_server(self, server_id, flavor_ref, **kwargs):
253 """Change the flavor of a server.
254
255 Available params: http://developer.openstack.org/
256 api-ref-compute-v2.1.html#resize
257
258 Most parameters except the following are passed to the API without
259 any changes.
260 :param disk_config: The name is changed to OS-DCF:diskConfig
261 """
262 kwargs['flavorRef'] = flavor_ref
263 if 'disk_config' in kwargs:
264 kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')
265 return self.action(server_id, 'resize', **kwargs)
266
267 def confirm_resize_server(self, server_id, **kwargs):
268 """Confirm the flavor change for a server.
269
270 Available params: see http://developer.openstack.org/
271 api-ref-compute-v2.1.html#confirmResize
272 """
273 return self.action(server_id, 'confirmResize',
274 schema.server_actions_confirm_resize,
275 **kwargs)
276
277 def revert_resize_server(self, server_id, **kwargs):
278 """Revert a server back to its original flavor.
279
280 Available params: see http://developer.openstack.org/
281 api-ref-compute-v2.1.html#revertResize
282 """
283 return self.action(server_id, 'revertResize', **kwargs)
284
285 def list_server_metadata(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800286 """Lists all metadata for a server.
287
288 Available params: see http://developer.openstack.org/
289 api-ref-compute-v2.1.html#listServerMetadata
290 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500291 resp, body = self.get("servers/%s/metadata" % server_id)
292 body = json.loads(body)
293 self.validate_response(schema.list_server_metadata, resp, body)
294 return rest_client.ResponseBody(resp, body)
295
296 def set_server_metadata(self, server_id, meta, no_metadata_field=False):
Lv Fumei7e326332016-07-08 15:18:03 +0800297 """Sets one or more metadata items for a server.
298
299 Available params: see http://developer.openstack.org/
300 api-ref-compute-v2.1.html#createServerMetadata
301 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500302 if no_metadata_field:
303 post_body = ""
304 else:
305 post_body = json.dumps({'metadata': meta})
306 resp, body = self.put('servers/%s/metadata' % server_id,
307 post_body)
308 body = json.loads(body)
309 self.validate_response(schema.set_server_metadata, resp, body)
310 return rest_client.ResponseBody(resp, body)
311
312 def update_server_metadata(self, server_id, meta):
Lv Fumei7e326332016-07-08 15:18:03 +0800313 """Updates one or more metadata items for a server.
314
315 Available params: see http://developer.openstack.org/
316 api-ref-compute-v2.1.html#updateServerMetadata
317 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500318 post_body = json.dumps({'metadata': meta})
319 resp, body = self.post('servers/%s/metadata' % server_id,
320 post_body)
321 body = json.loads(body)
322 self.validate_response(schema.update_server_metadata,
323 resp, body)
324 return rest_client.ResponseBody(resp, body)
325
326 def show_server_metadata_item(self, server_id, key):
Lv Fumei7e326332016-07-08 15:18:03 +0800327 """Shows details for a metadata item, by key, for a server.
328
329 Available params: see http://developer.openstack.org/
330 api-ref-compute-v2.1.html#showServerMetadataItem
331 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500332 resp, body = self.get("servers/%s/metadata/%s" % (server_id, key))
333 body = json.loads(body)
334 self.validate_response(schema.set_show_server_metadata_item,
335 resp, body)
336 return rest_client.ResponseBody(resp, body)
337
338 def set_server_metadata_item(self, server_id, key, meta):
Lv Fumei7e326332016-07-08 15:18:03 +0800339 """Sets a metadata item, by key, for a server.
340
341 Available params: see http://developer.openstack.org/
342 api-ref-compute-v2.1.html#setServerMetadataItem
343 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500344 post_body = json.dumps({'meta': meta})
345 resp, body = self.put('servers/%s/metadata/%s' % (server_id, key),
346 post_body)
347 body = json.loads(body)
348 self.validate_response(schema.set_show_server_metadata_item,
349 resp, body)
350 return rest_client.ResponseBody(resp, body)
351
352 def delete_server_metadata_item(self, server_id, key):
Lv Fumei7e326332016-07-08 15:18:03 +0800353 """Deletes a metadata item, by key, from a server.
354
355 Available params: see http://developer.openstack.org/
356 api-ref-compute-v2.1.html#deleteServerMetadataItem
357 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500358 resp, body = self.delete("servers/%s/metadata/%s" %
359 (server_id, key))
360 self.validate_response(schema.delete_server_metadata_item,
361 resp, body)
362 return rest_client.ResponseBody(resp, body)
363
364 def stop_server(self, server_id, **kwargs):
Lv Fumei7e326332016-07-08 15:18:03 +0800365 """Stops a running server and changes its status to SHUTOFF.
366
367 Available params: see http://developer.openstack.org/
368 api-ref-compute-v2.1.html#stop
369 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500370 return self.action(server_id, 'os-stop', **kwargs)
371
372 def start_server(self, server_id, **kwargs):
Lv Fumei7e326332016-07-08 15:18:03 +0800373 """Starts a stopped server and changes its status to ACTIVE.
374
375 Available params: see http://developer.openstack.org/
376 api-ref-compute-v2.1.html#start
377 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500378 return self.action(server_id, 'os-start', **kwargs)
379
380 def attach_volume(self, server_id, **kwargs):
zhuflff6d0da2016-06-12 17:27:12 +0800381 """Attaches a volume to a server instance.
382
383 Available params: see http://developer.openstack.org/
384 api-ref-compute-v2.1.html#attachVolume
385 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500386 post_body = json.dumps({'volumeAttachment': kwargs})
387 resp, body = self.post('servers/%s/os-volume_attachments' % server_id,
388 post_body)
389 body = json.loads(body)
390 self.validate_response(schema.attach_volume, resp, body)
391 return rest_client.ResponseBody(resp, body)
392
393 def update_attached_volume(self, server_id, attachment_id, **kwargs):
394 """Swaps a volume attached to an instance for another volume"""
395 post_body = json.dumps({'volumeAttachment': kwargs})
396 resp, body = self.put('servers/%s/os-volume_attachments/%s' %
397 (server_id, attachment_id),
398 post_body)
399 self.validate_response(schema.update_attached_volume, resp, body)
400 return rest_client.ResponseBody(resp, body)
401
402 def detach_volume(self, server_id, volume_id): # noqa
Lv Fumei7e326332016-07-08 15:18:03 +0800403 """Detaches a volume from a server instance.
404
405 Available params: see http://developer.openstack.org/
406 api-ref-compute-v2.1.html#deleteVolumeAttachment
407 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500408 resp, body = self.delete('servers/%s/os-volume_attachments/%s' %
409 (server_id, volume_id))
410 self.validate_response(schema.detach_volume, resp, body)
411 return rest_client.ResponseBody(resp, body)
412
413 def show_volume_attachment(self, server_id, volume_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800414 """Return details about the given volume attachment.
415
416 Available params: see http://developer.openstack.org/
417 api-ref-compute-v2.1.html#
418 getVolumeAttachmentDetails
419 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500420 resp, body = self.get('servers/%s/os-volume_attachments/%s' % (
421 server_id, volume_id))
422 body = json.loads(body)
423 self.validate_response(schema.show_volume_attachment, resp, body)
424 return rest_client.ResponseBody(resp, body)
425
426 def list_volume_attachments(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800427 """Returns the list of volume attachments for a given instance.
428
429 Available params: see http://developer.openstack.org/
430 api-ref-compute-v2.1.html#listVolumeAttachments
431 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500432 resp, body = self.get('servers/%s/os-volume_attachments' % (
433 server_id))
434 body = json.loads(body)
435 self.validate_response(schema.list_volume_attachments, resp, body)
436 return rest_client.ResponseBody(resp, body)
437
438 def add_security_group(self, server_id, **kwargs):
439 """Add a security group to the server.
440
Lv Fumei7e326332016-07-08 15:18:03 +0800441 Available params: http://developer.openstack.org/
442 api-ref-compute-v2.1.html#addSecurityGroup
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500443 """
444 # TODO(oomichi): The api-site doesn't contain this API description.
445 # So the above should be changed to the api-site link after
446 # adding the description on the api-site.
447 # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524199
448 return self.action(server_id, 'addSecurityGroup', **kwargs)
449
450 def remove_security_group(self, server_id, **kwargs):
451 """Remove a security group from the server.
452
Lv Fumei7e326332016-07-08 15:18:03 +0800453 Available params: http://developer.openstack.org/
454 api-ref-compute-v2.1.html#removeSecurityGroup
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500455 """
456 # TODO(oomichi): The api-site doesn't contain this API description.
457 # So the above should be changed to the api-site link after
458 # adding the description on the api-site.
459 # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524199
460 return self.action(server_id, 'removeSecurityGroup', **kwargs)
461
462 def live_migrate_server(self, server_id, **kwargs):
463 """This should be called with administrator privileges.
464
465 Available params: http://developer.openstack.org/
466 api-ref-compute-v2.1.html#migrateLive
467 """
468 return self.action(server_id, 'os-migrateLive', **kwargs)
469
470 def migrate_server(self, server_id, **kwargs):
471 """Migrate a server to a new host.
472
473 Available params: http://developer.openstack.org/
474 api-ref-compute-v2.1.html#migrate
475 """
476 return self.action(server_id, 'migrate', **kwargs)
477
478 def lock_server(self, server_id, **kwargs):
479 """Lock the given server.
480
481 Available params: http://developer.openstack.org/
482 api-ref-compute-v2.1.html#lock
483 """
484 return self.action(server_id, 'lock', **kwargs)
485
486 def unlock_server(self, server_id, **kwargs):
487 """UNlock the given server.
488
489 Available params: http://developer.openstack.org/
490 api-ref-compute-v2.1.html#unlock
491 """
492 return self.action(server_id, 'unlock', **kwargs)
493
494 def suspend_server(self, server_id, **kwargs):
495 """Suspend the provided server.
496
497 Available params: http://developer.openstack.org/
498 api-ref-compute-v2.1.html#suspend
499 """
500 return self.action(server_id, 'suspend', **kwargs)
501
502 def resume_server(self, server_id, **kwargs):
503 """Un-suspend the provided server.
504
505 Available params: http://developer.openstack.org/
506 api-ref-compute-v2.1.html#resume
507 """
508 return self.action(server_id, 'resume', **kwargs)
509
510 def pause_server(self, server_id, **kwargs):
511 """Pause the provided server.
512
513 Available params: http://developer.openstack.org/
514 api-ref-compute-v2.1.html#pause
515 """
516 return self.action(server_id, 'pause', **kwargs)
517
518 def unpause_server(self, server_id, **kwargs):
519 """Un-pause the provided server.
520
521 Available params: http://developer.openstack.org/
522 api-ref-compute-v2.1.html#unpause
523 """
524 return self.action(server_id, 'unpause', **kwargs)
525
526 def reset_state(self, server_id, **kwargs):
527 """Reset the state of a server to active/error.
528
529 Available params: http://developer.openstack.org/
530 api-ref-compute-v2.1.html#resetState
531 """
532 return self.action(server_id, 'os-resetState', **kwargs)
533
534 def shelve_server(self, server_id, **kwargs):
535 """Shelve the provided server.
536
537 Available params: http://developer.openstack.org/
538 api-ref-compute-v2.1.html#shelve
539 """
540 return self.action(server_id, 'shelve', **kwargs)
541
542 def unshelve_server(self, server_id, **kwargs):
543 """Un-shelve the provided server.
544
545 Available params: http://developer.openstack.org/
546 api-ref-compute-v2.1.html#unshelve
547 """
548 return self.action(server_id, 'unshelve', **kwargs)
549
550 def shelve_offload_server(self, server_id, **kwargs):
551 """Shelve-offload the provided server.
552
553 Available params: http://developer.openstack.org/
554 api-ref-compute-v2.1.html#shelveOffload
555 """
556 return self.action(server_id, 'shelveOffload', **kwargs)
557
558 def get_console_output(self, server_id, **kwargs):
559 """Get console output.
560
561 Available params: http://developer.openstack.org/
562 api-ref-compute-v2.1.html#getConsoleOutput
563 """
564 return self.action(server_id, 'os-getConsoleOutput',
565 schema.get_console_output, **kwargs)
566
567 def list_virtual_interfaces(self, server_id):
568 """List the virtual interfaces used in an instance."""
569 resp, body = self.get('/'.join(['servers', server_id,
570 'os-virtual-interfaces']))
571 body = json.loads(body)
572 self.validate_response(schema.list_virtual_interfaces, resp, body)
573 return rest_client.ResponseBody(resp, body)
574
575 def rescue_server(self, server_id, **kwargs):
576 """Rescue the provided server.
577
578 Available params: http://developer.openstack.org/
579 api-ref-compute-v2.1.html#rescue
580 """
581 return self.action(server_id, 'rescue', schema.rescue_server, **kwargs)
582
583 def unrescue_server(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800584 """Unrescue the provided server.
585
586 Available params: http://developer.openstack.org/
587 api-ref-compute-v2.1.html#unrescue
588 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500589 return self.action(server_id, 'unrescue')
590
591 def show_server_diagnostics(self, server_id):
592 """Get the usage data for a server."""
593 resp, body = self.get("servers/%s/diagnostics" % server_id)
594 return rest_client.ResponseBody(resp, json.loads(body))
595
596 def list_instance_actions(self, server_id):
597 """List the provided server action."""
598 resp, body = self.get("servers/%s/os-instance-actions" %
599 server_id)
600 body = json.loads(body)
601 self.validate_response(schema.list_instance_actions, resp, body)
602 return rest_client.ResponseBody(resp, body)
603
604 def show_instance_action(self, server_id, request_id):
605 """Returns the action details of the provided server."""
606 resp, body = self.get("servers/%s/os-instance-actions/%s" %
607 (server_id, request_id))
608 body = json.loads(body)
609 self.validate_response(schema.show_instance_action, resp, body)
610 return rest_client.ResponseBody(resp, body)
611
612 def force_delete_server(self, server_id, **kwargs):
613 """Force delete a server.
614
615 Available params: http://developer.openstack.org/
616 api-ref-compute-v2.1.html#forceDelete
617 """
618 return self.action(server_id, 'forceDelete', **kwargs)
619
620 def restore_soft_deleted_server(self, server_id, **kwargs):
621 """Restore a soft-deleted server.
622
623 Available params: http://developer.openstack.org/
624 api-ref-compute-v2.1.html#restore
625 """
626 return self.action(server_id, 'restore', **kwargs)
627
628 def reset_network(self, server_id, **kwargs):
629 """Reset the Network of a server.
630
631 Available params: http://developer.openstack.org/
632 api-ref-compute-v2.1.html#resetNetwork
633 """
634 return self.action(server_id, 'resetNetwork', **kwargs)
635
636 def inject_network_info(self, server_id, **kwargs):
637 """Inject the Network Info into server.
638
639 Available params: http://developer.openstack.org/
640 api-ref-compute-v2.1.html#injectNetworkInfo
641 """
642 return self.action(server_id, 'injectNetworkInfo', **kwargs)
643
644 def get_vnc_console(self, server_id, **kwargs):
645 """Get URL of VNC console.
646
647 Available params: http://developer.openstack.org/
648 api-ref-compute-v2.1.html#getVNCConsole
649 """
650 return self.action(server_id, "os-getVNCConsole",
651 schema.get_vnc_console, **kwargs)
652
653 def add_fixed_ip(self, server_id, **kwargs):
654 """Add a fixed IP to server instance.
655
656 Available params: http://developer.openstack.org/
657 api-ref-compute-v2.1.html#addFixedIp
658 """
659 return self.action(server_id, 'addFixedIp', **kwargs)
660
661 def remove_fixed_ip(self, server_id, **kwargs):
662 """Remove input fixed IP from input server instance.
663
664 Available params: http://developer.openstack.org/
665 api-ref-compute-v2.1.html#removeFixedIp
666 """
667 return self.action(server_id, 'removeFixedIp', **kwargs)