blob: 1c8d4f3cc321a1f029cea7add35c3d8bc6bcde2c [file] [log] [blame]
dwallecke62b9f02012-10-10 23:34:42 -05001# 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 Walleck1465d612011-11-02 02:22:15 -050018import json
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050019import urllib
Daryl Walleck1465d612011-11-02 02:22:15 -050020
Matthew Treinisha83a16e2012-12-07 13:44:02 -050021from tempest.common.rest_client import RestClient
22
Daryl Walleck1465d612011-11-02 02:22:15 -050023
Tiago Melloeda03b52012-08-22 23:47:29 -030024class FlavorsClientJSON(RestClient):
Daryl Walleck1465d612011-11-02 02:22:15 -050025
Daryl Walleck587385b2012-03-03 13:00:26 -060026 def __init__(self, config, username, password, auth_url, tenant_name=None):
Tiago Melloeda03b52012-08-22 23:47:29 -030027 super(FlavorsClientJSON, self).__init__(config, username, password,
28 auth_url, tenant_name)
chris fattarsi5098fa22012-04-17 13:27:00 -070029 self.service = self.config.compute.catalog_type
Daryl Walleck1465d612011-11-02 02:22:15 -050030
31 def list_flavors(self, params=None):
32 url = 'flavors'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050033 if params:
34 url += '?%s' % urllib.urlencode(params)
Daryl Walleck1465d612011-11-02 02:22:15 -050035
chris fattarsi5098fa22012-04-17 13:27:00 -070036 resp, body = self.get(url)
Daryl Walleck1465d612011-11-02 02:22:15 -050037 body = json.loads(body)
Daryl Walleck74d04092012-01-10 23:33:46 -060038 return resp, body['flavors']
Daryl Walleck1465d612011-11-02 02:22:15 -050039
40 def list_flavors_with_detail(self, params=None):
41 url = 'flavors/detail'
Matthew Treinish26dd0fa2012-12-04 17:14:37 -050042 if params:
43 url += '?%s' % urllib.urlencode(params)
Daryl Walleck1465d612011-11-02 02:22:15 -050044
chris fattarsi5098fa22012-04-17 13:27:00 -070045 resp, body = self.get(url)
Daryl Walleck1465d612011-11-02 02:22:15 -050046 body = json.loads(body)
Daryl Walleck74d04092012-01-10 23:33:46 -060047 return resp, body['flavors']
Daryl Walleck1465d612011-11-02 02:22:15 -050048
49 def get_flavor_details(self, flavor_id):
chris fattarsi5098fa22012-04-17 13:27:00 -070050 resp, body = self.get("flavors/%s" % str(flavor_id))
Daryl Walleck1465d612011-11-02 02:22:15 -050051 body = json.loads(body)
52 return resp, body['flavor']
Rohit Karajgi03530292012-04-24 17:00:50 -070053
54 def create_flavor(self, name, ram, vcpus, disk, ephemeral, flavor_id,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080055 swap, rxtx):
Rohit Karajgi03530292012-04-24 17:00:50 -070056 """Creates a new flavor or instance type"""
57 post_body = {
Zhongyue Luo30a563f2012-09-30 23:43:50 +090058 '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 Karajgi03530292012-04-24 17:00:50 -070067
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))