blob: 55a4a1b9922d982fd371db22d36bc6aa8263f7c2 [file] [log] [blame]
dwallecke62b9f02012-10-10 23:34:42 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
nithya-ganesane6a36c82013-02-15 14:38:27 +00004# Copyright 2013 Hewlett-Packard Development Company, L.P.
dwallecke62b9f02012-10-10 23:34:42 -05005# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
Daryl Wallecke5b83d42011-11-10 14:39:02 -060019import json
Daryl Wallecke5b83d42011-11-10 14:39:02 -060020import time
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050021import urllib
Daryl Wallecke5b83d42011-11-10 14:39:02 -060022
Matthew Treinisha83a16e2012-12-07 13:44:02 -050023from tempest.common.rest_client import RestClient
Attila Fazekas0abbc952013-07-01 19:19:42 +020024from tempest.common import waiters
Matthew Treinisha83a16e2012-12-07 13:44:02 -050025from tempest import exceptions
26
Daryl Wallecke5b83d42011-11-10 14:39:02 -060027
Dan Smithcf8fab62012-08-14 08:03:48 -070028class ServersClientJSON(RestClient):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060029
Brant Knudsonc7ca3342013-03-28 21:08:50 -050030 def __init__(self, config, username, password, auth_url, tenant_name=None,
31 auth_version='v2'):
Dan Smithcf8fab62012-08-14 08:03:48 -070032 super(ServersClientJSON, self).__init__(config, username, password,
Brant Knudsonc7ca3342013-03-28 21:08:50 -050033 auth_url, tenant_name,
34 auth_version=auth_version)
chris fattarsi5098fa22012-04-17 13:27:00 -070035 self.service = self.config.compute.catalog_type
Daryl Wallecke5b83d42011-11-10 14:39:02 -060036
Rohit Karajgi95446a22011-12-12 06:21:43 -080037 def create_server(self, name, image_ref, flavor_ref, **kwargs):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060038 """
39 Creates an instance of a server.
Rohit Karajgi95446a22011-12-12 06:21:43 -080040 name (Required): The name of the server.
41 image_ref (Required): Reference to the image used to build the server.
42 flavor_ref (Required): The flavor used to build the server.
43 Following optional keyword arguments are accepted:
Daryl Wallecke5b83d42011-11-10 14:39:02 -060044 adminPass: Sets the initial root password.
chris fattarsia6c2a732012-05-02 17:00:19 -070045 key_name: Key name of keypair that was created earlier.
David Kranz28e79de2012-04-12 15:49:41 -040046 meta: A dictionary of values to be used as metadata.
Daryl Wallecke5b83d42011-11-10 14:39:02 -060047 personality: A list of dictionaries for files to be injected into
48 the server.
Rohit Karajgi95446a22011-12-12 06:21:43 -080049 security_groups: A list of security group dicts.
50 networks: A list of network dicts with UUID and fixed_ip.
51 user_data: User data for instance.
52 availability_zone: Availability zone in which to launch instance.
Daryl Wallecke5b83d42011-11-10 14:39:02 -060053 accessIPv4: The IPv4 access address for the server.
54 accessIPv6: The IPv6 access address for the server.
Rohit Karajgi95446a22011-12-12 06:21:43 -080055 min_count: Count of minimum number of instances to launch.
56 max_count: Count of maximum number of instances to launch.
Daryl Wallecke36d5002012-03-28 09:56:10 -050057 disk_config: Determines if user or admin controls disk configuration.
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050058 return_reservation_id: Enable/Disable the return of reservation id
Daryl Wallecke5b83d42011-11-10 14:39:02 -060059 """
Daryl Wallecke5b83d42011-11-10 14:39:02 -060060 post_body = {
61 'name': name,
62 'imageRef': image_ref,
David Kranz28e79de2012-04-12 15:49:41 -040063 'flavorRef': flavor_ref
Daryl Wallecke5b83d42011-11-10 14:39:02 -060064 }
65
chris fattarsia6c2a732012-05-02 17:00:19 -070066 for option in ['personality', 'adminPass', 'key_name',
Zhongyue Luoe0884a32012-09-25 17:24:17 +080067 'security_groups', 'networks', 'user_data',
68 'availability_zone', 'accessIPv4', 'accessIPv6',
69 'min_count', 'max_count', ('metadata', 'meta'),
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050070 ('OS-DCF:diskConfig', 'disk_config'),
71 'return_reservation_id']:
David Kranz28e79de2012-04-12 15:49:41 -040072 if isinstance(option, tuple):
73 post_param = option[0]
74 key = option[1]
75 else:
76 post_param = option
77 key = option
78 value = kwargs.get(key)
Zhongyue Luoe471d6e2012-09-17 17:02:43 +080079 if value is not None:
David Kranz28e79de2012-04-12 15:49:41 -040080 post_body[post_param] = value
Daryl Wallecke5b83d42011-11-10 14:39:02 -060081 post_body = json.dumps({'server': post_body})
chris fattarsi5098fa22012-04-17 13:27:00 -070082 resp, body = self.post('servers', post_body, self.headers)
Jay Pipes5135bfc2012-01-05 15:46:49 -050083
Daryl Wallecke5b83d42011-11-10 14:39:02 -060084 body = json.loads(body)
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050085 # NOTE(maurosr): this deals with the case of multiple server create
86 # with return reservation id set True
87 if 'reservation_id' in body:
88 return resp, body
Daryl Wallecke5b83d42011-11-10 14:39:02 -060089 return resp, body['server']
90
91 def update_server(self, server_id, name=None, meta=None, accessIPv4=None,
ivan-zhu72d7d5b2013-10-16 17:30:58 +080092 accessIPv6=None, disk_config=None):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060093 """
94 Updates the properties of an existing server.
95 server_id: The id of an existing server.
96 name: The name of the server.
97 personality: A list of files to be injected into the server.
98 accessIPv4: The IPv4 access address for the server.
99 accessIPv6: The IPv6 access address for the server.
100 """
101
102 post_body = {}
103
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800104 if meta is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600105 post_body['metadata'] = meta
106
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800107 if name is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600108 post_body['name'] = name
109
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800110 if accessIPv4 is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600111 post_body['accessIPv4'] = accessIPv4
112
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800113 if accessIPv6 is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600114 post_body['accessIPv6'] = accessIPv6
115
ivan-zhu72d7d5b2013-10-16 17:30:58 +0800116 if disk_config is not None:
117 post_body['OS-DCF:diskConfig'] = disk_config
118
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600119 post_body = json.dumps({'server': post_body})
chris fattarsi5098fa22012-04-17 13:27:00 -0700120 resp, body = self.put("servers/%s" % str(server_id),
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800121 post_body, self.headers)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600122 body = json.loads(body)
123 return resp, body['server']
124
125 def get_server(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500126 """Returns the details of an existing server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700127 resp, body = self.get("servers/%s" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600128 body = json.loads(body)
129 return resp, body['server']
130
131 def delete_server(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500132 """Deletes the given server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700133 return self.delete("servers/%s" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600134
135 def list_servers(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500136 """Lists all servers for a user."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600137
138 url = 'servers'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -0500139 if params:
140 url += '?%s' % urllib.urlencode(params)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600141
chris fattarsi5098fa22012-04-17 13:27:00 -0700142 resp, body = self.get(url)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600143 body = json.loads(body)
144 return resp, body
145
146 def list_servers_with_detail(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500147 """Lists all servers in detail for a user."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600148
149 url = 'servers/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -0500150 if params:
151 url += '?%s' % urllib.urlencode(params)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600152
chris fattarsi5098fa22012-04-17 13:27:00 -0700153 resp, body = self.get(url)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600154 body = json.loads(body)
155 return resp, body
156
157 def wait_for_server_status(self, server_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500158 """Waits for a server to reach a given status."""
Attila Fazekas0abbc952013-07-01 19:19:42 +0200159 return waiters.wait_for_server_status(self, server_id, status)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600160
Jay Pipes051075a2012-04-28 17:39:37 -0400161 def wait_for_server_termination(self, server_id, ignore_error=False):
Sean Daguef237ccb2013-01-04 15:19:14 -0500162 """Waits for server to reach termination."""
Rohit Karajgi4a64d232012-05-17 07:44:37 -0700163 start_time = int(time.time())
164 while True:
165 try:
166 resp, body = self.get_server(server_id)
167 except exceptions.NotFound:
168 return
169
170 server_status = body['status']
Jay Pipes051075a2012-04-28 17:39:37 -0400171 if server_status == 'ERROR' and not ignore_error:
Jay Pipes444c3e62012-10-04 19:26:35 -0400172 raise exceptions.BuildErrorException(server_id=server_id)
Rohit Karajgi4a64d232012-05-17 07:44:37 -0700173
174 if int(time.time()) - start_time >= self.build_timeout:
175 raise exceptions.TimeoutException
176
177 time.sleep(self.build_interval)
178
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600179 def list_addresses(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500180 """Lists all addresses for a server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700181 resp, body = self.get("servers/%s/ips" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600182 body = json.loads(body)
183 return resp, body['addresses']
184
185 def list_addresses_by_network(self, server_id, network_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500186 """Lists all addresses of a specific network type for a server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700187 resp, body = self.get("servers/%s/ips/%s" %
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800188 (str(server_id), network_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600189 body = json.loads(body)
190 return resp, body
191
Attila Fazekasd4299282013-02-22 13:25:23 +0100192 def action(self, server_id, action_name, response_key, **kwargs):
193 post_body = json.dumps({action_name: kwargs})
194 resp, body = self.post('servers/%s/action' % str(server_id),
195 post_body, self.headers)
196 if response_key is not None:
197 body = json.loads(body)[response_key]
198 return resp, body
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600199
Attila Fazekasd4299282013-02-22 13:25:23 +0100200 def change_password(self, server_id, adminPass):
201 """Changes the root password for the server."""
202 return self.action(server_id, 'changePassword', None,
203 adminPass=adminPass)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600204
205 def reboot(self, server_id, reboot_type):
Sean Daguef237ccb2013-01-04 15:19:14 -0500206 """Reboots a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100207 return self.action(server_id, 'reboot', None, type=reboot_type)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600208
Attila Fazekasd4299282013-02-22 13:25:23 +0100209 def rebuild(self, server_id, image_ref, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500210 """Rebuilds a server with a new image."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100211 kwargs['imageRef'] = image_ref
212 if 'disk_config' in kwargs:
213 kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
214 del kwargs['disk_config']
215 return self.action(server_id, 'rebuild', 'server', **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600216
Attila Fazekasd4299282013-02-22 13:25:23 +0100217 def resize(self, server_id, flavor_ref, **kwargs):
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600218 """Changes the flavor of a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100219 kwargs['flavorRef'] = flavor_ref
220 if 'disk_config' in kwargs:
221 kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
222 del kwargs['disk_config']
223 return self.action(server_id, 'resize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600224
Attila Fazekasd4299282013-02-22 13:25:23 +0100225 def confirm_resize(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500226 """Confirms the flavor change for a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100227 return self.action(server_id, 'confirmResize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600228
Attila Fazekasd4299282013-02-22 13:25:23 +0100229 def revert_resize(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500230 """Reverts a server back to its original flavor."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100231 return self.action(server_id, 'revertResize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600232
Attila Fazekasd4299282013-02-22 13:25:23 +0100233 def create_image(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500234 """Creates an image of the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100235 return self.action(server_id, 'createImage', None, name=name)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600236
237 def list_server_metadata(self, server_id):
chris fattarsi5098fa22012-04-17 13:27:00 -0700238 resp, body = self.get("servers/%s/metadata" % str(server_id))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600239 body = json.loads(body)
240 return resp, body['metadata']
241
Chris Yeohd0b52e72013-09-17 22:38:59 +0930242 def set_server_metadata(self, server_id, meta, no_metadata_field=False):
243 if no_metadata_field:
244 post_body = ""
245 else:
246 post_body = json.dumps({'metadata': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800247 resp, body = self.put('servers/%s/metadata' % str(server_id),
248 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600249 body = json.loads(body)
250 return resp, body['metadata']
251
252 def update_server_metadata(self, server_id, meta):
253 post_body = json.dumps({'metadata': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800254 resp, body = self.post('servers/%s/metadata' % str(server_id),
255 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600256 body = json.loads(body)
257 return resp, body['metadata']
258
259 def get_server_metadata_item(self, server_id, key):
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800260 resp, body = self.get("servers/%s/metadata/%s" % (str(server_id), key))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600261 body = json.loads(body)
262 return resp, body['meta']
263
264 def set_server_metadata_item(self, server_id, key, meta):
265 post_body = json.dumps({'meta': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800266 resp, body = self.put('servers/%s/metadata/%s' % (str(server_id), key),
267 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600268 body = json.loads(body)
269 return resp, body['meta']
270
271 def delete_server_metadata_item(self, server_id, key):
chris fattarsi5098fa22012-04-17 13:27:00 -0700272 resp, body = self.delete("servers/%s/metadata/%s" %
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800273 (str(server_id), key))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600274 return resp, body
Dan Smithc18d8c62012-07-02 08:09:26 -0700275
Attila Fazekasd4299282013-02-22 13:25:23 +0100276 def stop(self, server_id, **kwargs):
277 return self.action(server_id, 'os-stop', None, **kwargs)
Dan Smithc18d8c62012-07-02 08:09:26 -0700278
Attila Fazekasd4299282013-02-22 13:25:23 +0100279 def start(self, server_id, **kwargs):
280 return self.action(server_id, 'os-start', None, **kwargs)
Dan Smithc18d8c62012-07-02 08:09:26 -0700281
282 def attach_volume(self, server_id, volume_id, device='/dev/vdz'):
Sean Daguef237ccb2013-01-04 15:19:14 -0500283 """Attaches a volume to a server instance."""
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900284 post_body = json.dumps({
285 'volumeAttachment': {
286 'volumeId': volume_id,
287 'device': device,
288 }
289 })
Dan Smithc18d8c62012-07-02 08:09:26 -0700290 resp, body = self.post('servers/%s/os-volume_attachments' % server_id,
291 post_body, self.headers)
292 return resp, body
293
294 def detach_volume(self, server_id, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500295 """Detaches a volume from a server instance."""
Dan Smithc18d8c62012-07-02 08:09:26 -0700296 resp, body = self.delete('servers/%s/os-volume_attachments/%s' %
297 (server_id, volume_id))
298 return resp, body
sapan-kona775cf632012-06-22 00:32:36 +0530299
Attila Fazekasd4299282013-02-22 13:25:23 +0100300 def add_security_group(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500301 """Adds a security group to the server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100302 return self.action(server_id, 'addSecurityGroup', None, name=name)
sapan-kona775cf632012-06-22 00:32:36 +0530303
Attila Fazekasd4299282013-02-22 13:25:23 +0100304 def remove_security_group(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500305 """Removes a security group from the server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100306 return self.action(server_id, 'removeSecurityGroup', None, name=name)
Mate Lakat99ee9142012-09-14 12:34:46 +0100307
308 def live_migrate_server(self, server_id, dest_host, use_block_migration):
Sean Daguef237ccb2013-01-04 15:19:14 -0500309 """This should be called with administrator privileges ."""
Mate Lakat99ee9142012-09-14 12:34:46 +0100310
311 migrate_params = {
312 "disk_over_commit": False,
313 "block_migration": use_block_migration,
314 "host": dest_host
315 }
316
317 req_body = json.dumps({'os-migrateLive': migrate_params})
318
319 resp, body = self.post("servers/%s/action" % str(server_id),
320 req_body, self.headers)
321 return resp, body
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600322
Attila Fazekasd4299282013-02-22 13:25:23 +0100323 def migrate_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500324 """Migrates a server to a new host."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100325 return self.action(server_id, 'migrate', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600326
Attila Fazekasd4299282013-02-22 13:25:23 +0100327 def lock_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500328 """Locks the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100329 return self.action(server_id, 'lock', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600330
Attila Fazekasd4299282013-02-22 13:25:23 +0100331 def unlock_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500332 """UNlocks the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100333 return self.action(server_id, 'unlock', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600334
Attila Fazekasd4299282013-02-22 13:25:23 +0100335 def suspend_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500336 """Suspends the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100337 return self.action(server_id, 'suspend', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600338
Attila Fazekasd4299282013-02-22 13:25:23 +0100339 def resume_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500340 """Un-suspends the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100341 return self.action(server_id, 'resume', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600342
Attila Fazekasd4299282013-02-22 13:25:23 +0100343 def pause_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500344 """Pauses the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100345 return self.action(server_id, 'pause', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600346
Attila Fazekasd4299282013-02-22 13:25:23 +0100347 def unpause_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500348 """Un-pauses the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100349 return self.action(server_id, 'unpause', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600350
Attila Fazekasd4299282013-02-22 13:25:23 +0100351 def reset_state(self, server_id, state='error'):
Sean Daguef237ccb2013-01-04 15:19:14 -0500352 """Resets the state of a server to active/error."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100353 return self.action(server_id, 'os-resetState', None, state=state)
Attila Fazekase4cb04c2013-01-29 09:51:58 +0100354
355 def get_console_output(self, server_id, length):
Attila Fazekasd4299282013-02-22 13:25:23 +0100356 return self.action(server_id, 'os-getConsoleOutput', 'output',
357 length=length)
Rami Vaknin76bc8bd2013-02-17 16:18:27 +0200358
359 def list_virtual_interfaces(self, server_id):
360 """
361 List the virtual interfaces used in an instance.
362 """
363 resp, body = self.get('/'.join(['servers', server_id,
364 'os-virtual-interfaces']))
365 return resp, json.loads(body)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000366
367 def rescue_server(self, server_id, adminPass=None):
368 """Rescue the provided server."""
369 return self.action(server_id, 'rescue', None, adminPass=adminPass)
370
371 def unrescue_server(self, server_id):
372 """Unrescue the provided server."""
373 return self.action(server_id, 'unrescue', None)
Leo Toyodafaca6ff2013-04-22 16:52:53 +0900374
Zhu Zhuda070852013-09-25 08:07:57 -0500375 def get_server_diagnostics(self, server_id):
376 """Get the usage data for a server."""
377 resp, body = self.get("servers/%s/diagnostics" % str(server_id))
378 return resp, json.loads(body)
379
Leo Toyodafaca6ff2013-04-22 16:52:53 +0900380 def list_instance_actions(self, server_id):
381 """List the provided server action."""
382 resp, body = self.get("servers/%s/os-instance-actions" %
383 str(server_id))
384 body = json.loads(body)
385 return resp, body['instanceActions']
386
387 def get_instance_action(self, server_id, request_id):
388 """Returns the action details of the provided server."""
389 resp, body = self.get("servers/%s/os-instance-actions/%s" %
390 (str(server_id), str(request_id)))
391 body = json.loads(body)
392 return resp, body['instanceAction']
Lingxian Kongaecc1092013-10-03 16:18:46 +0800393
394 def force_delete_server(self, server_id, **kwargs):
395 """Force delete a server."""
396 return self.action(server_id, 'forceDelete', None, **kwargs)
397
398 def restore_soft_deleted_server(self, server_id, **kwargs):
399 """Restore a soft-deleted server."""
400 return self.action(server_id, 'restore', None, **kwargs)