blob: f397c4b5703144e45ea32dc98ecac1da572cb029 [file] [log] [blame]
ivan-zhu09111942013-08-01 08:09:16 +08001# Copyright 2012 OpenStack Foundation
2# Copyright 2013 Hewlett-Packard Development Company, L.P.
ivan-zhu8f992be2013-07-31 14:56:58 +08003# Copyright 2013 IBM Corp
ivan-zhu09111942013-08-01 08:09:16 +08004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import json
19import time
20import urllib
21
Ghanshyam7fa397c2014-04-01 19:32:38 +090022from tempest.api_schema.compute import servers as common_schema
Ken'ichi Ohmichi02604582014-03-14 16:23:41 +090023from tempest.api_schema.compute.v3 import servers as schema
Haiwei Xu16ee2c82014-03-05 04:59:18 +090024from tempest.common import rest_client
ivan-zhu09111942013-08-01 08:09:16 +080025from tempest.common import waiters
Matthew Treinish684d8992014-01-30 16:27:40 +000026from tempest import config
ivan-zhu09111942013-08-01 08:09:16 +080027from tempest import exceptions
28
Matthew Treinish684d8992014-01-30 16:27:40 +000029CONF = config.CONF
30
ivan-zhu09111942013-08-01 08:09:16 +080031
Haiwei Xu16ee2c82014-03-05 04:59:18 +090032class ServersV3ClientJSON(rest_client.RestClient):
ivan-zhu09111942013-08-01 08:09:16 +080033
Andrea Frittoli8bbdb162014-01-06 11:06:13 +000034 def __init__(self, auth_provider):
35 super(ServersV3ClientJSON, self).__init__(auth_provider)
Matthew Treinish684d8992014-01-30 16:27:40 +000036 self.service = CONF.compute.catalog_v3_type
ivan-zhu09111942013-08-01 08:09:16 +080037
38 def create_server(self, name, image_ref, flavor_ref, **kwargs):
39 """
40 Creates an instance of a server.
41 name (Required): The name of the server.
42 image_ref (Required): Reference to the image used to build the server.
43 flavor_ref (Required): The flavor used to build the server.
44 Following optional keyword arguments are accepted:
Ken'ichi Ohmichie985ca82013-11-12 15:10:35 +090045 admin_password: Sets the initial root password.
ivan-zhu09111942013-08-01 08:09:16 +080046 key_name: Key name of keypair that was created earlier.
47 meta: A dictionary of values to be used as metadata.
ivan-zhu09111942013-08-01 08:09:16 +080048 security_groups: A list of security group dicts.
49 networks: A list of network dicts with UUID and fixed_ip.
50 user_data: User data for instance.
51 availability_zone: Availability zone in which to launch instance.
ivan-zhu8f992be2013-07-31 14:56:58 +080052 access_ip_v4: The IPv4 access address for the server.
53 access_ip_v6: The IPv6 access address for the server.
ivan-zhu09111942013-08-01 08:09:16 +080054 min_count: Count of minimum number of instances to launch.
55 max_count: Count of maximum number of instances to launch.
56 disk_config: Determines if user or admin controls disk configuration.
57 return_reservation_id: Enable/Disable the return of reservation id
58 """
59 post_body = {
60 'name': name,
ivan-zhu8f992be2013-07-31 14:56:58 +080061 'image_ref': image_ref,
62 'flavor_ref': flavor_ref
ivan-zhu09111942013-08-01 08:09:16 +080063 }
64
ivan-zhu82094252013-11-21 10:16:11 +080065 for option in ['admin_password', 'key_name', 'networks',
ivan-zhu2ca89b32013-08-07 22:37:32 +080066 ('os-security-groups:security_groups',
67 'security_groups'),
ivan-zhu8f992be2013-07-31 14:56:58 +080068 ('os-user-data:user_data', 'user_data'),
69 ('os-availability-zone:availability_zone',
70 'availability_zone'),
ivan-zhu2ca89b32013-08-07 22:37:32 +080071 ('os-access-ips:access_ip_v4', 'access_ip_v4'),
72 ('os-access-ips:access_ip_v6', 'access_ip_v6'),
ivan-zhu8f992be2013-07-31 14:56:58 +080073 ('os-multiple-create:min_count', 'min_count'),
74 ('os-multiple-create:max_count', 'max_count'),
75 ('metadata', 'meta'),
76 ('os-disk-config:disk_config', 'disk_config'),
77 ('os-multiple-create:return_reservation_id',
Yuiko Takada7835d502014-01-15 10:15:03 +000078 'return_reservation_id')]:
ivan-zhu09111942013-08-01 08:09:16 +080079 if isinstance(option, tuple):
80 post_param = option[0]
81 key = option[1]
82 else:
83 post_param = option
84 key = option
85 value = kwargs.get(key)
86 if value is not None:
87 post_body[post_param] = value
88 post_body = json.dumps({'server': post_body})
vponomaryovf4c27f92014-02-18 10:56:42 +020089 resp, body = self.post('servers', post_body)
ivan-zhu09111942013-08-01 08:09:16 +080090
91 body = json.loads(body)
92 # NOTE(maurosr): this deals with the case of multiple server create
93 # with return reservation id set True
ivan-zhuf0bf3012013-11-25 16:03:42 +080094 if 'servers_reservation' in body:
95 return resp, body['servers_reservation']
Ken'ichi Ohmichi02604582014-03-14 16:23:41 +090096 self.validate_response(schema.create_server, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +080097 return resp, body['server']
98
ivan-zhu8f992be2013-07-31 14:56:58 +080099 def update_server(self, server_id, name=None, meta=None, access_ip_v4=None,
100 access_ip_v6=None, disk_config=None):
ivan-zhu09111942013-08-01 08:09:16 +0800101 """
102 Updates the properties of an existing server.
103 server_id: The id of an existing server.
104 name: The name of the server.
ivan-zhu8f992be2013-07-31 14:56:58 +0800105 access_ip_v4: The IPv4 access address for the server.
106 access_ip_v6: The IPv6 access address for the server.
ivan-zhu09111942013-08-01 08:09:16 +0800107 """
108
109 post_body = {}
110
111 if meta is not None:
112 post_body['metadata'] = meta
113
114 if name is not None:
115 post_body['name'] = name
116
ivan-zhu8f992be2013-07-31 14:56:58 +0800117 if access_ip_v4 is not None:
ivan-zhuf0bf3012013-11-25 16:03:42 +0800118 post_body['os-access-ips:access_ip_v4'] = access_ip_v4
ivan-zhu09111942013-08-01 08:09:16 +0800119
ivan-zhu8f992be2013-07-31 14:56:58 +0800120 if access_ip_v6 is not None:
ivan-zhuf0bf3012013-11-25 16:03:42 +0800121 post_body['os-access-ips:access_ip_v6'] = access_ip_v6
ivan-zhu09111942013-08-01 08:09:16 +0800122
123 if disk_config is not None:
ivan-zhu50969522013-08-26 11:10:39 +0800124 post_body['os-disk-config:disk_config'] = disk_config
ivan-zhu09111942013-08-01 08:09:16 +0800125
126 post_body = json.dumps({'server': post_body})
vponomaryovf4c27f92014-02-18 10:56:42 +0200127 resp, body = self.put("servers/%s" % str(server_id), post_body)
ivan-zhu09111942013-08-01 08:09:16 +0800128 body = json.loads(body)
Ken'ichi Ohmichi29cd5122014-04-28 11:04:52 +0900129 self.validate_response(schema.update_server, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800130 return resp, body['server']
131
132 def get_server(self, server_id):
133 """Returns the details of an existing server."""
134 resp, body = self.get("servers/%s" % str(server_id))
135 body = json.loads(body)
136 return resp, body['server']
137
138 def delete_server(self, server_id):
139 """Deletes the given server."""
Ghanshyam4ac02742014-04-17 19:15:47 +0900140 resp, body = self.delete("servers/%s" % str(server_id))
141 self.validate_response(common_schema.delete_server, resp, body)
142 return resp, body
ivan-zhu09111942013-08-01 08:09:16 +0800143
144 def list_servers(self, params=None):
145 """Lists all servers for a user."""
146
147 url = 'servers'
148 if params:
149 url += '?%s' % urllib.urlencode(params)
150
151 resp, body = self.get(url)
152 body = json.loads(body)
Ghanshyam623c38f2014-04-21 17:16:21 +0900153 self.validate_response(common_schema.list_servers, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800154 return resp, body
155
156 def list_servers_with_detail(self, params=None):
157 """Lists all servers in detail for a user."""
158
159 url = 'servers/detail'
160 if params:
161 url += '?%s' % urllib.urlencode(params)
162
163 resp, body = self.get(url)
164 body = json.loads(body)
165 return resp, body
166
Zhi Kun Liude892722013-12-30 15:27:52 +0800167 def wait_for_server_status(self, server_id, status, extra_timeout=0,
168 raise_on_error=True):
ivan-zhu09111942013-08-01 08:09:16 +0800169 """Waits for a server to reach a given status."""
Ken'ichi Ohmichi39437e22013-10-06 00:21:38 +0900170 return waiters.wait_for_server_status(self, server_id, status,
Zhi Kun Liude892722013-12-30 15:27:52 +0800171 extra_timeout=extra_timeout,
172 raise_on_error=raise_on_error)
ivan-zhu09111942013-08-01 08:09:16 +0800173
174 def wait_for_server_termination(self, server_id, ignore_error=False):
175 """Waits for server to reach termination."""
176 start_time = int(time.time())
177 while True:
178 try:
179 resp, body = self.get_server(server_id)
180 except exceptions.NotFound:
181 return
182
183 server_status = body['status']
184 if server_status == 'ERROR' and not ignore_error:
185 raise exceptions.BuildErrorException(server_id=server_id)
186
187 if int(time.time()) - start_time >= self.build_timeout:
188 raise exceptions.TimeoutException
189
190 time.sleep(self.build_interval)
191
192 def list_addresses(self, server_id):
193 """Lists all addresses for a server."""
194 resp, body = self.get("servers/%s/ips" % str(server_id))
195 body = json.loads(body)
Ghanshyamd847c582014-05-07 16:21:36 +0900196 self.validate_response(schema.list_addresses, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800197 return resp, body['addresses']
198
199 def list_addresses_by_network(self, server_id, network_id):
200 """Lists all addresses of a specific network type for a server."""
201 resp, body = self.get("servers/%s/ips/%s" %
202 (str(server_id), network_id))
203 body = json.loads(body)
Ghanshyam9541ad12014-05-07 16:38:43 +0900204 self.validate_response(schema.list_addresses_by_network, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800205 return resp, body
206
Ghanshyam997c9092014-04-03 19:00:20 +0900207 def action(self, server_id, action_name, response_key,
208 schema=common_schema.server_actions_common_schema, **kwargs):
ivan-zhu09111942013-08-01 08:09:16 +0800209 post_body = json.dumps({action_name: kwargs})
210 resp, body = self.post('servers/%s/action' % str(server_id),
vponomaryovf4c27f92014-02-18 10:56:42 +0200211 post_body)
ivan-zhu09111942013-08-01 08:09:16 +0800212 if response_key is not None:
Ghanshyam7ee264a2014-04-02 16:37:57 +0900213 body = json.loads(body)
214 # Check for Schema as 'None' because if we do not have any server
215 # action schema implemented yet then they can pass 'None' to skip
216 # the validation.Once all server action has their schema
217 # implemented then, this check can be removed if every actions are
218 # supposed to validate their response.
219 # TODO(GMann): Remove the below 'if' check once all server actions
220 # schema are implemented.
221 if schema is not None:
222 self.validate_response(schema, resp, body)
223 body = body[response_key]
Ghanshyam997c9092014-04-03 19:00:20 +0900224 else:
225 self.validate_response(schema, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800226 return resp, body
227
ivan-zhu2ca89b32013-08-07 22:37:32 +0800228 def create_backup(self, server_id, backup_type, rotation, name):
229 """Backup a server instance."""
230 return self.action(server_id, "create_backup", None,
231 backup_type=backup_type,
232 rotation=rotation,
233 name=name)
234
ivan-zhu8f992be2013-07-31 14:56:58 +0800235 def change_password(self, server_id, admin_password):
ivan-zhu09111942013-08-01 08:09:16 +0800236 """Changes the root password for the server."""
Ghanshyam997c9092014-04-03 19:00:20 +0900237 return self.action(server_id, 'change_password',
238 None, schema.server_actions_change_password,
ivan-zhu8f992be2013-07-31 14:56:58 +0800239 admin_password=admin_password)
ivan-zhu09111942013-08-01 08:09:16 +0800240
ivan-zhuaf8c4e62014-01-22 17:09:42 +0800241 def get_password(self, server_id):
242 resp, body = self.get("servers/%s/os-server-password" %
243 str(server_id))
244 body = json.loads(body)
Ghanshyam7fa397c2014-04-01 19:32:38 +0900245 self.validate_response(common_schema.get_password, resp, body)
ivan-zhuaf8c4e62014-01-22 17:09:42 +0800246 return resp, body
247
248 def delete_password(self, server_id):
249 """
250 Removes the encrypted server password from the metadata server
251 Note that this does not actually change the instance server
252 password.
253 """
Ghanshyam997c9092014-04-03 19:00:20 +0900254 resp, body = self.delete("servers/%s/os-server-password" %
255 str(server_id))
256 self.validate_response(common_schema.server_actions_delete_password,
257 resp, body)
258 return resp, body
ivan-zhuaf8c4e62014-01-22 17:09:42 +0800259
ivan-zhu09111942013-08-01 08:09:16 +0800260 def reboot(self, server_id, reboot_type):
261 """Reboots a server."""
262 return self.action(server_id, 'reboot', None, type=reboot_type)
263
264 def rebuild(self, server_id, image_ref, **kwargs):
265 """Rebuilds a server with a new image."""
ivan-zhu8f992be2013-07-31 14:56:58 +0800266 kwargs['image_ref'] = image_ref
ivan-zhu09111942013-08-01 08:09:16 +0800267 if 'disk_config' in kwargs:
ivan-zhu8f992be2013-07-31 14:56:58 +0800268 kwargs['os-disk-config:disk_config'] = kwargs['disk_config']
ivan-zhu09111942013-08-01 08:09:16 +0800269 del kwargs['disk_config']
Ghanshyam7ee264a2014-04-02 16:37:57 +0900270 return self.action(server_id, 'rebuild', 'server', None, **kwargs)
ivan-zhu09111942013-08-01 08:09:16 +0800271
272 def resize(self, server_id, flavor_ref, **kwargs):
273 """Changes the flavor of a server."""
ivan-zhu8f992be2013-07-31 14:56:58 +0800274 kwargs['flavor_ref'] = flavor_ref
ivan-zhu09111942013-08-01 08:09:16 +0800275 if 'disk_config' in kwargs:
ivan-zhu8f992be2013-07-31 14:56:58 +0800276 kwargs['os-disk-config:disk_config'] = kwargs['disk_config']
ivan-zhu09111942013-08-01 08:09:16 +0800277 del kwargs['disk_config']
278 return self.action(server_id, 'resize', None, **kwargs)
279
280 def confirm_resize(self, server_id, **kwargs):
281 """Confirms the flavor change for a server."""
ivan-zhu8f992be2013-07-31 14:56:58 +0800282 return self.action(server_id, 'confirm_resize', None, **kwargs)
ivan-zhu09111942013-08-01 08:09:16 +0800283
284 def revert_resize(self, server_id, **kwargs):
285 """Reverts a server back to its original flavor."""
ivan-zhu8f992be2013-07-31 14:56:58 +0800286 return self.action(server_id, 'revert_resize', None, **kwargs)
ivan-zhu09111942013-08-01 08:09:16 +0800287
ivan-zhu8f992be2013-07-31 14:56:58 +0800288 def create_image(self, server_id, name, meta=None):
289 """Creates an image of the original server."""
290
291 post_body = {
292 'create_image': {
293 'name': name,
294 }
295 }
296
297 if meta is not None:
298 post_body['create_image']['metadata'] = meta
299
300 post_body = json.dumps(post_body)
301 resp, body = self.post('servers/%s/action' % str(server_id),
vponomaryovf4c27f92014-02-18 10:56:42 +0200302 post_body)
ivan-zhu8f992be2013-07-31 14:56:58 +0800303 return resp, body
ivan-zhu09111942013-08-01 08:09:16 +0800304
305 def list_server_metadata(self, server_id):
306 resp, body = self.get("servers/%s/metadata" % str(server_id))
307 body = json.loads(body)
Ghanshyama8f66532014-04-23 17:18:14 +0900308 self.validate_response(common_schema.list_server_metadata, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800309 return resp, body['metadata']
310
311 def set_server_metadata(self, server_id, meta, no_metadata_field=False):
312 if no_metadata_field:
313 post_body = ""
314 else:
315 post_body = json.dumps({'metadata': meta})
316 resp, body = self.put('servers/%s/metadata' % str(server_id),
vponomaryovf4c27f92014-02-18 10:56:42 +0200317 post_body)
ivan-zhu09111942013-08-01 08:09:16 +0800318 body = json.loads(body)
Haiwei Xu3d2b7af2014-04-12 02:50:26 +0900319 self.validate_response(common_schema.set_server_metadata, resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800320 return resp, body['metadata']
321
322 def update_server_metadata(self, server_id, meta):
323 post_body = json.dumps({'metadata': meta})
324 resp, body = self.post('servers/%s/metadata' % str(server_id),
vponomaryovf4c27f92014-02-18 10:56:42 +0200325 post_body)
ivan-zhu09111942013-08-01 08:09:16 +0800326 body = json.loads(body)
327 return resp, body['metadata']
328
329 def get_server_metadata_item(self, server_id, key):
330 resp, body = self.get("servers/%s/metadata/%s" % (str(server_id), key))
331 body = json.loads(body)
Ghanshyameaaa6a42014-04-25 18:38:21 +0900332 self.validate_response(schema.set_get_server_metadata_item,
333 resp, body)
ivan-zhu8f992be2013-07-31 14:56:58 +0800334 return resp, body['metadata']
ivan-zhu09111942013-08-01 08:09:16 +0800335
336 def set_server_metadata_item(self, server_id, key, meta):
ivan-zhu8f992be2013-07-31 14:56:58 +0800337 post_body = json.dumps({'metadata': meta})
ivan-zhu09111942013-08-01 08:09:16 +0800338 resp, body = self.put('servers/%s/metadata/%s' % (str(server_id), key),
vponomaryovf4c27f92014-02-18 10:56:42 +0200339 post_body)
ivan-zhu09111942013-08-01 08:09:16 +0800340 body = json.loads(body)
Ghanshyameaaa6a42014-04-25 18:38:21 +0900341 self.validate_response(schema.set_get_server_metadata_item,
342 resp, body)
ivan-zhu8f992be2013-07-31 14:56:58 +0800343 return resp, body['metadata']
ivan-zhu09111942013-08-01 08:09:16 +0800344
345 def delete_server_metadata_item(self, server_id, key):
346 resp, body = self.delete("servers/%s/metadata/%s" %
347 (str(server_id), key))
Ghanshyameaaa6a42014-04-25 18:38:21 +0900348 self.validate_response(common_schema.delete_server_metadata_item,
349 resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800350 return resp, body
351
352 def stop(self, server_id, **kwargs):
ivan-zhu8f992be2013-07-31 14:56:58 +0800353 return self.action(server_id, 'stop', None, **kwargs)
ivan-zhu09111942013-08-01 08:09:16 +0800354
355 def start(self, server_id, **kwargs):
ivan-zhu8f992be2013-07-31 14:56:58 +0800356 return self.action(server_id, 'start', None, **kwargs)
ivan-zhu09111942013-08-01 08:09:16 +0800357
358 def attach_volume(self, server_id, volume_id, device='/dev/vdz'):
359 """Attaches a volume to a server instance."""
Ghanshyam385c4e72014-03-27 11:42:25 +0900360 resp, body = self.action(server_id, 'attach', None,
361 volume_id=volume_id, device=device)
362 self.validate_response(schema.attach_detach_volume, resp, body)
363 return resp, body
ivan-zhu09111942013-08-01 08:09:16 +0800364
365 def detach_volume(self, server_id, volume_id):
366 """Detaches a volume from a server instance."""
Ghanshyam385c4e72014-03-27 11:42:25 +0900367 resp, body = self.action(server_id, 'detach', None,
368 volume_id=volume_id)
369 self.validate_response(schema.attach_detach_volume, resp, body)
370 return resp, body
ivan-zhu09111942013-08-01 08:09:16 +0800371
ivan-zhu09111942013-08-01 08:09:16 +0800372 def live_migrate_server(self, server_id, dest_host, use_block_migration):
373 """This should be called with administrator privileges ."""
374
375 migrate_params = {
376 "disk_over_commit": False,
377 "block_migration": use_block_migration,
378 "host": dest_host
379 }
380
ivan-zhu8f992be2013-07-31 14:56:58 +0800381 req_body = json.dumps({'migrate_live': migrate_params})
ivan-zhu09111942013-08-01 08:09:16 +0800382
383 resp, body = self.post("servers/%s/action" % str(server_id),
vponomaryovf4c27f92014-02-18 10:56:42 +0200384 req_body)
Ghanshyam997c9092014-04-03 19:00:20 +0900385 self.validate_response(common_schema.server_actions_common_schema,
386 resp, body)
ivan-zhu09111942013-08-01 08:09:16 +0800387 return resp, body
388
389 def migrate_server(self, server_id, **kwargs):
390 """Migrates a server to a new host."""
391 return self.action(server_id, 'migrate', None, **kwargs)
392
393 def lock_server(self, server_id, **kwargs):
394 """Locks the given server."""
395 return self.action(server_id, 'lock', None, **kwargs)
396
397 def unlock_server(self, server_id, **kwargs):
398 """UNlocks the given server."""
399 return self.action(server_id, 'unlock', None, **kwargs)
400
401 def suspend_server(self, server_id, **kwargs):
Zhi Kun Liude892722013-12-30 15:27:52 +0800402 """Suspends the provided server."""
ivan-zhu09111942013-08-01 08:09:16 +0800403 return self.action(server_id, 'suspend', None, **kwargs)
404
405 def resume_server(self, server_id, **kwargs):
Zhi Kun Liude892722013-12-30 15:27:52 +0800406 """Un-suspends the provided server."""
ivan-zhu09111942013-08-01 08:09:16 +0800407 return self.action(server_id, 'resume', None, **kwargs)
408
409 def pause_server(self, server_id, **kwargs):
Zhi Kun Liude892722013-12-30 15:27:52 +0800410 """Pauses the provided server."""
ivan-zhu09111942013-08-01 08:09:16 +0800411 return self.action(server_id, 'pause', None, **kwargs)
412
413 def unpause_server(self, server_id, **kwargs):
Zhi Kun Liude892722013-12-30 15:27:52 +0800414 """Un-pauses the provided server."""
ivan-zhu09111942013-08-01 08:09:16 +0800415 return self.action(server_id, 'unpause', None, **kwargs)
416
417 def reset_state(self, server_id, state='error'):
418 """Resets the state of a server to active/error."""
ivan-zhu8f992be2013-07-31 14:56:58 +0800419 return self.action(server_id, 'reset_state', None, state=state)
ivan-zhu09111942013-08-01 08:09:16 +0800420
ivan-zhu2ca89b32013-08-07 22:37:32 +0800421 def shelve_server(self, server_id, **kwargs):
422 """Shelves the provided server."""
423 return self.action(server_id, 'shelve', None, **kwargs)
424
425 def unshelve_server(self, server_id, **kwargs):
426 """Un-shelves the provided server."""
427 return self.action(server_id, 'unshelve', None, **kwargs)
428
Ken'ichi Ohmichi17b7f112014-02-20 06:33:49 +0900429 def shelve_offload_server(self, server_id, **kwargs):
430 """Shelve-offload the provided server."""
431 return self.action(server_id, 'shelve_offload', None, **kwargs)
432
ivan-zhu09111942013-08-01 08:09:16 +0800433 def get_console_output(self, server_id, length):
ivan-zhu8f992be2013-07-31 14:56:58 +0800434 return self.action(server_id, 'get_console_output', 'output',
Ghanshyam7ee264a2014-04-02 16:37:57 +0900435 common_schema.get_console_output, length=length)
ivan-zhu09111942013-08-01 08:09:16 +0800436
Yuiko Takada7835d502014-01-15 10:15:03 +0000437 def rescue_server(self, server_id, **kwargs):
ivan-zhu09111942013-08-01 08:09:16 +0800438 """Rescue the provided server."""
Ghanshyam7ee264a2014-04-02 16:37:57 +0900439 return self.action(server_id, 'rescue', 'admin_password',
440 None, **kwargs)
ivan-zhu09111942013-08-01 08:09:16 +0800441
442 def unrescue_server(self, server_id):
443 """Unrescue the provided server."""
444 return self.action(server_id, 'unrescue', None)
445
446 def get_server_diagnostics(self, server_id):
447 """Get the usage data for a server."""
ivan-zhu8f992be2013-07-31 14:56:58 +0800448 resp, body = self.get("servers/%s/os-server-diagnostics" %
449 str(server_id))
ivan-zhu09111942013-08-01 08:09:16 +0800450 return resp, json.loads(body)
451
Rohan Kanade8ac8c972014-04-09 07:35:56 +0200452 def list_server_actions(self, server_id):
ivan-zhu09111942013-08-01 08:09:16 +0800453 """List the provided server action."""
Rohan Kanade8ac8c972014-04-09 07:35:56 +0200454 resp, body = self.get("servers/%s/os-server-actions" %
ivan-zhu09111942013-08-01 08:09:16 +0800455 str(server_id))
456 body = json.loads(body)
Rohan Kanade8ac8c972014-04-09 07:35:56 +0200457 return resp, body['server_actions']
ivan-zhu09111942013-08-01 08:09:16 +0800458
Rohan Kanade8ac8c972014-04-09 07:35:56 +0200459 def get_server_action(self, server_id, request_id):
ivan-zhu09111942013-08-01 08:09:16 +0800460 """Returns the action details of the provided server."""
Rohan Kanade8ac8c972014-04-09 07:35:56 +0200461 resp, body = self.get("servers/%s/os-server-actions/%s" %
ivan-zhu09111942013-08-01 08:09:16 +0800462 (str(server_id), str(request_id)))
463 body = json.loads(body)
Rohan Kanade8ac8c972014-04-09 07:35:56 +0200464 return resp, body['server_action']
ivan-zhu2ca89b32013-08-07 22:37:32 +0800465
466 def force_delete_server(self, server_id, **kwargs):
467 """Force delete a server."""
468 return self.action(server_id, 'force_delete', None, **kwargs)
469
470 def restore_soft_deleted_server(self, server_id, **kwargs):
471 """Restore a soft-deleted server."""
472 return self.action(server_id, 'restore', None, **kwargs)
Ghanshyam Mann41c17572014-02-27 18:52:56 +0900473
474 def get_vnc_console(self, server_id, type):
475 """Get URL of VNC console."""
476 post_body = json.dumps({
477 "get_vnc_console": {
478 "type": type
479 }
480 })
481 resp, body = self.post('servers/%s/action' % str(server_id),
482 post_body)
483 body = json.loads(body)
Ghanshyamd6d30402014-04-02 15:28:37 +0900484 self.validate_response(common_schema.get_vnc_console, resp, body)
Ghanshyam Mann41c17572014-02-27 18:52:56 +0900485 return resp, body['console']
Ghanshyam0549f7b2014-03-04 19:07:52 +0900486
487 def reset_network(self, server_id, **kwargs):
488 """Resets the Network of a server"""
489 return self.action(server_id, 'reset_network', None, **kwargs)
490
491 def inject_network_info(self, server_id, **kwargs):
492 """Inject the Network Info into server"""
493 return self.action(server_id, 'inject_network_info', None, **kwargs)
Ghanshyam70876d02014-03-11 11:40:18 +0900494
495 def get_spice_console(self, server_id, console_type):
496 """Get URL of Spice console."""
497 return self.action(server_id, "get_spice_console"
Ghanshyam7ee264a2014-04-02 16:37:57 +0900498 "console", None, type=console_type)
Ghanshyam70876d02014-03-11 11:40:18 +0900499
500 def get_rdp_console(self, server_id, console_type):
501 """Get URL of RDP console."""
502 return self.action(server_id, "get_rdp_console"
Ghanshyam7ee264a2014-04-02 16:37:57 +0900503 "console", None, type=console_type)