Skip to content

Commit 3ec9bc3

Browse files
author
Ed Cranford
committed
Adding Flavors to the client
1 parent 4487402 commit 3ec9bc3

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

reddwarfclient/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self, username, api_key, tenant=None, auth_url=None,
102102
service_url=service_url)
103103
self.versions = Versions(self)
104104
self.databases = Databases(self)
105+
self.flavors = Flavors(self)
105106
self.instances = Instances(self)
106107
self.users = Users(self)
107108
self.root = Root(self)
@@ -116,6 +117,7 @@ def __init__(self, username, api_key, tenant=None, auth_url=None,
116117
from reddwarfclient.accounts import Accounts
117118
from reddwarfclient.config import Configs
118119
from reddwarfclient.databases import Databases
120+
from reddwarfclient.flavors import Flavors
119121
from reddwarfclient.instances import Instances
120122
from reddwarfclient.hosts import Hosts
121123
from reddwarfclient.management import Management

reddwarfclient/flavors.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright (c) 2012 OpenStack, LLC.
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+
16+
17+
from novaclient import base
18+
19+
import exceptions
20+
21+
from reddwarfclient.common import check_for_exceptions
22+
23+
class Flavor(base.Resource):
24+
"""
25+
A Flavor is an Instance type, specifying among other things, RAM size.
26+
"""
27+
def __repr__(self):
28+
return "<Flavor: %s>" % self.name
29+
30+
31+
class Flavors(base.ManagerWithFind):
32+
"""
33+
Manage :class:`Flavor` resources.
34+
"""
35+
resource_class = Flavor
36+
37+
def __repr__(self):
38+
return "<Flavors Manager at %s>" % id(self)
39+
40+
def _list(self, url, response_key):
41+
resp, body = self.api.client.get(url)
42+
if not body:
43+
raise Exception("Call to " + url + " did not return a body.")
44+
return [self.resource_class(self, res) for res in body[response_key]]
45+
46+
def list(self):
47+
"""
48+
Get a list of all flavors.
49+
50+
:rtype: list of :class:`Flavor`.
51+
"""
52+
return self.detail()
53+
54+
def index(self):
55+
"""
56+
Get a list of all flavors.
57+
58+
:rtype: list of :class:`Flavor`.
59+
"""
60+
return self._list("/flavors", "flavors")
61+
62+
def detail(self):
63+
"""
64+
Get the details of all flavors.
65+
66+
:rtype: list of :class:`Flavor`.
67+
"""
68+
#return self._get("/flavors/detail", "flavors")
69+
return self._list("/flavors/detail", "flavors")
70+
71+
def get(self, flavor):
72+
"""
73+
Get a specific flavor.
74+
75+
:rtype: :class:`Flavor`
76+
"""
77+
return self._get("/flavors/%s" % base.getid(flavor),
78+
"flavor")
79+

0 commit comments

Comments
 (0)