|
| 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