| 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 | |
| Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 65 | def show_volume(self, volume_id): |
| Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 66 | """Returns the details of a single volume.""" |
| Rohit Karajgi | dd47d7e | 2012-07-31 04:11:01 -0700 | [diff] [blame] | 67 | url = "volumes/%s" % str(volume_id) |
| Attila Fazekas | b8aa759 | 2013-01-26 01:25:45 +0100 | [diff] [blame] | 68 | resp, body = self.get(url) |
| rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 69 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 70 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 71 | return rest_client.ResponseBody(resp, body) |
| rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 72 | |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 73 | def create_volume(self, **kwargs): |
| Ken'ichi Ohmichi | b279084 | 2015-11-17 11:46:13 +0000 | [diff] [blame] | 74 | """Creates a new Volume. |
| 75 | |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 76 | Available params: see http://developer.openstack.org/ |
| 77 | api-ref-blockstorage-v2.html#createVolume |
| rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 78 | """ |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 79 | if 'size' not in kwargs: |
| 80 | kwargs['size'] = self.default_volume_size |
| 81 | post_body = json.dumps({'volume': kwargs}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 82 | resp, body = self.post('volumes', post_body) |
| rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 83 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 84 | self.expected_success(self.create_resp, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 85 | return rest_client.ResponseBody(resp, body) |
| rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 86 | |
| QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 87 | def update_volume(self, volume_id, **kwargs): |
| 88 | """Updates the Specified Volume.""" |
| 89 | put_body = json.dumps({'volume': kwargs}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 90 | resp, body = self.put('volumes/%s' % volume_id, put_body) |
| QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 91 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 92 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 93 | return rest_client.ResponseBody(resp, body) |
| QingXin Meng | 611768a | 2013-09-18 00:51:33 -0700 | [diff] [blame] | 94 | |
| rajalakshmi-ganesan | ddd9e0e | 2012-03-21 00:49:22 +0530 | [diff] [blame] | 95 | def delete_volume(self, volume_id): |
| Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 96 | """Deletes the Specified Volume.""" |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 97 | resp, body = self.delete("volumes/%s" % str(volume_id)) |
| 98 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 99 | return rest_client.ResponseBody(resp, body) |
| rajalakshmi-ganesan | b446557 | 2012-03-22 01:22:50 +0530 | [diff] [blame] | 100 | |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 101 | def upload_volume(self, volume_id, **kwargs): |
| Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 102 | """Uploads a volume in Glance.""" |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 103 | post_body = json.dumps({'os-volume_upload_image': kwargs}) |
| Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 104 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 105 | resp, body = self.post(url, post_body) |
| Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 106 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 107 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 108 | return rest_client.ResponseBody(resp, body) |
| Giulio Fidente | 884e9da | 2013-06-21 17:25:42 +0200 | [diff] [blame] | 109 | |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 110 | def attach_volume(self, volume_id, **kwargs): |
| Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 111 | """Attaches a volume to a given instance on a given mountpoint.""" |
| Ghanshyam | 8fc0ed2 | 2015-12-18 10:25:14 +0900 | [diff] [blame] | 112 | post_body = json.dumps({'os-attach': kwargs}) |
| Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 113 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 114 | resp, body = self.post(url, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 115 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 116 | return rest_client.ResponseBody(resp, body) |
| Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 117 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 118 | def set_bootable_volume(self, volume_id, **kwargs): |
| bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 119 | """set a bootable flag for a volume - true or false.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 120 | post_body = json.dumps({'os-set_bootable': kwargs}) |
| bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 121 | url = 'volumes/%s/action' % (volume_id) |
| 122 | resp, body = self.post(url, post_body) |
| 123 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 124 | return rest_client.ResponseBody(resp, body) |
| bkopilov | 8a657ae | 2015-05-11 11:45:23 +0300 | [diff] [blame] | 125 | |
| Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 126 | def detach_volume(self, volume_id): |
| Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 127 | """Detaches a volume from an instance.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 128 | post_body = json.dumps({'os-detach': {}}) |
| Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 129 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 130 | resp, body = self.post(url, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 131 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 132 | return rest_client.ResponseBody(resp, body) |
| Rohit Karajgi | a42fe44 | 2012-09-21 03:08:33 -0700 | [diff] [blame] | 133 | |
| zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 134 | def reserve_volume(self, volume_id): |
| 135 | """Reserves a volume.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 136 | post_body = json.dumps({'os-reserve': {}}) |
| zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 137 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 138 | resp, body = self.post(url, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 139 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 140 | return rest_client.ResponseBody(resp, body) |
| zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 141 | |
| 142 | def unreserve_volume(self, volume_id): |
| 143 | """Restore a reserved volume .""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 144 | post_body = json.dumps({'os-unreserve': {}}) |
| zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 145 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 146 | resp, body = self.post(url, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 147 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 148 | return rest_client.ResponseBody(resp, body) |
| zhangyanzi | 6b63243 | 2013-10-24 19:08:50 +0800 | [diff] [blame] | 149 | |
| David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 150 | def is_resource_deleted(self, id): |
| 151 | try: |
| Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 152 | self.show_volume(id) |
| Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 153 | except lib_exc.NotFound: |
| David Kranz | 6aceb4a | 2012-06-05 14:05:45 -0400 | [diff] [blame] | 154 | return True |
| 155 | return False |
| wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 156 | |
| Matt Riedemann | d2b9651 | 2014-10-13 10:18:16 -0700 | [diff] [blame] | 157 | @property |
| 158 | def resource_type(self): |
| 159 | """Returns the primary type of resource this client works with.""" |
| 160 | return 'volume' |
| 161 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 162 | def extend_volume(self, volume_id, **kwargs): |
| wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 163 | """Extend a volume.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 164 | post_body = json.dumps({'os-extend': kwargs}) |
| wanghao | 5b98175 | 2013-10-22 11:41:41 +0800 | [diff] [blame] | 165 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 166 | resp, body = self.post(url, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 167 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 168 | return rest_client.ResponseBody(resp, body) |
| wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 169 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 170 | def reset_volume_status(self, volume_id, **kwargs): |
| wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 171 | """Reset the Specified Volume's Status.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 172 | post_body = json.dumps({'os-reset_status': kwargs}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 173 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 174 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 175 | return rest_client.ResponseBody(resp, body) |
| wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 176 | |
| 177 | def volume_begin_detaching(self, volume_id): |
| 178 | """Volume Begin Detaching.""" |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 179 | # ref cinder/api/contrib/volume_actions.py#L158 |
| wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 180 | post_body = json.dumps({'os-begin_detaching': {}}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 181 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 182 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 183 | return rest_client.ResponseBody(resp, body) |
| wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 184 | |
| 185 | def volume_roll_detaching(self, volume_id): |
| 186 | """Volume Roll Detaching.""" |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 187 | # cinder/api/contrib/volume_actions.py#L170 |
| wanghao | aa1f2f9 | 2013-10-10 11:30:37 +0800 | [diff] [blame] | 188 | post_body = json.dumps({'os-roll_detaching': {}}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 189 | resp, body = self.post('volumes/%s/action' % volume_id, 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) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 192 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 193 | def create_volume_transfer(self, **kwargs): |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 194 | """Create a volume transfer.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 195 | post_body = json.dumps({'transfer': kwargs}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 196 | resp, body = self.post('os-volume-transfer', post_body) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 197 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 198 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 199 | return rest_client.ResponseBody(resp, body) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 200 | |
| Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 201 | def show_volume_transfer(self, transfer_id): |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 202 | """Returns the details of a volume transfer.""" |
| 203 | url = "os-volume-transfer/%s" % str(transfer_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 204 | resp, body = self.get(url) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 205 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 206 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 207 | return rest_client.ResponseBody(resp, body) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 208 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 209 | def list_volume_transfers(self, **params): |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 210 | """List all the volume transfers created.""" |
| 211 | url = 'os-volume-transfer' |
| 212 | if params: |
| 213 | url += '?%s' % urllib.urlencode(params) |
| 214 | resp, body = self.get(url) |
| 215 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 216 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 217 | return rest_client.ResponseBody(resp, body) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 218 | |
| 219 | def delete_volume_transfer(self, transfer_id): |
| 220 | """Delete a volume transfer.""" |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 221 | resp, body = self.delete("os-volume-transfer/%s" % str(transfer_id)) |
| 222 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 223 | return rest_client.ResponseBody(resp, body) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 224 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 225 | def accept_volume_transfer(self, transfer_id, **kwargs): |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 226 | """Accept a volume transfer.""" |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 227 | url = 'os-volume-transfer/%s/accept' % transfer_id |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 228 | post_body = json.dumps({'accept': kwargs}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 229 | resp, body = self.post(url, post_body) |
| wingwj | cbd82dc | 2013-10-22 16:38:39 +0800 | [diff] [blame] | 230 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 231 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 232 | return rest_client.ResponseBody(resp, body) |
| zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 233 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 234 | def update_volume_readonly(self, volume_id, **kwargs): |
| zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 235 | """Update the Specified Volume readonly.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 236 | post_body = json.dumps({'os-update_readonly_flag': kwargs}) |
| zhangyanzi | aa18007 | 2013-11-21 12:31:26 +0800 | [diff] [blame] | 237 | url = 'volumes/%s/action' % (volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 238 | resp, body = self.post(url, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 239 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 240 | return rest_client.ResponseBody(resp, body) |
| wanghao | 9d3d6cb | 2013-11-12 15:10:10 +0800 | [diff] [blame] | 241 | |
| 242 | def force_delete_volume(self, volume_id): |
| 243 | """Force Delete Volume.""" |
| 244 | post_body = json.dumps({'os-force_delete': {}}) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 245 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 246 | self.expected_success(202, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 247 | return rest_client.ResponseBody(resp, body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 248 | |
| 249 | def create_volume_metadata(self, volume_id, metadata): |
| 250 | """Create metadata for the volume.""" |
| 251 | put_body = json.dumps({'metadata': metadata}) |
| 252 | url = "volumes/%s/metadata" % str(volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 253 | resp, body = self.post(url, put_body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 254 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 255 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 256 | return rest_client.ResponseBody(resp, body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 257 | |
| Ken'ichi Ohmichi | 35798fb | 2015-04-06 01:22:41 +0000 | [diff] [blame] | 258 | def show_volume_metadata(self, volume_id): |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 259 | """Get metadata of the volume.""" |
| 260 | url = "volumes/%s/metadata" % str(volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 261 | resp, body = self.get(url) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 262 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 263 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 264 | return rest_client.ResponseBody(resp, body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 265 | |
| 266 | def update_volume_metadata(self, volume_id, metadata): |
| 267 | """Update metadata for the volume.""" |
| 268 | put_body = json.dumps({'metadata': metadata}) |
| 269 | url = "volumes/%s/metadata" % str(volume_id) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 270 | resp, body = self.put(url, put_body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 271 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 272 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 273 | return rest_client.ResponseBody(resp, body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 274 | |
| 275 | def update_volume_metadata_item(self, volume_id, id, meta_item): |
| 276 | """Update metadata item for the volume.""" |
| 277 | put_body = json.dumps({'meta': meta_item}) |
| 278 | url = "volumes/%s/metadata/%s" % (str(volume_id), str(id)) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 279 | resp, body = self.put(url, put_body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 280 | body = json.loads(body) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 281 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 282 | return rest_client.ResponseBody(resp, body) |
| huangtianhua | 0ff4168 | 2013-12-16 14:49:31 +0800 | [diff] [blame] | 283 | |
| 284 | def delete_volume_metadata_item(self, volume_id, id): |
| 285 | """Delete metadata item for the volume.""" |
| 286 | url = "volumes/%s/metadata/%s" % (str(volume_id), str(id)) |
| Valeriy Ponomaryov | 88686d8 | 2014-02-16 12:24:51 +0200 | [diff] [blame] | 287 | resp, body = self.delete(url) |
| Swapnil Kulkarni | d9df38c | 2014-08-16 18:06:52 +0000 | [diff] [blame] | 288 | self.expected_success(200, resp.status) |
| Ken'ichi Ohmichi | 90d446a | 2016-03-02 10:17:38 -0800 | [diff] [blame] | 289 | return rest_client.ResponseBody(resp, body) |
| Zhi Kun Liu | 6e6cf83 | 2014-05-08 17:25:22 +0800 | [diff] [blame] | 290 | |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 291 | def retype_volume(self, volume_id, **kwargs): |
| nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 292 | """Updates volume with new volume type.""" |
| Ghanshyam | 58a9e87 | 2015-12-18 10:46:07 +0900 | [diff] [blame] | 293 | post_body = json.dumps({'os-retype': kwargs}) |
| nayna-patel | 78f743e | 2015-01-09 10:52:51 +0000 | [diff] [blame] | 294 | resp, body = self.post('volumes/%s/action' % volume_id, post_body) |
| 295 | self.expected_success(202, resp.status) |