ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 16 | from oslo_serialization import jsonutils as json |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 17 | import six |
Matthew Treinish | 8912814 | 2015-04-23 10:44:30 -0400 | [diff] [blame] | 18 | from six.moves.urllib import parse as urllib |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 19 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 20 | from tempest.lib.common import rest_client |
Andrea Frittoli (andreaf) | db9672e | 2016-02-23 14:07:24 -0500 | [diff] [blame] | 21 | from tempest.lib import exceptions as lib_exc |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 22 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 23 | |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 24 | class BaseVolumesClient(rest_client.RestClient): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 25 | """Base client class to send CRUD Volume API requests""" |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 26 | |
Ken'ichi Ohmichi | a39d0be | 2014-12-17 08:46:11 +0000 | [diff] [blame] | 27 | create_resp = 200 |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 28 | |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 29 | def __init__(self, auth_provider, service, region, |
| 30 | default_volume_size=1, **kwargs): |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 31 | super(BaseVolumesClient, self).__init__( |
Ken'ichi Ohmichi | 234da80 | 2015-02-13 04:48:06 +0000 | [diff] [blame] | 32 | auth_provider, service, region, **kwargs) |
| 33 | self.default_volume_size = default_volume_size |
| 34 | |
anju tiwari | 789449a | 2013-08-29 16:56:17 +0530 | [diff] [blame] | 35 | def get_attachment_from_volume(self, volume): |
| 36 | """Return the element 'attachment' from input volumes.""" |
| 37 | return volume['attachments'][0] |
| 38 | |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 39 | def _prepare_params(self, params): |
| 40 | """Prepares params for use in get or _ext_get methods. |
| 41 | |
| 42 | If params is a string it will be left as it is, but if it's not it will |
| 43 | be urlencoded. |
| 44 | """ |
| 45 | if isinstance(params, six.string_types): |
| 46 | return params |
| 47 | return urllib.urlencode(params) |
| 48 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 49 | def list_volumes(self, detail=False, params=None): |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 50 | """List all the volumes created. |
| 51 | |
| 52 | Params can be a string (must be urlencoded) or a dictionary. |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 53 | """ |
Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 54 | url = 'volumes' |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 55 | if detail: |
| 56 | url += '/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 57 | if params: |
Gorka Eguileor | 0ea58af | 2015-06-17 18:32:42 +0200 | [diff] [blame] | 58 | url += '?%s' % self._prepare_params(params) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 59 | |
John Warren | 6177c9e | 2015-08-19 20:00:17 +0000 | [diff] [blame] | 60 | resp, body = self.get(url) |
| 61 | body = json.loads(body) |
| 62 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 63 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 64 | |
bkopilov | 1f161e5 | 2016-04-18 13:27:48 +0300 | [diff] [blame] | 65 | def show_pools(self, detail=False): |
| 66 | # List all the volumes pools (hosts) |
| 67 | url = 'scheduler-stats/get_pools' |
| 68 | if detail: |
| 69 | url += '?detail=True' |
| 70 | |
| 71 | resp, body = self.get(url) |
| 72 | body = json.loads(body) |
| 73 | self.expected_success(200, resp.status) |
| 74 | return rest_client.ResponseBody(resp, body) |
| 75 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 76 | def show_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 77 | """Returns the details of a single volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 78 | url = "volumes/%s" % volume_id |
Attila Fazekas | b8aa759 | 2013-01-26 01:25:45 +0100 | [diff] [blame] | 79 | resp, body = self.get(url) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 80 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 81 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 82 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 83 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 84 | def create_volume(self, **kwargs): |
Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 85 | """Creates a new Volume. |
| 86 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 87 | Available params: see http://developer.openstack.org/ |
| 88 | api-ref-blockstorage-v2.html#createVolume |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 89 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 90 | if 'size' not in kwargs: |
| 91 | kwargs['size'] = self.default_volume_size |
| 92 | post_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 93 | resp, body = self.post('volumes', post_body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 94 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 95 | self.expected_success(self.create_resp, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 96 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 97 | |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 98 | def update_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 99 | """Updates the Specified Volume. |
| 100 | |
| 101 | Available params: see http://developer.openstack.org/ |
| 102 | api-ref-blockstorage-v2.html#updateVolume |
| 103 | """ |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 104 | put_body = json.dumps({'volume': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 105 | resp, body = self.put('volumes/%s' % volume_id, put_body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 106 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 107 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 108 | return rest_client.ResponseBody(resp, body) |
QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 109 | |
rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 110 | def delete_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 111 | """Deletes the Specified Volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 112 | resp, body = self.delete("volumes/%s" % volume_id) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 113 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 114 | return rest_client.ResponseBody(resp, body) |
rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 115 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 116 | def upload_volume(self, volume_id, **kwargs): |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 117 | """Uploads a volume in Glance.""" |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 118 | post_body = json.dumps({'os-volume_upload_image': kwargs}) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 119 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 120 | resp, body = self.post(url, post_body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 121 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 122 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 123 | return rest_client.ResponseBody(resp, body) |
Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 124 | |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 125 | def attach_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 126 | """Attaches a volume to a given instance on a given mountpoint. |
| 127 | |
| 128 | Available params: see http://developer.openstack.org/ |
| 129 | api-ref-blockstorage-v2.html#attachVolume |
| 130 | """ |
Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 131 | post_body = json.dumps({'os-attach': kwargs}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 132 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 133 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 134 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 135 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 136 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 137 | def set_bootable_volume(self, volume_id, **kwargs): |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 138 | """set a bootable flag for a volume - true or false.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 139 | post_body = json.dumps({'os-set_bootable': kwargs}) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 140 | url = 'volumes/%s/action' % (volume_id) |
| 141 | resp, body = self.post(url, post_body) |
| 142 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 143 | return rest_client.ResponseBody(resp, body) |
bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 144 | |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 145 | def detach_volume(self, volume_id): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 146 | """Detaches a volume from an instance.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 147 | post_body = json.dumps({'os-detach': {}}) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 148 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 149 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 150 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 151 | return rest_client.ResponseBody(resp, body) |
Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 152 | |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 153 | def reserve_volume(self, volume_id): |
| 154 | """Reserves a volume.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 155 | post_body = json.dumps({'os-reserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 156 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 157 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 158 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 159 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 160 | |
| 161 | def unreserve_volume(self, volume_id): |
| 162 | """Restore a reserved volume .""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 163 | post_body = json.dumps({'os-unreserve': {}}) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 164 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 165 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 166 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 167 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 168 | |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 169 | def is_resource_deleted(self, id): |
| 170 | try: |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 171 | self.show_volume(id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 172 | except lib_exc.NotFound: |
David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 173 | return True |
| 174 | return False |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 175 | |
Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 176 | @property |
| 177 | def resource_type(self): |
| 178 | """Returns the primary type of resource this client works with.""" |
| 179 | return 'volume' |
| 180 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 181 | def extend_volume(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 182 | """Extend a volume. |
| 183 | |
| 184 | Available params: see http://developer.openstack.org/ |
| 185 | api-ref-blockstorage-v2.html#extendVolume |
| 186 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 187 | post_body = json.dumps({'os-extend': kwargs}) |
wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 188 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 189 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 190 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 191 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 192 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 193 | def reset_volume_status(self, volume_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 194 | """Reset the Specified Volume's Status. |
| 195 | |
| 196 | Available params: see http://developer.openstack.org/ |
| 197 | api-ref-blockstorage-v2.html#resetVolume |
| 198 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 199 | post_body = json.dumps({'os-reset_status': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 200 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 201 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 202 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 203 | |
| 204 | def volume_begin_detaching(self, volume_id): |
| 205 | """Volume Begin Detaching.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 206 | # ref cinder/api/contrib/volume_actions.py#L158 |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 207 | post_body = json.dumps({'os-begin_detaching': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 208 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 209 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 210 | return rest_client.ResponseBody(resp, body) |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 211 | |
| 212 | def volume_roll_detaching(self, volume_id): |
| 213 | """Volume Roll Detaching.""" |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 214 | # cinder/api/contrib/volume_actions.py#L170 |
wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 215 | post_body = json.dumps({'os-roll_detaching': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 216 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 217 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 218 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 219 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 220 | def create_volume_transfer(self, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 221 | """Create a volume transfer. |
| 222 | |
| 223 | Available params: see http://developer.openstack.org/ |
| 224 | api-ref-blockstorage-v2.html#createVolumeTransfer |
| 225 | """ |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 226 | post_body = json.dumps({'transfer': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 227 | resp, body = self.post('os-volume-transfer', post_body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 228 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 229 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 230 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 231 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 232 | def show_volume_transfer(self, transfer_id): |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 233 | """Returns the details of a volume transfer.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 234 | url = "os-volume-transfer/%s" % transfer_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 235 | resp, body = self.get(url) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 236 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 237 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 238 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 239 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 240 | def list_volume_transfers(self, **params): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 241 | """List all the volume transfers created. |
| 242 | |
| 243 | Available params: see http://developer.openstack.org/ |
| 244 | api-ref-blockstorage-v2.html#listVolumeTransfer |
| 245 | """ |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 246 | url = 'os-volume-transfer' |
| 247 | if params: |
| 248 | url += '?%s' % urllib.urlencode(params) |
| 249 | resp, body = self.get(url) |
| 250 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 251 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 252 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 253 | |
| 254 | def delete_volume_transfer(self, transfer_id): |
| 255 | """Delete a volume transfer.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 256 | resp, body = self.delete("os-volume-transfer/%s" % transfer_id) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 257 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 258 | return rest_client.ResponseBody(resp, body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 259 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 260 | def accept_volume_transfer(self, transfer_id, **kwargs): |
guo xian | d8bc1cd | 2016-06-23 12:35:43 +0800 | [diff] [blame] | 261 | """Accept a volume transfer. |
| 262 | |
| 263 | Available params: see http://developer.openstack.org/ |
| 264 | api-ref-blockstorage-v2.html#acceptVolumeTransfer |
| 265 | """ |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 266 | url = 'os-volume-transfer/%s/accept' % transfer_id |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 267 | post_body = json.dumps({'accept': kwargs}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 268 | resp, body = self.post(url, post_body) |
wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 269 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 270 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 271 | return rest_client.ResponseBody(resp, body) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 272 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 273 | def update_volume_readonly(self, volume_id, **kwargs): |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 274 | """Update the Specified Volume readonly.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 275 | post_body = json.dumps({'os-update_readonly_flag': kwargs}) |
zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 276 | url = 'volumes/%s/action' % (volume_id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 277 | resp, body = self.post(url, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 278 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 279 | return rest_client.ResponseBody(resp, body) |
wanghao | 9d3d6cb | 2013-11-12 15:10:10 +0800 | [diff] [blame] | 280 | |
| 281 | def force_delete_volume(self, volume_id): |
| 282 | """Force Delete Volume.""" |
| 283 | post_body = json.dumps({'os-force_delete': {}}) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 284 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 285 | self.expected_success(202, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 286 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 287 | |
| 288 | def create_volume_metadata(self, volume_id, metadata): |
| 289 | """Create metadata for the volume.""" |
| 290 | put_body = json.dumps({'metadata': metadata}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 291 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 292 | resp, body = self.post(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 293 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 294 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 295 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 296 | |
Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 297 | def show_volume_metadata(self, volume_id): |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 298 | """Get metadata of the volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 299 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 300 | resp, body = self.get(url) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 301 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 302 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 303 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 304 | |
| 305 | def update_volume_metadata(self, volume_id, metadata): |
| 306 | """Update metadata for the volume.""" |
| 307 | put_body = json.dumps({'metadata': metadata}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 308 | url = "volumes/%s/metadata" % volume_id |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 309 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 310 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 311 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 312 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 313 | |
| 314 | def update_volume_metadata_item(self, volume_id, id, meta_item): |
| 315 | """Update metadata item for the volume.""" |
| 316 | put_body = json.dumps({'meta': meta_item}) |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 317 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 318 | resp, body = self.put(url, put_body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 319 | body = json.loads(body) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 320 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 321 | return rest_client.ResponseBody(resp, body) |
huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 322 | |
| 323 | def delete_volume_metadata_item(self, volume_id, id): |
| 324 | """Delete metadata item for the volume.""" |
guo yunxian | 6cdf056 | 2016-08-17 16:21:52 +0800 | [diff] [blame^] | 325 | url = "volumes/%s/metadata/%s" % (volume_id, id) |
Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 326 | resp, body = self.delete(url) |
Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 327 | self.expected_success(200, resp.status) |
Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 328 | return rest_client.ResponseBody(resp, body) |
Zhi Kun Liu | 6e6cf83 | 2014-05-08 17:25:22 +0800 | [diff] [blame] | 329 | |
lkuchlan | 119b2f2 | 2016-06-20 20:59:41 +0300 | [diff] [blame] | 330 | def update_volume_image_metadata(self, volume_id, **kwargs): |
lkuchlan | 6a61bd9 | 2016-06-23 22:46:08 +0300 | [diff] [blame] | 331 | """Update image metadata for the volume. |
| 332 | |
| 333 | Available params: see http://developer.openstack.org/ |
| 334 | api-ref-blockstorage-v2.html |
| 335 | #setVolumeimagemetadata |
| 336 | """ |
lkuchlan | 119b2f2 | 2016-06-20 20:59:41 +0300 | [diff] [blame] | 337 | post_body = json.dumps({'os-set_image_metadata': {'metadata': kwargs}}) |
| 338 | url = "volumes/%s/action" % (volume_id) |
| 339 | resp, body = self.post(url, post_body) |
| 340 | body = json.loads(body) |
| 341 | self.expected_success(200, resp.status) |
| 342 | return rest_client.ResponseBody(resp, body) |
| 343 | |
| 344 | def delete_volume_image_metadata(self, volume_id, key_name): |
| 345 | """Delete image metadata item for the volume.""" |
| 346 | post_body = json.dumps({'os-unset_image_metadata': {'key': key_name}}) |
| 347 | url = "volumes/%s/action" % (volume_id) |
| 348 | resp, body = self.post(url, post_body) |
| 349 | self.expected_success(200, resp.status) |
| 350 | return rest_client.ResponseBody(resp, body) |
| 351 | |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 352 | def retype_volume(self, volume_id, **kwargs): |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 353 | """Updates volume with new volume type.""" |
Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 354 | post_body = json.dumps({'os-retype': kwargs}) |
nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 355 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 356 | self.expected_success(202, resp.status) |