blob: 3569b5029d270796ca67f3c14c9be2bf2c97702c [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
24from tempest import exceptions
25
Daryl Wallecke5b83d42011-11-10 14:39:02 -060026
Dan Smithcf8fab62012-08-14 08:03:48 -070027class ServersClientJSON(RestClient):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060028
Daryl Walleck587385b2012-03-03 13:00:26 -060029 def __init__(self, config, username, password, auth_url, tenant_name=None):
Dan Smithcf8fab62012-08-14 08:03:48 -070030 super(ServersClientJSON, self).__init__(config, username, password,
31 auth_url, tenant_name)
chris fattarsi5098fa22012-04-17 13:27:00 -070032 self.service = self.config.compute.catalog_type
Daryl Wallecke5b83d42011-11-10 14:39:02 -060033
Rohit Karajgi95446a22011-12-12 06:21:43 -080034 def create_server(self, name, image_ref, flavor_ref, **kwargs):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060035 """
36 Creates an instance of a server.
Rohit Karajgi95446a22011-12-12 06:21:43 -080037 name (Required): The name of the server.
38 image_ref (Required): Reference to the image used to build the server.
39 flavor_ref (Required): The flavor used to build the server.
40 Following optional keyword arguments are accepted:
Daryl Wallecke5b83d42011-11-10 14:39:02 -060041 adminPass: Sets the initial root password.
chris fattarsia6c2a732012-05-02 17:00:19 -070042 key_name: Key name of keypair that was created earlier.
David Kranz28e79de2012-04-12 15:49:41 -040043 meta: A dictionary of values to be used as metadata.
Daryl Wallecke5b83d42011-11-10 14:39:02 -060044 personality: A list of dictionaries for files to be injected into
45 the server.
Rohit Karajgi95446a22011-12-12 06:21:43 -080046 security_groups: A list of security group dicts.
47 networks: A list of network dicts with UUID and fixed_ip.
48 user_data: User data for instance.
49 availability_zone: Availability zone in which to launch instance.
Daryl Wallecke5b83d42011-11-10 14:39:02 -060050 accessIPv4: The IPv4 access address for the server.
51 accessIPv6: The IPv6 access address for the server.
Rohit Karajgi95446a22011-12-12 06:21:43 -080052 min_count: Count of minimum number of instances to launch.
53 max_count: Count of maximum number of instances to launch.
Daryl Wallecke36d5002012-03-28 09:56:10 -050054 disk_config: Determines if user or admin controls disk configuration.
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050055 return_reservation_id: Enable/Disable the return of reservation id
Daryl Wallecke5b83d42011-11-10 14:39:02 -060056 """
Daryl Wallecke5b83d42011-11-10 14:39:02 -060057 post_body = {
58 'name': name,
59 'imageRef': image_ref,
David Kranz28e79de2012-04-12 15:49:41 -040060 'flavorRef': flavor_ref
Daryl Wallecke5b83d42011-11-10 14:39:02 -060061 }
62
chris fattarsia6c2a732012-05-02 17:00:19 -070063 for option in ['personality', 'adminPass', 'key_name',
Zhongyue Luoe0884a32012-09-25 17:24:17 +080064 'security_groups', 'networks', 'user_data',
65 'availability_zone', 'accessIPv4', 'accessIPv6',
66 'min_count', 'max_count', ('metadata', 'meta'),
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050067 ('OS-DCF:diskConfig', 'disk_config'),
68 'return_reservation_id']:
David Kranz28e79de2012-04-12 15:49:41 -040069 if isinstance(option, tuple):
70 post_param = option[0]
71 key = option[1]
72 else:
73 post_param = option
74 key = option
75 value = kwargs.get(key)
Zhongyue Luoe471d6e2012-09-17 17:02:43 +080076 if value is not None:
David Kranz28e79de2012-04-12 15:49:41 -040077 post_body[post_param] = value
Daryl Wallecke5b83d42011-11-10 14:39:02 -060078 post_body = json.dumps({'server': post_body})
chris fattarsi5098fa22012-04-17 13:27:00 -070079 resp, body = self.post('servers', post_body, self.headers)
Jay Pipes5135bfc2012-01-05 15:46:49 -050080
Daryl Wallecke5b83d42011-11-10 14:39:02 -060081 body = json.loads(body)
Mauro S. M. Rodriguesc5da4f42013-03-04 23:57:10 -050082 # NOTE(maurosr): this deals with the case of multiple server create
83 # with return reservation id set True
84 if 'reservation_id' in body:
85 return resp, body
Daryl Wallecke5b83d42011-11-10 14:39:02 -060086 return resp, body['server']
87
88 def update_server(self, server_id, name=None, meta=None, accessIPv4=None,
89 accessIPv6=None):
90 """
91 Updates the properties of an existing server.
92 server_id: The id of an existing server.
93 name: The name of the server.
94 personality: A list of files to be injected into the server.
95 accessIPv4: The IPv4 access address for the server.
96 accessIPv6: The IPv6 access address for the server.
97 """
98
99 post_body = {}
100
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800101 if meta is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600102 post_body['metadata'] = meta
103
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800104 if name is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600105 post_body['name'] = name
106
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800107 if accessIPv4 is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600108 post_body['accessIPv4'] = accessIPv4
109
Zhongyue Luoe471d6e2012-09-17 17:02:43 +0800110 if accessIPv6 is not None:
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600111 post_body['accessIPv6'] = accessIPv6
112
113 post_body = json.dumps({'server': post_body})
chris fattarsi5098fa22012-04-17 13:27:00 -0700114 resp, body = self.put("servers/%s" % str(server_id),
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800115 post_body, self.headers)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600116 body = json.loads(body)
117 return resp, body['server']
118
119 def get_server(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500120 """Returns the details of an existing server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700121 resp, body = self.get("servers/%s" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600122 body = json.loads(body)
123 return resp, body['server']
124
125 def delete_server(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500126 """Deletes the given server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700127 return self.delete("servers/%s" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600128
129 def list_servers(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500130 """Lists all servers for a user."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600131
132 url = 'servers'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -0500133 if params:
134 url += '?%s' % urllib.urlencode(params)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600135
chris fattarsi5098fa22012-04-17 13:27:00 -0700136 resp, body = self.get(url)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600137 body = json.loads(body)
138 return resp, body
139
140 def list_servers_with_detail(self, params=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500141 """Lists all servers in detail for a user."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600142
143 url = 'servers/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -0500144 if params:
145 url += '?%s' % urllib.urlencode(params)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600146
chris fattarsi5098fa22012-04-17 13:27:00 -0700147 resp, body = self.get(url)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600148 body = json.loads(body)
149 return resp, body
150
151 def wait_for_server_status(self, server_id, status):
Sean Daguef237ccb2013-01-04 15:19:14 -0500152 """Waits for a server to reach a given status."""
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600153 resp, body = self.get_server(server_id)
154 server_status = body['status']
155 start = int(time.time())
156
157 while(server_status != status):
158 time.sleep(self.build_interval)
159 resp, body = self.get_server(server_id)
160 server_status = body['status']
161
Jay Pipes5135bfc2012-01-05 15:46:49 -0500162 if server_status == 'ERROR':
163 raise exceptions.BuildErrorException(server_id=server_id)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600164
Eoghan Glynnf72969c2012-03-05 12:33:10 +0000165 timed_out = int(time.time()) - start >= self.build_timeout
166
167 if server_status != status and timed_out:
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800168 message = ('Server %s failed to reach %s status within the '
169 'required time (%s s).' %
170 (server_id, status, self.build_timeout))
Eoghan Glynnf72969c2012-03-05 12:33:10 +0000171 message += ' Current status: %s.' % server_status
Daryl Walleckf0087032011-12-18 13:37:05 -0600172 raise exceptions.TimeoutException(message)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600173
Jay Pipes051075a2012-04-28 17:39:37 -0400174 def wait_for_server_termination(self, server_id, ignore_error=False):
Sean Daguef237ccb2013-01-04 15:19:14 -0500175 """Waits for server to reach termination."""
Rohit Karajgi4a64d232012-05-17 07:44:37 -0700176 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']
Jay Pipes051075a2012-04-28 17:39:37 -0400184 if server_status == 'ERROR' and not ignore_error:
Jay Pipes444c3e62012-10-04 19:26:35 -0400185 raise exceptions.BuildErrorException(server_id=server_id)
Rohit Karajgi4a64d232012-05-17 07:44:37 -0700186
187 if int(time.time()) - start_time >= self.build_timeout:
188 raise exceptions.TimeoutException
189
190 time.sleep(self.build_interval)
191
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600192 def list_addresses(self, server_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500193 """Lists all addresses for a server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700194 resp, body = self.get("servers/%s/ips" % str(server_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600195 body = json.loads(body)
196 return resp, body['addresses']
197
198 def list_addresses_by_network(self, server_id, network_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500199 """Lists all addresses of a specific network type for a server."""
chris fattarsi5098fa22012-04-17 13:27:00 -0700200 resp, body = self.get("servers/%s/ips/%s" %
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800201 (str(server_id), network_id))
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600202 body = json.loads(body)
203 return resp, body
204
Attila Fazekasd4299282013-02-22 13:25:23 +0100205 def action(self, server_id, action_name, response_key, **kwargs):
206 post_body = json.dumps({action_name: kwargs})
207 resp, body = self.post('servers/%s/action' % str(server_id),
208 post_body, self.headers)
209 if response_key is not None:
210 body = json.loads(body)[response_key]
211 return resp, body
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600212
Attila Fazekasd4299282013-02-22 13:25:23 +0100213 def change_password(self, server_id, adminPass):
214 """Changes the root password for the server."""
215 return self.action(server_id, 'changePassword', None,
216 adminPass=adminPass)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600217
218 def reboot(self, server_id, reboot_type):
Sean Daguef237ccb2013-01-04 15:19:14 -0500219 """Reboots a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100220 return self.action(server_id, 'reboot', None, type=reboot_type)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600221
Attila Fazekasd4299282013-02-22 13:25:23 +0100222 def rebuild(self, server_id, image_ref, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500223 """Rebuilds a server with a new image."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100224 kwargs['imageRef'] = image_ref
225 if 'disk_config' in kwargs:
226 kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
227 del kwargs['disk_config']
228 return self.action(server_id, 'rebuild', 'server', **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600229
Attila Fazekasd4299282013-02-22 13:25:23 +0100230 def resize(self, server_id, flavor_ref, **kwargs):
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600231 """Changes the flavor of a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100232 kwargs['flavorRef'] = flavor_ref
233 if 'disk_config' in kwargs:
234 kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
235 del kwargs['disk_config']
236 return self.action(server_id, 'resize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600237
Attila Fazekasd4299282013-02-22 13:25:23 +0100238 def confirm_resize(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500239 """Confirms the flavor change for a server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100240 return self.action(server_id, 'confirmResize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600241
Attila Fazekasd4299282013-02-22 13:25:23 +0100242 def revert_resize(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500243 """Reverts a server back to its original flavor."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100244 return self.action(server_id, 'revertResize', None, **kwargs)
Daryl Wallecke5b83d42011-11-10 14:39:02 -0600245
Attila Fazekasd4299282013-02-22 13:25:23 +0100246 def create_image(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500247 """Creates an image of the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100248 return self.action(server_id, 'createImage', None, name=name)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600249
250 def list_server_metadata(self, server_id):
chris fattarsi5098fa22012-04-17 13:27:00 -0700251 resp, body = self.get("servers/%s/metadata" % str(server_id))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600252 body = json.loads(body)
253 return resp, body['metadata']
254
255 def set_server_metadata(self, server_id, meta):
256 post_body = json.dumps({'metadata': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800257 resp, body = self.put('servers/%s/metadata' % str(server_id),
258 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600259 body = json.loads(body)
260 return resp, body['metadata']
261
262 def update_server_metadata(self, server_id, meta):
263 post_body = json.dumps({'metadata': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800264 resp, body = self.post('servers/%s/metadata' % str(server_id),
265 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600266 body = json.loads(body)
267 return resp, body['metadata']
268
269 def get_server_metadata_item(self, server_id, key):
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800270 resp, body = self.get("servers/%s/metadata/%s" % (str(server_id), key))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600271 body = json.loads(body)
272 return resp, body['meta']
273
274 def set_server_metadata_item(self, server_id, key, meta):
275 post_body = json.dumps({'meta': meta})
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800276 resp, body = self.put('servers/%s/metadata/%s' % (str(server_id), key),
277 post_body, self.headers)
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600278 body = json.loads(body)
279 return resp, body['meta']
280
281 def delete_server_metadata_item(self, server_id, key):
chris fattarsi5098fa22012-04-17 13:27:00 -0700282 resp, body = self.delete("servers/%s/metadata/%s" %
Zhongyue Luoe0884a32012-09-25 17:24:17 +0800283 (str(server_id), key))
Daryl Walleck73a9e7a2011-11-15 17:43:31 -0600284 return resp, body
Dan Smithc18d8c62012-07-02 08:09:26 -0700285
Attila Fazekasd4299282013-02-22 13:25:23 +0100286 def stop(self, server_id, **kwargs):
287 return self.action(server_id, 'os-stop', None, **kwargs)
Dan Smithc18d8c62012-07-02 08:09:26 -0700288
Attila Fazekasd4299282013-02-22 13:25:23 +0100289 def start(self, server_id, **kwargs):
290 return self.action(server_id, 'os-start', None, **kwargs)
Dan Smithc18d8c62012-07-02 08:09:26 -0700291
292 def attach_volume(self, server_id, volume_id, device='/dev/vdz'):
Sean Daguef237ccb2013-01-04 15:19:14 -0500293 """Attaches a volume to a server instance."""
Zhongyue Luo30a563f2012-09-30 23:43:50 +0900294 post_body = json.dumps({
295 'volumeAttachment': {
296 'volumeId': volume_id,
297 'device': device,
298 }
299 })
Dan Smithc18d8c62012-07-02 08:09:26 -0700300 resp, body = self.post('servers/%s/os-volume_attachments' % server_id,
301 post_body, self.headers)
302 return resp, body
303
304 def detach_volume(self, server_id, volume_id):
Sean Daguef237ccb2013-01-04 15:19:14 -0500305 """Detaches a volume from a server instance."""
Dan Smithc18d8c62012-07-02 08:09:26 -0700306 resp, body = self.delete('servers/%s/os-volume_attachments/%s' %
307 (server_id, volume_id))
308 return resp, body
sapan-kona775cf632012-06-22 00:32:36 +0530309
Attila Fazekasd4299282013-02-22 13:25:23 +0100310 def add_security_group(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500311 """Adds a security group to the server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100312 return self.action(server_id, 'addSecurityGroup', None, name=name)
sapan-kona775cf632012-06-22 00:32:36 +0530313
Attila Fazekasd4299282013-02-22 13:25:23 +0100314 def remove_security_group(self, server_id, name):
Sean Daguef237ccb2013-01-04 15:19:14 -0500315 """Removes a security group from the server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100316 return self.action(server_id, 'removeSecurityGroup', None, name=name)
Mate Lakat99ee9142012-09-14 12:34:46 +0100317
318 def live_migrate_server(self, server_id, dest_host, use_block_migration):
Sean Daguef237ccb2013-01-04 15:19:14 -0500319 """This should be called with administrator privileges ."""
Mate Lakat99ee9142012-09-14 12:34:46 +0100320
321 migrate_params = {
322 "disk_over_commit": False,
323 "block_migration": use_block_migration,
324 "host": dest_host
325 }
326
327 req_body = json.dumps({'os-migrateLive': migrate_params})
328
329 resp, body = self.post("servers/%s/action" % str(server_id),
330 req_body, self.headers)
331 return resp, body
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600332
333 def list_servers_for_all_tenants(self):
334
335 url = self.base_url + '/servers?all_tenants=1'
336 resp = self.requests.get(url)
Attila Fazekasfa756cb2013-02-12 10:52:42 +0100337 resp, body = self.get('servers', self.headers)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600338
339 body = json.loads(body)
340 return resp, body['servers']
341
Attila Fazekasd4299282013-02-22 13:25:23 +0100342 def migrate_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500343 """Migrates a server to a new host."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100344 return self.action(server_id, 'migrate', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600345
Attila Fazekasd4299282013-02-22 13:25:23 +0100346 def lock_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500347 """Locks the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100348 return self.action(server_id, 'lock', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600349
Attila Fazekasd4299282013-02-22 13:25:23 +0100350 def unlock_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500351 """UNlocks the given server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100352 return self.action(server_id, 'unlock', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600353
Attila Fazekasd4299282013-02-22 13:25:23 +0100354 def suspend_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500355 """Suspends the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100356 return self.action(server_id, 'suspend', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600357
Attila Fazekasd4299282013-02-22 13:25:23 +0100358 def resume_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500359 """Un-suspends the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100360 return self.action(server_id, 'resume', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600361
Attila Fazekasd4299282013-02-22 13:25:23 +0100362 def pause_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500363 """Pauses the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100364 return self.action(server_id, 'pause', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600365
Attila Fazekasd4299282013-02-22 13:25:23 +0100366 def unpause_server(self, server_id, **kwargs):
Sean Daguef237ccb2013-01-04 15:19:14 -0500367 """Un-pauses the provded server."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100368 return self.action(server_id, 'unpause', None, **kwargs)
Daryl Walleck3d3f6102012-11-09 15:16:42 -0600369
Attila Fazekasd4299282013-02-22 13:25:23 +0100370 def reset_state(self, server_id, state='error'):
Sean Daguef237ccb2013-01-04 15:19:14 -0500371 """Resets the state of a server to active/error."""
Attila Fazekasd4299282013-02-22 13:25:23 +0100372 return self.action(server_id, 'os-resetState', None, state=state)
Attila Fazekase4cb04c2013-01-29 09:51:58 +0100373
374 def get_console_output(self, server_id, length):
Attila Fazekasd4299282013-02-22 13:25:23 +0100375 return self.action(server_id, 'os-getConsoleOutput', 'output',
376 length=length)
Rami Vaknin76bc8bd2013-02-17 16:18:27 +0200377
378 def list_virtual_interfaces(self, server_id):
379 """
380 List the virtual interfaces used in an instance.
381 """
382 resp, body = self.get('/'.join(['servers', server_id,
383 'os-virtual-interfaces']))
384 return resp, json.loads(body)
nithya-ganesane6a36c82013-02-15 14:38:27 +0000385
386 def rescue_server(self, server_id, adminPass=None):
387 """Rescue the provided server."""
388 return self.action(server_id, 'rescue', None, adminPass=adminPass)
389
390 def unrescue_server(self, server_id):
391 """Unrescue the provided server."""
392 return self.action(server_id, 'unrescue', None)
Leo Toyodafaca6ff2013-04-22 16:52:53 +0900393
394 def list_instance_actions(self, server_id):
395 """List the provided server action."""
396 resp, body = self.get("servers/%s/os-instance-actions" %
397 str(server_id))
398 body = json.loads(body)
399 return resp, body['instanceActions']
400
401 def get_instance_action(self, server_id, request_id):
402 """Returns the action details of the provided server."""
403 resp, body = self.get("servers/%s/os-instance-actions/%s" %
404 (str(server_id), str(request_id)))
405 body = json.loads(body)
406 return resp, body['instanceAction']