Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 1 | from types import StringTypes |
Tony Mack | aae0bf0 | 2013-04-09 09:43:50 -0400 | [diff] [blame] | 2 | from plstackapi.openstack.client import OpenStackClient |
| 3 | from plstackapi.openstack.driver import OpenStackDriver |
Tony Mack | f1c1224 | 2013-04-09 16:08:43 -0400 | [diff] [blame] | 4 | from plstackapi.core.api.auth import auth_check |
| 5 | from plstackapi.core.models import Flavor |
Tony Mack | aae0bf0 | 2013-04-09 09:43:50 -0400 | [diff] [blame] | 6 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 7 | def _get_flavors(filter): |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 8 | if isinstance(filter, StringTypes) and filter.isdigit(): |
| 9 | filter = int(filter) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 10 | if isinstance(filter, int): |
| 11 | flavors = Flavor.objects.filter(id=filter) |
| 12 | elif isinstance(filter, StringTypes): |
| 13 | flavors = Flavor.objects.filter(name=filter) |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 14 | elif isinstance(filter, dict): |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 15 | flavors = Flavor.objects.filter(**filter) |
| 16 | else: |
| 17 | flavors = [] |
| 18 | return flavors |
Tony Mack | aae0bf0 | 2013-04-09 09:43:50 -0400 | [diff] [blame] | 19 | |
| 20 | def add_flavor(auth, fields={}): |
| 21 | """not implemented""" |
| 22 | return |
| 23 | |
| 24 | def delete_flavor(auth, filter={}): |
| 25 | """not implemented""" |
| 26 | return 1 |
| 27 | |
| 28 | def get_flavors(auth, filter={}): |
| 29 | auth_check(auth) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 30 | flavors = _get_flavors(filter) |
Tony Mack | aae0bf0 | 2013-04-09 09:43:50 -0400 | [diff] [blame] | 31 | return flavors |
| 32 | |
| 33 | |
| 34 | |