dwalleck | e62b9f0 | 2012-10-10 23:34:42 -0500 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2012 OpenStack, LLC |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 18 | import json |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 19 | import urllib |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 20 | |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 21 | from tempest.common.rest_client import RestClient |
| 22 | |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 23 | |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 24 | class FlavorsClientJSON(RestClient): |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 25 | |
Daryl Walleck | 587385b | 2012-03-03 13:00:26 -0600 | [diff] [blame] | 26 | def __init__(self, config, username, password, auth_url, tenant_name=None): |
Tiago Mello | eda03b5 | 2012-08-22 23:47:29 -0300 | [diff] [blame] | 27 | super(FlavorsClientJSON, self).__init__(config, username, password, |
| 28 | auth_url, tenant_name) |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 29 | self.service = self.config.compute.catalog_type |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 30 | |
| 31 | def list_flavors(self, params=None): |
| 32 | url = 'flavors' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 33 | if params: |
| 34 | url += '?%s' % urllib.urlencode(params) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 35 | |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 36 | resp, body = self.get(url) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 37 | body = json.loads(body) |
Daryl Walleck | 74d0409 | 2012-01-10 23:33:46 -0600 | [diff] [blame] | 38 | return resp, body['flavors'] |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 39 | |
| 40 | def list_flavors_with_detail(self, params=None): |
| 41 | url = 'flavors/detail' |
Matthew Treinish | 26dd0fa | 2012-12-04 17:14:37 -0500 | [diff] [blame] | 42 | if params: |
| 43 | url += '?%s' % urllib.urlencode(params) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 44 | |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 45 | resp, body = self.get(url) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 46 | body = json.loads(body) |
Daryl Walleck | 74d0409 | 2012-01-10 23:33:46 -0600 | [diff] [blame] | 47 | return resp, body['flavors'] |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 48 | |
| 49 | def get_flavor_details(self, flavor_id): |
chris fattarsi | 5098fa2 | 2012-04-17 13:27:00 -0700 | [diff] [blame] | 50 | resp, body = self.get("flavors/%s" % str(flavor_id)) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 51 | body = json.loads(body) |
| 52 | return resp, body['flavor'] |
Rohit Karajgi | 0353029 | 2012-04-24 17:00:50 -0700 | [diff] [blame] | 53 | |
| 54 | def create_flavor(self, name, ram, vcpus, disk, ephemeral, flavor_id, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 55 | swap, rxtx): |
Rohit Karajgi | 0353029 | 2012-04-24 17:00:50 -0700 | [diff] [blame] | 56 | """Creates a new flavor or instance type""" |
| 57 | post_body = { |
Zhongyue Luo | 30a563f | 2012-09-30 23:43:50 +0900 | [diff] [blame] | 58 | 'name': name, |
| 59 | 'ram': ram, |
| 60 | 'vcpus': vcpus, |
| 61 | 'disk': disk, |
| 62 | 'OS-FLV-EXT-DATA:ephemeral': ephemeral, |
| 63 | 'id': flavor_id, |
| 64 | 'swap': swap, |
| 65 | 'rxtx_factor': rxtx, |
| 66 | } |
Rohit Karajgi | 0353029 | 2012-04-24 17:00:50 -0700 | [diff] [blame] | 67 | |
| 68 | post_body = json.dumps({'flavor': post_body}) |
| 69 | resp, body = self.post('flavors', post_body, self.headers) |
| 70 | |
| 71 | body = json.loads(body) |
| 72 | return resp, body['flavor'] |
| 73 | |
| 74 | def delete_flavor(self, flavor_id): |
| 75 | """Deletes the given flavor""" |
| 76 | return self.delete("flavors/%s" % str(flavor_id)) |