blob: 24557d8b58c7284503b6c2eddc0c46111bd6890b [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
Dong Mad12c2332016-10-19 01:36:27 -070095 For a full list of available parameters, please refer to the official
96 API reference:
97 http://developer.openstack.org/api-ref-compute-v2.1.html#updateServer
Matthew Treinish9e26ca82016-02-23 11:43:20 -050098
99 Most parameters except the following are passed to the API without
100 any changes.
101 :param disk_config: The name is changed to OS-DCF:diskConfig
102 """
103 if kwargs.get('disk_config'):
104 kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')
105
106 post_body = json.dumps({'server': kwargs})
107 resp, body = self.put("servers/%s" % server_id, post_body)
108 body = json.loads(body)
lanoux2746ba02016-03-16 17:41:01 +0900109 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500110 self.validate_response(schema.update_server, resp, body)
111 return rest_client.ResponseBody(resp, body)
112
113 def show_server(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800114 """Get server details.
115
Dong Mad12c2332016-10-19 01:36:27 -0700116 For a full list of available parameters, please refer to the official
117 API reference:
118 http://developer.openstack.org/api-ref-compute-v2.1.html#showServer
Lv Fumei7e326332016-07-08 15:18:03 +0800119 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500120 resp, body = self.get("servers/%s" % server_id)
121 body = json.loads(body)
lanoux2746ba02016-03-16 17:41:01 +0900122 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500123 self.validate_response(schema.get_server, resp, body)
124 return rest_client.ResponseBody(resp, body)
125
126 def delete_server(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800127 """Delete server.
128
Dong Mad12c2332016-10-19 01:36:27 -0700129 For a full list of available parameters, please refer to the official
130 API reference:
131 http://developer.openstack.org/api-ref-compute-v2.1.html#deleteServer
Lv Fumei7e326332016-07-08 15:18:03 +0800132 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500133 resp, body = self.delete("servers/%s" % server_id)
134 self.validate_response(schema.delete_server, resp, body)
135 return rest_client.ResponseBody(resp, body)
136
137 def list_servers(self, detail=False, **params):
138 """List servers.
139
Dong Mad12c2332016-10-19 01:36:27 -0700140 For a full list of available parameters, please refer to the official
141 API reference:
142 http://developer.openstack.org/api-ref-compute-v2.1.html#listServers
143 http://developer.openstack.org/api-ref-compute-v2.1.html#listDetailServers
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500144 """
145
146 url = 'servers'
lanoux2746ba02016-03-16 17:41:01 +0900147 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500148 _schema = schema.list_servers
149
150 if detail:
151 url += '/detail'
152 _schema = schema.list_servers_detail
153 if params:
154 url += '?%s' % urllib.urlencode(params)
155
156 resp, body = self.get(url)
157 body = json.loads(body)
158 self.validate_response(_schema, resp, body)
159 return rest_client.ResponseBody(resp, body)
160
161 def list_addresses(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800162 """Lists all addresses for a server.
163
Dong Mad12c2332016-10-19 01:36:27 -0700164 For a full list of available parameters, please refer to the official
165 API reference:
166 http://developer.openstack.org/api-ref-compute-v2.1.html#list-ips
Lv Fumei7e326332016-07-08 15:18:03 +0800167 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500168 resp, body = self.get("servers/%s/ips" % server_id)
169 body = json.loads(body)
170 self.validate_response(schema.list_addresses, resp, body)
171 return rest_client.ResponseBody(resp, body)
172
173 def list_addresses_by_network(self, server_id, network_id):
174 """Lists all addresses of a specific network type for a server."""
175 resp, body = self.get("servers/%s/ips/%s" %
176 (server_id, network_id))
177 body = json.loads(body)
178 self.validate_response(schema.list_addresses_by_network, resp, body)
179 return rest_client.ResponseBody(resp, body)
180
181 def action(self, server_id, action_name,
182 schema=schema.server_actions_common_schema,
183 **kwargs):
184 post_body = json.dumps({action_name: kwargs})
185 resp, body = self.post('servers/%s/action' % server_id,
186 post_body)
187 if body:
188 body = json.loads(body)
189 self.validate_response(schema, resp, body)
190 return rest_client.ResponseBody(resp, body)
191
192 def create_backup(self, server_id, **kwargs):
193 """Backup a server instance.
194
Dong Mad12c2332016-10-19 01:36:27 -0700195 For a full list of available parameters, please refer to the official
196 API reference:
197 http://developer.openstack.org/api-ref-compute-v2.1.html#createBackup
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500198 """
199 return self.action(server_id, "createBackup", **kwargs)
200
201 def change_password(self, server_id, **kwargs):
202 """Change the root password for the server.
203
Dong Mad12c2332016-10-19 01:36:27 -0700204 For a full list of available parameters, please refer to the official
205 API reference:
206 http://developer.openstack.org/api-ref-compute-v2.1.html#changePassword
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500207 """
208 return self.action(server_id, 'changePassword', **kwargs)
209
210 def show_password(self, server_id):
211 resp, body = self.get("servers/%s/os-server-password" %
212 server_id)
213 body = json.loads(body)
214 self.validate_response(schema.show_password, resp, body)
215 return rest_client.ResponseBody(resp, body)
216
217 def delete_password(self, server_id):
218 """Removes the encrypted server password from the metadata server
219
220 Note that this does not actually change the instance server
221 password.
222 """
223 resp, body = self.delete("servers/%s/os-server-password" %
224 server_id)
225 self.validate_response(schema.server_actions_delete_password,
226 resp, body)
227 return rest_client.ResponseBody(resp, body)
228
229 def reboot_server(self, server_id, **kwargs):
230 """Reboot a server.
231
Dong Mad12c2332016-10-19 01:36:27 -0700232 For a full list of available parameters, please refer to the official
233 API reference:
234 http://developer.openstack.org/api-ref-compute-v2.1.html#reboot
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500235 """
236 return self.action(server_id, 'reboot', **kwargs)
237
238 def rebuild_server(self, server_id, image_ref, **kwargs):
239 """Rebuild a server with a new image.
240
Dong Mad12c2332016-10-19 01:36:27 -0700241 For a full list of available parameters, please refer to the official
242 API reference:
243 http://developer.openstack.org/api-ref-compute-v2.1.html#rebuild
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500244
245 Most parameters except the following are passed to the API without
246 any changes.
247 :param disk_config: The name is changed to OS-DCF:diskConfig
248 """
249 kwargs['imageRef'] = image_ref
250 if 'disk_config' in kwargs:
251 kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')
lanoux2746ba02016-03-16 17:41:01 +0900252 schema = self.get_schema(self.schema_versions_info)
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500253 if self.enable_instance_password:
254 rebuild_schema = schema.rebuild_server_with_admin_pass
255 else:
256 rebuild_schema = schema.rebuild_server
257 return self.action(server_id, 'rebuild',
258 rebuild_schema, **kwargs)
259
260 def resize_server(self, server_id, flavor_ref, **kwargs):
261 """Change the flavor of a server.
262
Dong Mad12c2332016-10-19 01:36:27 -0700263 For a full list of available parameters, please refer to the official
264 API reference:
265 http://developer.openstack.org/api-ref-compute-v2.1.html#resize
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500266
267 Most parameters except the following are passed to the API without
268 any changes.
269 :param disk_config: The name is changed to OS-DCF:diskConfig
270 """
271 kwargs['flavorRef'] = flavor_ref
272 if 'disk_config' in kwargs:
273 kwargs['OS-DCF:diskConfig'] = kwargs.pop('disk_config')
274 return self.action(server_id, 'resize', **kwargs)
275
276 def confirm_resize_server(self, server_id, **kwargs):
277 """Confirm the flavor change for a server.
278
Dong Mad12c2332016-10-19 01:36:27 -0700279 For a full list of available parameters, please refer to the official
280 API reference:
281 http://developer.openstack.org/api-ref-compute-v2.1.html#confirmResize
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500282 """
283 return self.action(server_id, 'confirmResize',
284 schema.server_actions_confirm_resize,
285 **kwargs)
286
287 def revert_resize_server(self, server_id, **kwargs):
288 """Revert a server back to its original flavor.
289
Dong Mad12c2332016-10-19 01:36:27 -0700290 For a full list of available parameters, please refer to the official
291 API reference:
292 http://developer.openstack.org/api-ref-compute-v2.1.html#revertResize
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500293 """
294 return self.action(server_id, 'revertResize', **kwargs)
295
296 def list_server_metadata(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800297 """Lists all metadata for a server.
298
Dong Mad12c2332016-10-19 01:36:27 -0700299 For a full list of available parameters, please refer to the official
300 API reference:
301 http://developer.openstack.org/api-ref-compute-v2.1.html#listServerMetadata
Lv Fumei7e326332016-07-08 15:18:03 +0800302 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500303 resp, body = self.get("servers/%s/metadata" % server_id)
304 body = json.loads(body)
305 self.validate_response(schema.list_server_metadata, resp, body)
306 return rest_client.ResponseBody(resp, body)
307
308 def set_server_metadata(self, server_id, meta, no_metadata_field=False):
Lv Fumei7e326332016-07-08 15:18:03 +0800309 """Sets one or more metadata items for a server.
310
Dong Mad12c2332016-10-19 01:36:27 -0700311 For a full list of available parameters, please refer to the official
312 API reference:
313 http://developer.openstack.org/api-ref-compute-v2.1.html#createServerMetadata
Lv Fumei7e326332016-07-08 15:18:03 +0800314 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500315 if no_metadata_field:
316 post_body = ""
317 else:
318 post_body = json.dumps({'metadata': meta})
319 resp, body = self.put('servers/%s/metadata' % server_id,
320 post_body)
321 body = json.loads(body)
322 self.validate_response(schema.set_server_metadata, resp, body)
323 return rest_client.ResponseBody(resp, body)
324
325 def update_server_metadata(self, server_id, meta):
Lv Fumei7e326332016-07-08 15:18:03 +0800326 """Updates one or more metadata items for a server.
327
Dong Mad12c2332016-10-19 01:36:27 -0700328 For a full list of available parameters, please refer to the official
329 API reference:
330 http://developer.openstack.org/api-ref-compute-v2.1.html#updateServerMetadata
Lv Fumei7e326332016-07-08 15:18:03 +0800331 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500332 post_body = json.dumps({'metadata': meta})
333 resp, body = self.post('servers/%s/metadata' % server_id,
334 post_body)
335 body = json.loads(body)
336 self.validate_response(schema.update_server_metadata,
337 resp, body)
338 return rest_client.ResponseBody(resp, body)
339
340 def show_server_metadata_item(self, server_id, key):
Lv Fumei7e326332016-07-08 15:18:03 +0800341 """Shows details for a metadata item, by key, for a server.
342
Dong Mad12c2332016-10-19 01:36:27 -0700343 For a full list of available parameters, please refer to the official
344 API reference:
345 http://developer.openstack.org/api-ref-compute-v2.1.html#showServerMetadataItem
Lv Fumei7e326332016-07-08 15:18:03 +0800346 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500347 resp, body = self.get("servers/%s/metadata/%s" % (server_id, key))
348 body = json.loads(body)
349 self.validate_response(schema.set_show_server_metadata_item,
350 resp, body)
351 return rest_client.ResponseBody(resp, body)
352
353 def set_server_metadata_item(self, server_id, key, meta):
Lv Fumei7e326332016-07-08 15:18:03 +0800354 """Sets a metadata item, by key, for a server.
355
Dong Mad12c2332016-10-19 01:36:27 -0700356 For a full list of available parameters, please refer to the official
357 API reference:
358 http://developer.openstack.org/api-ref-compute-v2.1.html#setServerMetadataItem
Lv Fumei7e326332016-07-08 15:18:03 +0800359 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500360 post_body = json.dumps({'meta': meta})
361 resp, body = self.put('servers/%s/metadata/%s' % (server_id, key),
362 post_body)
363 body = json.loads(body)
364 self.validate_response(schema.set_show_server_metadata_item,
365 resp, body)
366 return rest_client.ResponseBody(resp, body)
367
368 def delete_server_metadata_item(self, server_id, key):
Lv Fumei7e326332016-07-08 15:18:03 +0800369 """Deletes a metadata item, by key, from a server.
370
Dong Mad12c2332016-10-19 01:36:27 -0700371 For a full list of available parameters, please refer to the official
372 API reference:
373 http://developer.openstack.org/api-ref-compute-v2.1.html#deleteServerMetadataItem
Lv Fumei7e326332016-07-08 15:18:03 +0800374 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500375 resp, body = self.delete("servers/%s/metadata/%s" %
376 (server_id, key))
377 self.validate_response(schema.delete_server_metadata_item,
378 resp, body)
379 return rest_client.ResponseBody(resp, body)
380
381 def stop_server(self, server_id, **kwargs):
Lv Fumei7e326332016-07-08 15:18:03 +0800382 """Stops a running server and changes its status to SHUTOFF.
383
Dong Mad12c2332016-10-19 01:36:27 -0700384 For a full list of available parameters, please refer to the official
385 API reference:
386 http://developer.openstack.org/api-ref-compute-v2.1.html#stop
Lv Fumei7e326332016-07-08 15:18:03 +0800387 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500388 return self.action(server_id, 'os-stop', **kwargs)
389
390 def start_server(self, server_id, **kwargs):
Lv Fumei7e326332016-07-08 15:18:03 +0800391 """Starts a stopped server and changes its status to ACTIVE.
392
Dong Mad12c2332016-10-19 01:36:27 -0700393 For a full list of available parameters, please refer to the official
394 API reference:
395 http://developer.openstack.org/api-ref-compute-v2.1.html#start
Lv Fumei7e326332016-07-08 15:18:03 +0800396 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500397 return self.action(server_id, 'os-start', **kwargs)
398
399 def attach_volume(self, server_id, **kwargs):
zhuflff6d0da2016-06-12 17:27:12 +0800400 """Attaches a volume to a server instance.
401
Dong Mad12c2332016-10-19 01:36:27 -0700402 For a full list of available parameters, please refer to the official
403 API reference:
404 http://developer.openstack.org/api-ref-compute-v2.1.html#attachVolume
zhuflff6d0da2016-06-12 17:27:12 +0800405 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500406 post_body = json.dumps({'volumeAttachment': kwargs})
407 resp, body = self.post('servers/%s/os-volume_attachments' % server_id,
408 post_body)
409 body = json.loads(body)
410 self.validate_response(schema.attach_volume, resp, body)
411 return rest_client.ResponseBody(resp, body)
412
413 def update_attached_volume(self, server_id, attachment_id, **kwargs):
414 """Swaps a volume attached to an instance for another volume"""
415 post_body = json.dumps({'volumeAttachment': kwargs})
416 resp, body = self.put('servers/%s/os-volume_attachments/%s' %
417 (server_id, attachment_id),
418 post_body)
419 self.validate_response(schema.update_attached_volume, resp, body)
420 return rest_client.ResponseBody(resp, body)
421
422 def detach_volume(self, server_id, volume_id): # noqa
Lv Fumei7e326332016-07-08 15:18:03 +0800423 """Detaches a volume from a server instance.
424
Dong Mad12c2332016-10-19 01:36:27 -0700425 For a full list of available parameters, please refer to the official
426 API reference:
427 http://developer.openstack.org/api-ref-compute-v2.1.html#deleteVolumeAttachment
Lv Fumei7e326332016-07-08 15:18:03 +0800428 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500429 resp, body = self.delete('servers/%s/os-volume_attachments/%s' %
430 (server_id, volume_id))
431 self.validate_response(schema.detach_volume, resp, body)
432 return rest_client.ResponseBody(resp, body)
433
434 def show_volume_attachment(self, server_id, volume_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800435 """Return details about the given volume attachment.
436
Dong Mad12c2332016-10-19 01:36:27 -0700437 For a full list of available parameters, please refer to the official
438 API reference:
439 http://developer.openstack.org/api-ref-compute-v2.1.html#getVolumeAttachmentDetails
Lv Fumei7e326332016-07-08 15:18:03 +0800440 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500441 resp, body = self.get('servers/%s/os-volume_attachments/%s' % (
442 server_id, volume_id))
443 body = json.loads(body)
444 self.validate_response(schema.show_volume_attachment, resp, body)
445 return rest_client.ResponseBody(resp, body)
446
447 def list_volume_attachments(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800448 """Returns the list of volume attachments for a given instance.
449
Dong Mad12c2332016-10-19 01:36:27 -0700450 For a full list of available parameters, please refer to the official
451 API reference:
452 http://developer.openstack.org/api-ref-compute-v2.1.html#listVolumeAttachments
Lv Fumei7e326332016-07-08 15:18:03 +0800453 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500454 resp, body = self.get('servers/%s/os-volume_attachments' % (
455 server_id))
456 body = json.loads(body)
457 self.validate_response(schema.list_volume_attachments, resp, body)
458 return rest_client.ResponseBody(resp, body)
459
460 def add_security_group(self, server_id, **kwargs):
461 """Add a security group to the server.
462
Dong Mad12c2332016-10-19 01:36:27 -0700463 For a full list of available parameters, please refer to the official
464 API reference:
465 http://developer.openstack.org/api-ref-compute-v2.1.html#addSecurityGroup
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500466 """
467 # TODO(oomichi): The api-site doesn't contain this API description.
468 # So the above should be changed to the api-site link after
469 # adding the description on the api-site.
470 # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524199
471 return self.action(server_id, 'addSecurityGroup', **kwargs)
472
473 def remove_security_group(self, server_id, **kwargs):
474 """Remove a security group from the server.
475
Dong Mad12c2332016-10-19 01:36:27 -0700476 For a full list of available parameters, please refer to the official
477 API reference:
478 http://developer.openstack.org/api-ref-compute-v2.1.html#removeSecurityGroup
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500479 """
480 # TODO(oomichi): The api-site doesn't contain this API description.
481 # So the above should be changed to the api-site link after
482 # adding the description on the api-site.
483 # LP: https://bugs.launchpad.net/openstack-api-site/+bug/1524199
484 return self.action(server_id, 'removeSecurityGroup', **kwargs)
485
486 def live_migrate_server(self, server_id, **kwargs):
487 """This should be called with administrator privileges.
488
Dong Mad12c2332016-10-19 01:36:27 -0700489 For a full list of available parameters, please refer to the official
490 API reference:
491 http://developer.openstack.org/api-ref-compute-v2.1.html#migrateLive
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500492 """
493 return self.action(server_id, 'os-migrateLive', **kwargs)
494
495 def migrate_server(self, server_id, **kwargs):
496 """Migrate a server to a new host.
497
Dong Mad12c2332016-10-19 01:36:27 -0700498 For a full list of available parameters, please refer to the official
499 API reference:
500 http://developer.openstack.org/api-ref-compute-v2.1.html#migrate
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500501 """
502 return self.action(server_id, 'migrate', **kwargs)
503
504 def lock_server(self, server_id, **kwargs):
505 """Lock the given server.
506
Dong Mad12c2332016-10-19 01:36:27 -0700507 For a full list of available parameters, please refer to the official
508 API reference:
509 http://developer.openstack.org/api-ref-compute-v2.1.html#lock
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500510 """
511 return self.action(server_id, 'lock', **kwargs)
512
513 def unlock_server(self, server_id, **kwargs):
514 """UNlock the given server.
515
Dong Mad12c2332016-10-19 01:36:27 -0700516 For a full list of available parameters, please refer to the official
517 API reference:
518 http://developer.openstack.org/api-ref-compute-v2.1.html#unlock
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500519 """
520 return self.action(server_id, 'unlock', **kwargs)
521
522 def suspend_server(self, server_id, **kwargs):
523 """Suspend the provided server.
524
Dong Mad12c2332016-10-19 01:36:27 -0700525 For a full list of available parameters, please refer to the official
526 API reference:
527 http://developer.openstack.org/api-ref-compute-v2.1.html#suspend
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500528 """
529 return self.action(server_id, 'suspend', **kwargs)
530
531 def resume_server(self, server_id, **kwargs):
532 """Un-suspend the provided server.
533
Dong Mad12c2332016-10-19 01:36:27 -0700534 For a full list of available parameters, please refer to the official
535 API reference:
536 http://developer.openstack.org/api-ref-compute-v2.1.html#resume
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500537 """
538 return self.action(server_id, 'resume', **kwargs)
539
540 def pause_server(self, server_id, **kwargs):
541 """Pause the provided server.
542
Dong Mad12c2332016-10-19 01:36:27 -0700543 For a full list of available parameters, please refer to the official
544 API reference:
545 http://developer.openstack.org/api-ref-compute-v2.1.html#pause
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500546 """
547 return self.action(server_id, 'pause', **kwargs)
548
549 def unpause_server(self, server_id, **kwargs):
550 """Un-pause the provided server.
551
Dong Mad12c2332016-10-19 01:36:27 -0700552 For a full list of available parameters, please refer to the official
553 API reference:
554 http://developer.openstack.org/api-ref-compute-v2.1.html#unpause
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500555 """
556 return self.action(server_id, 'unpause', **kwargs)
557
558 def reset_state(self, server_id, **kwargs):
559 """Reset the state of a server to active/error.
560
Dong Mad12c2332016-10-19 01:36:27 -0700561 For a full list of available parameters, please refer to the official
562 API reference:
563 http://developer.openstack.org/api-ref-compute-v2.1.html#resetState
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500564 """
565 return self.action(server_id, 'os-resetState', **kwargs)
566
567 def shelve_server(self, server_id, **kwargs):
568 """Shelve the provided server.
569
Dong Mad12c2332016-10-19 01:36:27 -0700570 For a full list of available parameters, please refer to the official
571 API reference:
572 http://developer.openstack.org/api-ref-compute-v2.1.html#shelve
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500573 """
574 return self.action(server_id, 'shelve', **kwargs)
575
576 def unshelve_server(self, server_id, **kwargs):
577 """Un-shelve the provided server.
578
Dong Mad12c2332016-10-19 01:36:27 -0700579 For a full list of available parameters, please refer to the official
580 API reference:
581 http://developer.openstack.org/api-ref-compute-v2.1.html#unshelve
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500582 """
583 return self.action(server_id, 'unshelve', **kwargs)
584
585 def shelve_offload_server(self, server_id, **kwargs):
586 """Shelve-offload the provided server.
587
Dong Mad12c2332016-10-19 01:36:27 -0700588 For a full list of available parameters, please refer to the official
589 API reference:
590 http://developer.openstack.org/api-ref-compute-v2.1.html#shelveOffload
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500591 """
592 return self.action(server_id, 'shelveOffload', **kwargs)
593
594 def get_console_output(self, server_id, **kwargs):
595 """Get console output.
596
Dong Mad12c2332016-10-19 01:36:27 -0700597 For a full list of available parameters, please refer to the official
598 API reference:
599 http://developer.openstack.org/api-ref-compute-v2.1.html#getConsoleOutput
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500600 """
601 return self.action(server_id, 'os-getConsoleOutput',
602 schema.get_console_output, **kwargs)
603
604 def list_virtual_interfaces(self, server_id):
605 """List the virtual interfaces used in an instance."""
606 resp, body = self.get('/'.join(['servers', server_id,
607 'os-virtual-interfaces']))
608 body = json.loads(body)
609 self.validate_response(schema.list_virtual_interfaces, resp, body)
610 return rest_client.ResponseBody(resp, body)
611
612 def rescue_server(self, server_id, **kwargs):
613 """Rescue the provided server.
614
Dong Mad12c2332016-10-19 01:36:27 -0700615 For a full list of available parameters, please refer to the official
616 API reference:
617 http://developer.openstack.org/api-ref-compute-v2.1.html#rescue
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500618 """
619 return self.action(server_id, 'rescue', schema.rescue_server, **kwargs)
620
621 def unrescue_server(self, server_id):
Lv Fumei7e326332016-07-08 15:18:03 +0800622 """Unrescue the provided server.
623
Dong Mad12c2332016-10-19 01:36:27 -0700624 For a full list of available parameters, please refer to the official
625 API reference:
626 http://developer.openstack.org/api-ref-compute-v2.1.html#unrescue
Lv Fumei7e326332016-07-08 15:18:03 +0800627 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500628 return self.action(server_id, 'unrescue')
629
630 def show_server_diagnostics(self, server_id):
631 """Get the usage data for a server."""
632 resp, body = self.get("servers/%s/diagnostics" % server_id)
633 return rest_client.ResponseBody(resp, json.loads(body))
634
635 def list_instance_actions(self, server_id):
636 """List the provided server action."""
637 resp, body = self.get("servers/%s/os-instance-actions" %
638 server_id)
639 body = json.loads(body)
640 self.validate_response(schema.list_instance_actions, resp, body)
641 return rest_client.ResponseBody(resp, body)
642
643 def show_instance_action(self, server_id, request_id):
644 """Returns the action details of the provided server."""
645 resp, body = self.get("servers/%s/os-instance-actions/%s" %
646 (server_id, request_id))
647 body = json.loads(body)
648 self.validate_response(schema.show_instance_action, resp, body)
649 return rest_client.ResponseBody(resp, body)
650
651 def force_delete_server(self, server_id, **kwargs):
652 """Force delete a server.
653
Dong Mad12c2332016-10-19 01:36:27 -0700654 For a full list of available parameters, please refer to the official
655 API reference:
656 http://developer.openstack.org/api-ref-compute-v2.1.html#forceDelete
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500657 """
658 return self.action(server_id, 'forceDelete', **kwargs)
659
660 def restore_soft_deleted_server(self, server_id, **kwargs):
661 """Restore a soft-deleted server.
662
Dong Mad12c2332016-10-19 01:36:27 -0700663 For a full list of available parameters, please refer to the official
664 API reference:
665 http://developer.openstack.org/api-ref-compute-v2.1.html#restore
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500666 """
667 return self.action(server_id, 'restore', **kwargs)
668
669 def reset_network(self, server_id, **kwargs):
670 """Reset the Network of a server.
671
Dong Mad12c2332016-10-19 01:36:27 -0700672 For a full list of available parameters, please refer to the official
673 API reference:
674 http://developer.openstack.org/api-ref-compute-v2.1.html#resetNetwork
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500675 """
676 return self.action(server_id, 'resetNetwork', **kwargs)
677
678 def inject_network_info(self, server_id, **kwargs):
679 """Inject the Network Info into server.
680
Dong Mad12c2332016-10-19 01:36:27 -0700681 For a full list of available parameters, please refer to the official
682 API reference:
683 http://developer.openstack.org/api-ref-compute-v2.1.html#injectNetworkInfo
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500684 """
685 return self.action(server_id, 'injectNetworkInfo', **kwargs)
686
687 def get_vnc_console(self, server_id, **kwargs):
688 """Get URL of VNC console.
689
Dong Mad12c2332016-10-19 01:36:27 -0700690 For a full list of available parameters, please refer to the official
691 API reference:
692 http://developer.openstack.org/api-ref-compute-v2.1.html#getVNCConsole
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500693 """
694 return self.action(server_id, "os-getVNCConsole",
695 schema.get_vnc_console, **kwargs)
696
697 def add_fixed_ip(self, server_id, **kwargs):
698 """Add a fixed IP to server instance.
699
Dong Mad12c2332016-10-19 01:36:27 -0700700 For a full list of available parameters, please refer to the official
701 API reference:
702 http://developer.openstack.org/api-ref-compute-v2.1.html#addFixedIp
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500703 """
704 return self.action(server_id, 'addFixedIp', **kwargs)
705
706 def remove_fixed_ip(self, server_id, **kwargs):
707 """Remove input fixed IP from input server instance.
708
Dong Mad12c2332016-10-19 01:36:27 -0700709 For a full list of available parameters, please refer to the official
710 API reference:
711 http://developer.openstack.org/api-ref-compute-v2.1.html#removeFixedIp
Matthew Treinish9e26ca82016-02-23 11:43:20 -0500712 """
713 return self.action(server_id, 'removeFixedIp', **kwargs)