ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 2 | # Copyright 2013 Hewlett-Packard Development Company, L.P. |
dwalleck | e62b9f0 | 2012-10-10 23:34:42 -0500 | [diff] [blame] | 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 17 | import json |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 18 | import time |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 19 | import urllib |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 20 | |
Marc Koderer | 6fbd74f | 2014-08-04 09:38:19 +0200 | [diff] [blame] | 21 | from tempest.api_schema.response.compute import servers as common_schema |
| 22 | from tempest.api_schema.response.compute.v2 import servers as schema |
Haiwei Xu | ab92462 | 2014-03-05 04:33:51 +0900 | [diff] [blame] | 23 | from tempest.common import rest_client |
Attila Fazekas | 0abbc95 | 2013-07-01 19:19:42 +0200 | [diff] [blame] | 24 | from tempest.common import waiters |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 25 | from tempest import config |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 26 | from tempest import exceptions |
| 27 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 28 | CONF = config.CONF |
| 29 | |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 30 | |
Haiwei Xu | ab92462 | 2014-03-05 04:33:51 +0900 | [diff] [blame] | 31 | class ServersClientJSON(rest_client.RestClient): |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 32 | |
Andrea Frittoli | 8bbdb16 | 2014-01-06 11:06:13 +0000 | [diff] [blame] | 33 | def __init__(self, auth_provider): |
| 34 | super(ServersClientJSON, self).__init__(auth_provider) |
| 35 | |
Matthew Treinish | 684d899 | 2014-01-30 16:27:40 +0000 | [diff] [blame] | 36 | self.service = CONF.compute.catalog_type |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 37 | |
Rohit Karajgi | 95446a2 | 2011-12-12 06:21:43 -0800 | [diff] [blame] | 38 | def create_server(self, name, image_ref, flavor_ref, **kwargs): |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 39 | """ |
| 40 | Creates an instance of a server. |
Rohit Karajgi | 95446a2 | 2011-12-12 06:21:43 -0800 | [diff] [blame] | 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: |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 45 | adminPass: Sets the initial root password. |
chris fattarsi | a6c2a73 | 2012-05-02 17:00:19 -0700 | [diff] [blame] | 46 | key_name: Key name of keypair that was created earlier. |
David Kranz | 28e79de | 2012-04-12 15:49:41 -0400 | [diff] [blame] | 47 | meta: A dictionary of values to be used as metadata. |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 48 | personality: A list of dictionaries for files to be injected into |
| 49 | the server. |
Rohit Karajgi | 95446a2 | 2011-12-12 06:21:43 -0800 | [diff] [blame] | 50 | security_groups: A list of security group dicts. |
| 51 | networks: A list of network dicts with UUID and fixed_ip. |
| 52 | user_data: User data for instance. |
| 53 | availability_zone: Availability zone in which to launch instance. |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 54 | accessIPv4: The IPv4 access address for the server. |
| 55 | accessIPv6: The IPv6 access address for the server. |
Rohit Karajgi | 95446a2 | 2011-12-12 06:21:43 -0800 | [diff] [blame] | 56 | min_count: Count of minimum number of instances to launch. |
| 57 | max_count: Count of maximum number of instances to launch. |
Daryl Walleck | e36d500 | 2012-03-28 09:56:10 -0500 | [diff] [blame] | 58 | disk_config: Determines if user or admin controls disk configuration. |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 59 | return_reservation_id: Enable/Disable the return of reservation id |
Andrey Pavlov | 2a2fc41 | 2014-06-09 11:02:53 +0400 | [diff] [blame] | 60 | block_device_mapping: Block device mapping for the server. |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame^] | 61 | block_device_mapping_v2: Block device mapping V2 for the server. |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 62 | """ |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 63 | post_body = { |
| 64 | 'name': name, |
| 65 | 'imageRef': image_ref, |
David Kranz | 28e79de | 2012-04-12 15:49:41 -0400 | [diff] [blame] | 66 | 'flavorRef': flavor_ref |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 67 | } |
| 68 | |
chris fattarsi | a6c2a73 | 2012-05-02 17:00:19 -0700 | [diff] [blame] | 69 | for option in ['personality', 'adminPass', 'key_name', |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 70 | 'security_groups', 'networks', 'user_data', |
| 71 | 'availability_zone', 'accessIPv4', 'accessIPv6', |
| 72 | 'min_count', 'max_count', ('metadata', 'meta'), |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 73 | ('OS-DCF:diskConfig', 'disk_config'), |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame^] | 74 | 'return_reservation_id', 'block_device_mapping', |
| 75 | 'block_device_mapping_v2']: |
David Kranz | 28e79de | 2012-04-12 15:49:41 -0400 | [diff] [blame] | 76 | if isinstance(option, tuple): |
| 77 | post_param = option[0] |
| 78 | key = option[1] |
| 79 | else: |
| 80 | post_param = option |
| 81 | key = option |
| 82 | value = kwargs.get(key) |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 83 | if value is not None: |
David Kranz | 28e79de | 2012-04-12 15:49:41 -0400 | [diff] [blame] | 84 | post_body[post_param] = value |
Joseph Lanoux | eef192f | 2014-08-01 14:32:53 +0000 | [diff] [blame^] | 85 | |
raiesmh08 | cbe21b0 | 2014-03-12 17:04:44 +0530 | [diff] [blame] | 86 | post_body = {'server': post_body} |
| 87 | |
| 88 | if 'sched_hints' in kwargs: |
| 89 | hints = {'os:scheduler_hints': kwargs.get('sched_hints')} |
| 90 | post_body = dict(post_body.items() + hints.items()) |
| 91 | post_body = json.dumps(post_body) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 92 | resp, body = self.post('servers', post_body) |
Jay Pipes | 5135bfc | 2012-01-05 15:46:49 -0500 | [diff] [blame] | 93 | |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 94 | body = json.loads(body) |
Mauro S. M. Rodrigues | c5da4f4 | 2013-03-04 23:57:10 -0500 | [diff] [blame] | 95 | # NOTE(maurosr): this deals with the case of multiple server create |
| 96 | # with return reservation id set True |
| 97 | if 'reservation_id' in body: |
| 98 | return resp, body |
Ghanshyam | 7f98910 | 2014-07-29 14:23:26 +0900 | [diff] [blame] | 99 | if CONF.compute_feature_enabled.enable_instance_password: |
| 100 | create_schema = schema.create_server_with_admin_pass |
| 101 | else: |
| 102 | create_schema = schema.create_server |
| 103 | self.validate_response(create_schema, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 104 | return resp, body['server'] |
| 105 | |
| 106 | def update_server(self, server_id, name=None, meta=None, accessIPv4=None, |
ivan-zhu | 72d7d5b | 2013-10-16 17:30:58 +0800 | [diff] [blame] | 107 | accessIPv6=None, disk_config=None): |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 108 | """ |
| 109 | Updates the properties of an existing server. |
| 110 | server_id: The id of an existing server. |
| 111 | name: The name of the server. |
| 112 | personality: A list of files to be injected into the server. |
| 113 | accessIPv4: The IPv4 access address for the server. |
| 114 | accessIPv6: The IPv6 access address for the server. |
| 115 | """ |
| 116 | |
| 117 | post_body = {} |
| 118 | |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 119 | if meta is not None: |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 120 | post_body['metadata'] = meta |
| 121 | |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 122 | if name is not None: |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 123 | post_body['name'] = name |
| 124 | |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 125 | if accessIPv4 is not None: |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 126 | post_body['accessIPv4'] = accessIPv4 |
| 127 | |
Zhongyue Luo | e471d6e | 2012-09-17 17:02:43 +0800 | [diff] [blame] | 128 | if accessIPv6 is not None: |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 129 | post_body['accessIPv6'] = accessIPv6 |
| 130 | |
ivan-zhu | 72d7d5b | 2013-10-16 17:30:58 +0800 | [diff] [blame] | 131 | if disk_config is not None: |
| 132 | post_body['OS-DCF:diskConfig'] = disk_config |
| 133 | |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 134 | post_body = json.dumps({'server': post_body}) |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 135 | resp, body = self.put("servers/%s" % str(server_id), post_body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 136 | body = json.loads(body) |
Ken'ichi Ohmichi | 29cd512 | 2014-04-28 11:04:52 +0900 | [diff] [blame] | 137 | self.validate_response(schema.update_server, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 138 | return resp, body['server'] |
| 139 | |
| 140 | def get_server(self, server_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 141 | """Returns the details of an existing server.""" |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 142 | resp, body = self.get("servers/%s" % str(server_id)) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 143 | body = json.loads(body) |
Ken'ichi Ohmichi | 21e4fc7 | 2014-05-08 16:46:23 +0900 | [diff] [blame] | 144 | self.validate_response(schema.get_server, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 145 | return resp, body['server'] |
| 146 | |
| 147 | def delete_server(self, server_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 148 | """Deletes the given server.""" |
Ghanshyam | 4ac0274 | 2014-04-17 19:15:47 +0900 | [diff] [blame] | 149 | resp, body = self.delete("servers/%s" % str(server_id)) |
| 150 | self.validate_response(common_schema.delete_server, resp, body) |
| 151 | return resp, body |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 152 | |
| 153 | def list_servers(self, params=None): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 154 | """Lists all servers for a user.""" |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 155 | |
| 156 | url = 'servers' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 157 | if params: |
| 158 | url += '?%s' % urllib.urlencode(params) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 159 | |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 160 | resp, body = self.get(url) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 161 | body = json.loads(body) |
Ghanshyam | 623c38f | 2014-04-21 17:16:21 +0900 | [diff] [blame] | 162 | self.validate_response(common_schema.list_servers, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 163 | return resp, body |
| 164 | |
| 165 | def list_servers_with_detail(self, params=None): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 166 | """Lists all servers in detail for a user.""" |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 167 | |
| 168 | url = 'servers/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 169 | if params: |
| 170 | url += '?%s' % urllib.urlencode(params) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 171 | |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 172 | resp, body = self.get(url) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 173 | body = json.loads(body) |
Ghanshyam | 5174486 | 2014-06-13 12:56:24 +0900 | [diff] [blame] | 174 | self.validate_response(schema.list_servers_detail, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 175 | return resp, body |
| 176 | |
Zhi Kun Liu | e540176 | 2013-09-11 20:45:48 +0800 | [diff] [blame] | 177 | def wait_for_server_status(self, server_id, status, extra_timeout=0, |
| 178 | raise_on_error=True): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 179 | """Waits for a server to reach a given status.""" |
Ken'ichi Ohmichi | 39437e2 | 2013-10-06 00:21:38 +0900 | [diff] [blame] | 180 | return waiters.wait_for_server_status(self, server_id, status, |
Zhi Kun Liu | e540176 | 2013-09-11 20:45:48 +0800 | [diff] [blame] | 181 | extra_timeout=extra_timeout, |
| 182 | raise_on_error=raise_on_error) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 183 | |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 184 | def wait_for_server_termination(self, server_id, ignore_error=False): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 185 | """Waits for server to reach termination.""" |
Rohit Karajgi | 4a64d23 | 2012-05-17 07:44:37 -0700 | [diff] [blame] | 186 | start_time = int(time.time()) |
| 187 | while True: |
| 188 | try: |
| 189 | resp, body = self.get_server(server_id) |
| 190 | except exceptions.NotFound: |
| 191 | return |
| 192 | |
| 193 | server_status = body['status'] |
Jay Pipes | 051075a | 2012-04-28 17:39:37 -0400 | [diff] [blame] | 194 | if server_status == 'ERROR' and not ignore_error: |
Jay Pipes | 444c3e6 | 2012-10-04 19:26:35 -0400 | [diff] [blame] | 195 | raise exceptions.BuildErrorException(server_id=server_id) |
Rohit Karajgi | 4a64d23 | 2012-05-17 07:44:37 -0700 | [diff] [blame] | 196 | |
| 197 | if int(time.time()) - start_time >= self.build_timeout: |
| 198 | raise exceptions.TimeoutException |
| 199 | |
| 200 | time.sleep(self.build_interval) |
| 201 | |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 202 | def list_addresses(self, server_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 203 | """Lists all addresses for a server.""" |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 204 | resp, body = self.get("servers/%s/ips" % str(server_id)) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 205 | body = json.loads(body) |
Ghanshyam | d847c58 | 2014-05-07 16:21:36 +0900 | [diff] [blame] | 206 | self.validate_response(schema.list_addresses, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 207 | return resp, body['addresses'] |
| 208 | |
| 209 | def list_addresses_by_network(self, server_id, network_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 210 | """Lists all addresses of a specific network type for a server.""" |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 211 | resp, body = self.get("servers/%s/ips/%s" % |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 212 | (str(server_id), network_id)) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 213 | body = json.loads(body) |
Ghanshyam | 9541ad1 | 2014-05-07 16:38:43 +0900 | [diff] [blame] | 214 | self.validate_response(schema.list_addresses_by_network, resp, body) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 215 | return resp, body |
| 216 | |
Ghanshyam | d6d3040 | 2014-04-02 15:28:37 +0900 | [diff] [blame] | 217 | def action(self, server_id, action_name, response_key, |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 218 | schema=common_schema.server_actions_common_schema, **kwargs): |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 219 | post_body = json.dumps({action_name: kwargs}) |
| 220 | resp, body = self.post('servers/%s/action' % str(server_id), |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 221 | post_body) |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 222 | if response_key is not None: |
Ghanshyam | d6d3040 | 2014-04-02 15:28:37 +0900 | [diff] [blame] | 223 | body = json.loads(body) |
Ghanshyam | 7ee264a | 2014-04-02 16:37:57 +0900 | [diff] [blame] | 224 | # Check for Schema as 'None' because if we do not have any server |
Ghanshyam | d6d3040 | 2014-04-02 15:28:37 +0900 | [diff] [blame] | 225 | # action schema implemented yet then they can pass 'None' to skip |
| 226 | # the validation.Once all server action has their schema |
| 227 | # implemented then, this check can be removed if every actions are |
| 228 | # supposed to validate their response. |
Ghanshyam | 7ee264a | 2014-04-02 16:37:57 +0900 | [diff] [blame] | 229 | # TODO(GMann): Remove the below 'if' check once all server actions |
| 230 | # schema are implemented. |
Ghanshyam | d6d3040 | 2014-04-02 15:28:37 +0900 | [diff] [blame] | 231 | if schema is not None: |
| 232 | self.validate_response(schema, resp, body) |
| 233 | body = body[response_key] |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 234 | else: |
| 235 | self.validate_response(schema, resp, body) |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 236 | return resp, body |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 237 | |
ivan-zhu | ccc8946 | 2013-10-31 16:53:12 +0800 | [diff] [blame] | 238 | def create_backup(self, server_id, backup_type, rotation, name): |
| 239 | """Backup a server instance.""" |
| 240 | return self.action(server_id, "createBackup", None, |
| 241 | backup_type=backup_type, |
| 242 | rotation=rotation, |
| 243 | name=name) |
| 244 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 245 | def change_password(self, server_id, adminPass): |
| 246 | """Changes the root password for the server.""" |
| 247 | return self.action(server_id, 'changePassword', None, |
| 248 | adminPass=adminPass) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 249 | |
ivan-zhu | 6de5b04 | 2013-10-24 17:21:48 +0800 | [diff] [blame] | 250 | def get_password(self, server_id): |
| 251 | resp, body = self.get("servers/%s/os-server-password" % |
| 252 | str(server_id)) |
| 253 | body = json.loads(body) |
Ghanshyam | 7fa397c | 2014-04-01 19:32:38 +0900 | [diff] [blame] | 254 | self.validate_response(common_schema.get_password, resp, body) |
ivan-zhu | 6de5b04 | 2013-10-24 17:21:48 +0800 | [diff] [blame] | 255 | return resp, body |
| 256 | |
| 257 | def delete_password(self, server_id): |
| 258 | """ |
| 259 | Removes the encrypted server password from the metadata server |
| 260 | Note that this does not actually change the instance server |
| 261 | password. |
| 262 | """ |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 263 | resp, body = self.delete("servers/%s/os-server-password" % |
| 264 | str(server_id)) |
| 265 | self.validate_response(common_schema.server_actions_delete_password, |
| 266 | resp, body) |
| 267 | return resp, body |
ivan-zhu | 6de5b04 | 2013-10-24 17:21:48 +0800 | [diff] [blame] | 268 | |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 269 | def reboot(self, server_id, reboot_type): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 270 | """Reboots a server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 271 | return self.action(server_id, 'reboot', None, type=reboot_type) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 272 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 273 | def rebuild(self, server_id, image_ref, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 274 | """Rebuilds a server with a new image.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 275 | kwargs['imageRef'] = image_ref |
| 276 | if 'disk_config' in kwargs: |
| 277 | kwargs['OS-DCF:diskConfig'] = kwargs['disk_config'] |
| 278 | del kwargs['disk_config'] |
Ghanshyam | 9c2e50d | 2014-07-22 21:32:05 +0900 | [diff] [blame] | 279 | if CONF.compute_feature_enabled.enable_instance_password: |
| 280 | rebuild_schema = schema.rebuild_server_with_admin_pass |
| 281 | else: |
| 282 | rebuild_schema = schema.rebuild_server |
| 283 | return self.action(server_id, 'rebuild', 'server', |
| 284 | rebuild_schema, **kwargs) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 285 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 286 | def resize(self, server_id, flavor_ref, **kwargs): |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 287 | """Changes the flavor of a server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 288 | kwargs['flavorRef'] = flavor_ref |
| 289 | if 'disk_config' in kwargs: |
| 290 | kwargs['OS-DCF:diskConfig'] = kwargs['disk_config'] |
| 291 | del kwargs['disk_config'] |
| 292 | return self.action(server_id, 'resize', None, **kwargs) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 293 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 294 | def confirm_resize(self, server_id, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 295 | """Confirms the flavor change for a server.""" |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 296 | return self.action(server_id, 'confirmResize', |
| 297 | None, schema.server_actions_confirm_resize, |
| 298 | **kwargs) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 299 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 300 | def revert_resize(self, server_id, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 301 | """Reverts a server back to its original flavor.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 302 | return self.action(server_id, 'revertResize', None, **kwargs) |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 303 | |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 304 | def list_server_metadata(self, server_id): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 305 | resp, body = self.get("servers/%s/metadata" % str(server_id)) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 306 | body = json.loads(body) |
Ghanshyam | a8f6653 | 2014-04-23 17:18:14 +0900 | [diff] [blame] | 307 | self.validate_response(common_schema.list_server_metadata, resp, body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 308 | return resp, body['metadata'] |
| 309 | |
Chris Yeoh | d0b52e7 | 2013-09-17 22:38:59 +0930 | [diff] [blame] | 310 | def set_server_metadata(self, server_id, meta, no_metadata_field=False): |
| 311 | if no_metadata_field: |
| 312 | post_body = "" |
| 313 | else: |
| 314 | post_body = json.dumps({'metadata': meta}) |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 315 | resp, body = self.put('servers/%s/metadata' % str(server_id), |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 316 | post_body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 317 | body = json.loads(body) |
Haiwei Xu | 3d2b7af | 2014-04-12 02:50:26 +0900 | [diff] [blame] | 318 | self.validate_response(common_schema.set_server_metadata, resp, body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 319 | return resp, body['metadata'] |
| 320 | |
| 321 | def update_server_metadata(self, server_id, meta): |
| 322 | post_body = json.dumps({'metadata': meta}) |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 323 | resp, body = self.post('servers/%s/metadata' % str(server_id), |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 324 | post_body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 325 | body = json.loads(body) |
Ghanshyam | e842106 | 2014-06-02 15:58:21 +0900 | [diff] [blame] | 326 | self.validate_response(common_schema.update_server_metadata, |
| 327 | resp, body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 328 | return resp, body['metadata'] |
| 329 | |
| 330 | def get_server_metadata_item(self, server_id, key): |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 331 | resp, body = self.get("servers/%s/metadata/%s" % (str(server_id), key)) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 332 | body = json.loads(body) |
Ghanshyam | eaaa6a4 | 2014-04-25 18:38:21 +0900 | [diff] [blame] | 333 | self.validate_response(schema.set_get_server_metadata_item, |
| 334 | resp, body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 335 | return resp, body['meta'] |
| 336 | |
| 337 | def set_server_metadata_item(self, server_id, key, meta): |
| 338 | post_body = json.dumps({'meta': meta}) |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 339 | resp, body = self.put('servers/%s/metadata/%s' % (str(server_id), key), |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 340 | post_body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 341 | body = json.loads(body) |
Ghanshyam | eaaa6a4 | 2014-04-25 18:38:21 +0900 | [diff] [blame] | 342 | self.validate_response(schema.set_get_server_metadata_item, |
| 343 | resp, body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 344 | return resp, body['meta'] |
| 345 | |
| 346 | def delete_server_metadata_item(self, server_id, key): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 347 | resp, body = self.delete("servers/%s/metadata/%s" % |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 348 | (str(server_id), key)) |
Ghanshyam | eaaa6a4 | 2014-04-25 18:38:21 +0900 | [diff] [blame] | 349 | self.validate_response(common_schema.delete_server_metadata_item, |
| 350 | resp, body) |
Daryl Walleck | 73a9e7a | 2011-11-15 17:43:31 -0600 | [diff] [blame] | 351 | return resp, body |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 352 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 353 | def stop(self, server_id, **kwargs): |
| 354 | return self.action(server_id, 'os-stop', None, **kwargs) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 355 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 356 | def start(self, server_id, **kwargs): |
| 357 | return self.action(server_id, 'os-start', None, **kwargs) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 358 | |
| 359 | def attach_volume(self, server_id, volume_id, device='/dev/vdz'): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 360 | """Attaches a volume to a server instance.""" |
Zhongyue Luo | 30a563f | 2012-09-30 23:43:50 +0900 | [diff] [blame] | 361 | post_body = json.dumps({ |
| 362 | 'volumeAttachment': { |
| 363 | 'volumeId': volume_id, |
| 364 | 'device': device, |
| 365 | } |
| 366 | }) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 367 | resp, body = self.post('servers/%s/os-volume_attachments' % server_id, |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 368 | post_body) |
Ghanshyam | 385c4e7 | 2014-03-27 11:42:25 +0900 | [diff] [blame] | 369 | body = json.loads(body) |
| 370 | self.validate_response(schema.attach_volume, resp, body) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 371 | return resp, body |
| 372 | |
| 373 | def detach_volume(self, server_id, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 374 | """Detaches a volume from a server instance.""" |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 375 | resp, body = self.delete('servers/%s/os-volume_attachments/%s' % |
| 376 | (server_id, volume_id)) |
Ghanshyam | 385c4e7 | 2014-03-27 11:42:25 +0900 | [diff] [blame] | 377 | self.validate_response(schema.detach_volume, resp, body) |
Dan Smith | c18d8c6 | 2012-07-02 08:09:26 -0700 | [diff] [blame] | 378 | return resp, body |
sapan-kona | 775cf63 | 2012-06-22 00:32:36 +0530 | [diff] [blame] | 379 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 380 | def add_security_group(self, server_id, name): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 381 | """Adds a security group to the server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 382 | return self.action(server_id, 'addSecurityGroup', None, name=name) |
sapan-kona | 775cf63 | 2012-06-22 00:32:36 +0530 | [diff] [blame] | 383 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 384 | def remove_security_group(self, server_id, name): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 385 | """Removes a security group from the server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 386 | return self.action(server_id, 'removeSecurityGroup', None, name=name) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 387 | |
| 388 | def live_migrate_server(self, server_id, dest_host, use_block_migration): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 389 | """This should be called with administrator privileges .""" |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 390 | |
| 391 | migrate_params = { |
| 392 | "disk_over_commit": False, |
| 393 | "block_migration": use_block_migration, |
| 394 | "host": dest_host |
| 395 | } |
| 396 | |
| 397 | req_body = json.dumps({'os-migrateLive': migrate_params}) |
| 398 | |
vponomaryov | f4c27f9 | 2014-02-18 10:56:42 +0200 | [diff] [blame] | 399 | resp, body = self.post("servers/%s/action" % str(server_id), req_body) |
Ghanshyam | 997c909 | 2014-04-03 19:00:20 +0900 | [diff] [blame] | 400 | self.validate_response(common_schema.server_actions_common_schema, |
| 401 | resp, body) |
Mate Lakat | 99ee914 | 2012-09-14 12:34:46 +0100 | [diff] [blame] | 402 | return resp, body |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 403 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 404 | def migrate_server(self, server_id, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 405 | """Migrates a server to a new host.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 406 | return self.action(server_id, 'migrate', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 407 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 408 | def lock_server(self, server_id, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 409 | """Locks the given server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 410 | return self.action(server_id, 'lock', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 411 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 412 | def unlock_server(self, server_id, **kwargs): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 413 | """UNlocks the given server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 414 | return self.action(server_id, 'unlock', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 415 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 416 | def suspend_server(self, server_id, **kwargs): |
Ken'ichi Ohmichi | 39437e2 | 2013-10-06 00:21:38 +0900 | [diff] [blame] | 417 | """Suspends the provided server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 418 | return self.action(server_id, 'suspend', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 419 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 420 | def resume_server(self, server_id, **kwargs): |
Ken'ichi Ohmichi | 39437e2 | 2013-10-06 00:21:38 +0900 | [diff] [blame] | 421 | """Un-suspends the provided server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 422 | return self.action(server_id, 'resume', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 423 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 424 | def pause_server(self, server_id, **kwargs): |
Ken'ichi Ohmichi | 39437e2 | 2013-10-06 00:21:38 +0900 | [diff] [blame] | 425 | """Pauses the provided server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 426 | return self.action(server_id, 'pause', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 427 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 428 | def unpause_server(self, server_id, **kwargs): |
Ken'ichi Ohmichi | 39437e2 | 2013-10-06 00:21:38 +0900 | [diff] [blame] | 429 | """Un-pauses the provided server.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 430 | return self.action(server_id, 'unpause', None, **kwargs) |
Daryl Walleck | 3d3f610 | 2012-11-09 15:16:42 -0600 | [diff] [blame] | 431 | |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 432 | def reset_state(self, server_id, state='error'): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 433 | """Resets the state of a server to active/error.""" |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 434 | return self.action(server_id, 'os-resetState', None, state=state) |
Attila Fazekas | e4cb04c | 2013-01-29 09:51:58 +0100 | [diff] [blame] | 435 | |
Ken'ichi Ohmichi | 39437e2 | 2013-10-06 00:21:38 +0900 | [diff] [blame] | 436 | def shelve_server(self, server_id, **kwargs): |
| 437 | """Shelves the provided server.""" |
| 438 | return self.action(server_id, 'shelve', None, **kwargs) |
| 439 | |
| 440 | def unshelve_server(self, server_id, **kwargs): |
| 441 | """Un-shelves the provided server.""" |
| 442 | return self.action(server_id, 'unshelve', None, **kwargs) |
| 443 | |
Ken'ichi Ohmichi | 17b7f11 | 2014-02-20 06:33:49 +0900 | [diff] [blame] | 444 | def shelve_offload_server(self, server_id, **kwargs): |
| 445 | """Shelve-offload the provided server.""" |
| 446 | return self.action(server_id, 'shelveOffload', None, **kwargs) |
| 447 | |
Attila Fazekas | e4cb04c | 2013-01-29 09:51:58 +0100 | [diff] [blame] | 448 | def get_console_output(self, server_id, length): |
Davanum Srinivas | 8a841c7 | 2014-06-19 18:33:14 -0400 | [diff] [blame] | 449 | kwargs = {'length': length} if length else {} |
Attila Fazekas | d429928 | 2013-02-22 13:25:23 +0100 | [diff] [blame] | 450 | return self.action(server_id, 'os-getConsoleOutput', 'output', |
Davanum Srinivas | 8a841c7 | 2014-06-19 18:33:14 -0400 | [diff] [blame] | 451 | common_schema.get_console_output, **kwargs) |
Rami Vaknin | 76bc8bd | 2013-02-17 16:18:27 +0200 | [diff] [blame] | 452 | |
| 453 | def list_virtual_interfaces(self, server_id): |
| 454 | """ |
| 455 | List the virtual interfaces used in an instance. |
| 456 | """ |
| 457 | resp, body = self.get('/'.join(['servers', server_id, |
| 458 | 'os-virtual-interfaces'])) |
Ghanshyam | 08ce58d | 2014-04-04 14:51:14 +0900 | [diff] [blame] | 459 | body = json.loads(body) |
| 460 | self.validate_response(schema.list_virtual_interfaces, resp, body) |
| 461 | return resp, body |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 462 | |
Yuiko Takada | 7835d50 | 2014-01-15 10:15:03 +0000 | [diff] [blame] | 463 | def rescue_server(self, server_id, **kwargs): |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 464 | """Rescue the provided server.""" |
Ghanshyam | 8845791 | 2014-07-25 16:02:12 +0900 | [diff] [blame] | 465 | return self.action(server_id, 'rescue', 'adminPass', |
| 466 | schema.rescue_server, **kwargs) |
nithya-ganesan | e6a36c8 | 2013-02-15 14:38:27 +0000 | [diff] [blame] | 467 | |
| 468 | def unrescue_server(self, server_id): |
| 469 | """Unrescue the provided server.""" |
| 470 | return self.action(server_id, 'unrescue', None) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 471 | |
Zhu Zhu | da07085 | 2013-09-25 08:07:57 -0500 | [diff] [blame] | 472 | def get_server_diagnostics(self, server_id): |
| 473 | """Get the usage data for a server.""" |
| 474 | resp, body = self.get("servers/%s/diagnostics" % str(server_id)) |
| 475 | return resp, json.loads(body) |
| 476 | |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 477 | def list_instance_actions(self, server_id): |
| 478 | """List the provided server action.""" |
| 479 | resp, body = self.get("servers/%s/os-instance-actions" % |
| 480 | str(server_id)) |
| 481 | body = json.loads(body) |
Ghanshyam | 2996609 | 2014-04-07 17:27:41 +0900 | [diff] [blame] | 482 | self.validate_response(schema.list_instance_actions, resp, body) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 483 | return resp, body['instanceActions'] |
| 484 | |
| 485 | def get_instance_action(self, server_id, request_id): |
| 486 | """Returns the action details of the provided server.""" |
| 487 | resp, body = self.get("servers/%s/os-instance-actions/%s" % |
| 488 | (str(server_id), str(request_id))) |
| 489 | body = json.loads(body) |
Ghanshyam | 4b41dfd | 2014-07-17 13:40:38 +0900 | [diff] [blame] | 490 | self.validate_response(schema.get_instance_action, resp, body) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 491 | return resp, body['instanceAction'] |
Lingxian Kong | aecc109 | 2013-10-03 16:18:46 +0800 | [diff] [blame] | 492 | |
| 493 | def force_delete_server(self, server_id, **kwargs): |
| 494 | """Force delete a server.""" |
| 495 | return self.action(server_id, 'forceDelete', None, **kwargs) |
| 496 | |
| 497 | def restore_soft_deleted_server(self, server_id, **kwargs): |
| 498 | """Restore a soft-deleted server.""" |
| 499 | return self.action(server_id, 'restore', None, **kwargs) |
Ghanshyam Mann | 79f4a09 | 2014-02-27 21:01:31 +0900 | [diff] [blame] | 500 | |
| 501 | def reset_network(self, server_id, **kwargs): |
| 502 | """Resets the Network of a server""" |
| 503 | return self.action(server_id, 'resetNetwork', None, **kwargs) |
| 504 | |
| 505 | def inject_network_info(self, server_id, **kwargs): |
| 506 | """Inject the Network Info into server""" |
| 507 | return self.action(server_id, 'injectNetworkInfo', None, **kwargs) |
Ghanshyam | 86d1a57 | 2014-03-05 10:19:25 +0900 | [diff] [blame] | 508 | |
| 509 | def get_vnc_console(self, server_id, console_type): |
| 510 | """Get URL of VNC console.""" |
| 511 | return self.action(server_id, "os-getVNCConsole", |
Ghanshyam | d6d3040 | 2014-04-02 15:28:37 +0900 | [diff] [blame] | 512 | "console", common_schema.get_vnc_console, |
| 513 | type=console_type) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 514 | |
| 515 | def create_server_group(self, name, policies): |
| 516 | """ |
| 517 | Create the server group |
| 518 | name : Name of the server-group |
| 519 | policies : List of the policies - affinity/anti-affinity) |
| 520 | """ |
| 521 | post_body = { |
| 522 | 'name': name, |
| 523 | 'policies': policies, |
| 524 | } |
| 525 | |
| 526 | post_body = json.dumps({'server_group': post_body}) |
| 527 | resp, body = self.post('os-server-groups', post_body) |
| 528 | |
| 529 | body = json.loads(body) |
Ghanshyam | f81f9fa | 2014-05-23 13:38:56 +0900 | [diff] [blame] | 530 | self.validate_response(schema.create_get_server_group, resp, body) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 531 | return resp, body['server_group'] |
| 532 | |
| 533 | def delete_server_group(self, server_group_id): |
| 534 | """Delete the given server-group.""" |
Ghanshyam | f81f9fa | 2014-05-23 13:38:56 +0900 | [diff] [blame] | 535 | resp, body = self.delete("os-server-groups/%s" % str(server_group_id)) |
| 536 | self.validate_response(schema.delete_server_group, resp, body) |
| 537 | return resp, body |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 538 | |
| 539 | def list_server_groups(self): |
| 540 | """List the server-groups.""" |
| 541 | resp, body = self.get("os-server-groups") |
| 542 | body = json.loads(body) |
Ghanshyam | 438ed3b | 2014-06-18 17:25:41 +0900 | [diff] [blame] | 543 | self.validate_response(schema.list_server_groups, resp, body) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 544 | return resp, body['server_groups'] |
| 545 | |
| 546 | def get_server_group(self, server_group_id): |
| 547 | """Get the details of given server_group.""" |
| 548 | resp, body = self.get("os-server-groups/%s" % str(server_group_id)) |
| 549 | body = json.loads(body) |
Ghanshyam | f81f9fa | 2014-05-23 13:38:56 +0900 | [diff] [blame] | 550 | self.validate_response(schema.create_get_server_group, resp, body) |
Abhijeet.Jain | 87dd445 | 2014-04-23 15:51:23 +0530 | [diff] [blame] | 551 | return resp, body['server_group'] |