blob: 1f2daecc88094f544fcb87f260d22541824c4d5f [file] [log] [blame]
dwallecke62b9f02012-10-10 23:34:42 -05001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
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,
92 accessIPv6=None):
93 """
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
116 post_body = json.dumps({'server': post_body})
chris fattarsi5098fa22012-04-17 13:27:00 -0700117 resp, body = self.put("servers/%s" % str(server_id),
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800118 post_body, self.headers)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600119 body = json.loads(body)
120 return resp, body['server']
121
122 def get_server(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500123 """Returns the details of an existing server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700124 resp, body = self.get("servers/%s" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600125 body = json.loads(body)
126 return resp, body['server']
127
128 def delete_server(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500129 """Deletes the given server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700130 return self.delete("servers/%s" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600131
132 def list_servers(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500133 """Lists all servers for a user."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600134
135 url = 'servers'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -0500136 if params:
137 url += '?%s' % urllib.urlencode(params)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600138
chris fattarsi5098fa22012-04-17 13:27:00 -0700139 resp, body = self.get(url)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600140 body = json.loads(body)
141 return resp, body
142
143 def list_servers_with_detail(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500144 """Lists all servers in detail for a user."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600145
146 url = 'servers/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -0500147 if params:
148 url += '?%s' % urllib.urlencode(params)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600149
chris fattarsi5098fa22012-04-17 13:27:00 -0700150 resp, body = self.get(url)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600151 body = json.loads(body)
152 return resp, body
153
154 def wait_for_server_status(self, server_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500155 """Waits for a server to reach a given status."""
Attila Fazekas0abbc952013-07-01 19:19:42 +0200156 return waiters.wait_for_server_status(self, server_id, status)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600157
Jay Pipes051075a2012-04-28 17:39:37 -0400158 def wait_for_server_termination(self, server_id, ignore_error=False):
Sean Daguef237ccb2013-01-04 15:19:14 -0500159 """Waits for server to reach termination."""
Rohit Karajgi4a64d232012-05-17 07:44:37 -0700160 start_time = int(time.time())
161 while True:
162 try:
163 resp, body = self.get_server(server_id)
164 except exceptions.NotFound:
165 return
166
167 server_status = body['status']
Jay Pipes051075a2012-04-28 17:39:37 -0400168 if server_status == 'ERROR' and not ignore_error:
Jay Pipes444c3e62012-10-04 19:26:35 -0400169 raise exceptions.BuildErrorException(server_id=server_id)
Rohit Karajgi4a64d232012-05-17 07:44:37 -0700170
171 if int(time.time()) - start_time >= self.build_timeout:
172 raise exceptions.TimeoutException
173
174 time.sleep(self.build_interval)
175
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600176 def list_addresses(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500177 """Lists all addresses for a server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700178 resp, body = self.get("servers/%s/ips" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600179 body = json.loads(body)
180 return resp, body['addresses']
181
182 def list_addresses_by_network(self, server_id, network_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500183 """Lists all addresses of a specific network type for a server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700184 resp, body = self.get("servers/%s/ips/%s" %
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800185 (str(server_id), network_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600186 body = json.loads(body)
187 return resp, body
188
Attila Fazekasd4299282013-02-22 13:25:23 +0100189 def action(self, server_id, action_name, response_key, **kwargs):
190 post_body = json.dumps({action_name: kwargs})
191 resp, body = self.post('servers/%s/action' % str(server_id),
192 post_body, self.headers)
193 if response_key is not None:
194 body = json.loads(body)[response_key]
195 return resp, body
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600196
Attila Fazekasd4299282013-02-22 13:25:23 +0100197 def change_password(self, server_id, adminPass):
198 """Changes the root password for the server."""
199 return self.action(server_id, 'changePassword', None,
200 adminPass=adminPass)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600201
202 def reboot(self, server_id, reboot_type):
Sean Daguef237ccb2013-01-04 15:19:14 -0500203 """Reboots a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100204 return self.action(server_id, 'reboot', None, type=reboot_type)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600205
Attila Fazekasd4299282013-02-22 13:25:23 +0100206 def rebuild(self, server_id, image_ref, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500207 """Rebuilds a server with a new image."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100208 kwargs['imageRef'] = image_ref
209 if 'disk_config' in kwargs:
210 kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
211 del kwargs['disk_config']
212 return self.action(server_id, 'rebuild', 'server', **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600213
Attila Fazekasd4299282013-02-22 13:25:23 +0100214 def resize(self, server_id, flavor_ref, **kwargs):
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600215 """Changes the flavor of a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100216 kwargs['flavorRef'] = flavor_ref
217 if 'disk_config' in kwargs:
218 kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
219 del kwargs['disk_config']
220 return self.action(server_id, 'resize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600221
Attila Fazekasd4299282013-02-22 13:25:23 +0100222 def confirm_resize(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500223 """Confirms the flavor change for a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100224 return self.action(server_id, 'confirmResize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600225
Attila Fazekasd4299282013-02-22 13:25:23 +0100226 def revert_resize(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500227 """Reverts a server back to its original flavor."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100228 return self.action(server_id, 'revertResize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600229
Attila Fazekasd4299282013-02-22 13:25:23 +0100230 def create_image(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500231 """Creates an image of the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100232 return self.action(server_id, 'createImage', None, name=name)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600233
234 def list_server_metadata(self, server_id):
chris fattarsi5098fa22012-04-17 13:27:00 -0700235 resp, body = self.get("servers/%s/metadata" % str(server_id))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600236 body = json.loads(body)
237 return resp, body['metadata']
238
239 def set_server_metadata(self, server_id, meta):
240 post_body = json.dumps({'metadata': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800241 resp, body = self.put('servers/%s/metadata' % str(server_id),
242 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600243 body = json.loads(body)
244 return resp, body['metadata']
245
246 def update_server_metadata(self, server_id, meta):
247 post_body = json.dumps({'metadata': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800248 resp, body = self.post('servers/%s/metadata' % str(server_id),
249 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600250 body = json.loads(body)
251 return resp, body['metadata']
252
253 def get_server_metadata_item(self, server_id, key):
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800254 resp, body = self.get("servers/%s/metadata/%s" % (str(server_id), key))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600255 body = json.loads(body)
256 return resp, body['meta']
257
258 def set_server_metadata_item(self, server_id, key, meta):
259 post_body = json.dumps({'meta': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800260 resp, body = self.put('servers/%s/metadata/%s' % (str(server_id), key),
261 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600262 body = json.loads(body)
263 return resp, body['meta']
264
265 def delete_server_metadata_item(self, server_id, key):
chris fattarsi5098fa22012-04-17 13:27:00 -0700266 resp, body = self.delete("servers/%s/metadata/%s" %
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800267 (str(server_id), key))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600268 return resp, body
Dan Smithc18d8c62012-07-02 08:09:26 -0700269
Attila Fazekasd4299282013-02-22 13:25:23 +0100270 def stop(self, server_id, **kwargs):
271 return self.action(server_id, 'os-stop', None, **kwargs)
Dan Smithc18d8c62012-07-02 08:09:26 -0700272
Attila Fazekasd4299282013-02-22 13:25:23 +0100273 def start(self, server_id, **kwargs):
274 return self.action(server_id, 'os-start', None, **kwargs)
Dan Smithc18d8c62012-07-02 08:09:26 -0700275
276 def attach_volume(self, server_id, volume_id, device='/dev/vdz'):
Sean Daguef237ccb2013-01-04 15:19:14 -0500277 """Attaches a volume to a server instance."""
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900278 post_body = json.dumps({
279 'volumeAttachment': {
280 'volumeId': volume_id,
281 'device': device,
282 }
283 })
Dan Smithc18d8c62012-07-02 08:09:26 -0700284 resp, body = self.post('servers/%s/os-volume_attachments' % server_id,
285 post_body, self.headers)
286 return resp, body
287
288 def detach_volume(self, server_id, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500289 """Detaches a volume from a server instance."""
Dan Smithc18d8c62012-07-02 08:09:26 -0700290 resp, body = self.delete('servers/%s/os-volume_attachments/%s' %
291 (server_id, volume_id))
292 return resp, body
sapan-kona775cf632012-06-22 00:32:36 +0530293
Attila Fazekasd4299282013-02-22 13:25:23 +0100294 def add_security_group(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500295 """Adds a security group to the server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100296 return self.action(server_id, 'addSecurityGroup', None, name=name)
sapan-kona775cf632012-06-22 00:32:36 +0530297
Attila Fazekasd4299282013-02-22 13:25:23 +0100298 def remove_security_group(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500299 """Removes a security group from the server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100300 return self.action(server_id, 'removeSecurityGroup', None, name=name)
Mate Lakat99ee9142012-09-14 12:34:46 +0100301
302 def live_migrate_server(self, server_id, dest_host, use_block_migration):
Sean Daguef237ccb2013-01-04 15:19:14 -0500303 """This should be called with administrator privileges ."""
Mate Lakat99ee9142012-09-14 12:34:46 +0100304
305 migrate_params = {
306 "disk_over_commit": False,
307 "block_migration": use_block_migration,
308 "host": dest_host
309 }
310
311 req_body = json.dumps({'os-migrateLive': migrate_params})
312
313 resp, body = self.post("servers/%s/action" % str(server_id),
314 req_body, self.headers)
315 return resp, body
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600316
Attila Fazekasd4299282013-02-22 13:25:23 +0100317 def migrate_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500318 """Migrates a server to a new host."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100319 return self.action(server_id, 'migrate', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600320
Attila Fazekasd4299282013-02-22 13:25:23 +0100321 def lock_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500322 """Locks the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100323 return self.action(server_id, 'lock', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600324
Attila Fazekasd4299282013-02-22 13:25:23 +0100325 def unlock_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500326 """UNlocks the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100327 return self.action(server_id, 'unlock', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600328
Attila Fazekasd4299282013-02-22 13:25:23 +0100329 def suspend_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500330 """Suspends the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100331 return self.action(server_id, 'suspend', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600332
Attila Fazekasd4299282013-02-22 13:25:23 +0100333 def resume_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500334 """Un-suspends the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100335 return self.action(server_id, 'resume', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600336
Attila Fazekasd4299282013-02-22 13:25:23 +0100337 def pause_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500338 """Pauses the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100339 return self.action(server_id, 'pause', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600340
Attila Fazekasd4299282013-02-22 13:25:23 +0100341 def unpause_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500342 """Un-pauses the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100343 return self.action(server_id, 'unpause', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600344
Attila Fazekasd4299282013-02-22 13:25:23 +0100345 def reset_state(self, server_id, state='error'):
Sean Daguef237ccb2013-01-04 15:19:14 -0500346 """Resets the state of a server to active/error."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100347 return self.action(server_id, 'os-resetState', None, state=state)
Attila Fazekase4cb04c2013-01-29 09:51:58 +0100348
349 def get_console_output(self, server_id, length):
Attila Fazekasd4299282013-02-22 13:25:23 +0100350 return self.action(server_id, 'os-getConsoleOutput', 'output',
351 length=length)
Rami Vaknin76bc8bd2013-02-17 16:18:27 +0200352
353 def list_virtual_interfaces(self, server_id):
354 """
355 List the virtual interfaces used in an instance.
356 """
357 resp, body = self.get('/'.join(['servers', server_id,
358 'os-virtual-interfaces']))
359 return resp, json.loads(body)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000360
361 def rescue_server(self, server_id, adminPass=None):
362 """Rescue the provided server."""
363 return self.action(server_id, 'rescue', None, adminPass=adminPass)
364
365 def unrescue_server(self, server_id):
366 """Unrescue the provided server."""
367 return self.action(server_id, 'unrescue', None)
Leo Toyodafaca6ff2013-04-22 16:52:53 +0900368
369 def list_instance_actions(self, server_id):
370 """List the provided server action."""
371 resp, body = self.get("servers/%s/os-instance-actions" %
372 str(server_id))
373 body = json.loads(body)
374 return resp, body['instanceActions']
375
376 def get_instance_action(self, server_id, request_id):
377 """Returns the action details of the provided server."""
378 resp, body = self.get("servers/%s/os-instance-actions/%s" %
379 (str(server_id), str(request_id)))
380 body = json.loads(body)
381 return resp, body['instanceAction']