blob: 41d9af2e64f914e37cfa072f4abd9bf1400e882f [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# Copyright 2012 OpenStack Foundation
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
16from oslo_serialization import jsonutils as json
17from six.moves.urllib import parse as urllib
18
19from tempest.lib.api_schema.response.compute.v2_1 import volumes as schema
20from tempest.lib.common import rest_client
21from tempest.lib import exceptions as lib_exc
Ghanshyamee9af302016-02-25 06:12:43 +090022from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050023
24
Ghanshyamee9af302016-02-25 06:12:43 +090025class VolumesClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050026
27 def list_volumes(self, detail=False, **params):
28 """List all the volumes created."""
29 url = 'os-volumes'
30
31 if detail:
32 url += '/detail'
33 if params:
34 url += '?%s' % urllib.urlencode(params)
35
36 resp, body = self.get(url)
37 body = json.loads(body)
38 self.validate_response(schema.list_volumes, resp, body)
39 return rest_client.ResponseBody(resp, body)
40
41 def show_volume(self, volume_id):
42 """Return the details of a single volume."""
43 url = "os-volumes/%s" % volume_id
44 resp, body = self.get(url)
45 body = json.loads(body)
46 self.validate_response(schema.create_get_volume, resp, body)
47 return rest_client.ResponseBody(resp, body)
48
49 def create_volume(self, **kwargs):
50 """Create a new Volume.
51
52 Available params: see http://developer.openstack.org/
53 api-ref-compute-v2.1.html#createVolume
54 """
55 post_body = json.dumps({'volume': kwargs})
56 resp, body = self.post('os-volumes', post_body)
57 body = json.loads(body)
58 self.validate_response(schema.create_get_volume, resp, body)
59 return rest_client.ResponseBody(resp, body)
60
61 def delete_volume(self, volume_id):
62 """Delete the Specified Volume."""
63 resp, body = self.delete("os-volumes/%s" % volume_id)
64 self.validate_response(schema.delete_volume, resp, body)
65 return rest_client.ResponseBody(resp, body)
66
67 def is_resource_deleted(self, id):
68 try:
69 self.show_volume(id)
70 except lib_exc.NotFound:
71 return True
72 return False
73
74 @property
75 def resource_type(self):
76 """Return the primary type of resource this client works with."""
77 return 'volume'