Vladyslav Drok | cb8d0fb | 2018-06-27 19:28:14 +0300 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | import common |
| 14 | |
| 15 | # Function alias to not shadow built-ins |
| 16 | __func_alias__ = { |
| 17 | 'list_': 'list' |
| 18 | } |
| 19 | |
| 20 | |
| 21 | @common.function_descriptor('update', 'Flavor extra specs', 'extra_specs') |
| 22 | @common.send('post') |
| 23 | def add_extra_specs(flavor_id, **kwargs): |
| 24 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 25 | url = '/flavors/{flavor_id}/os-extra_specs'.format(flavor_id=flavor_id) |
| 26 | return url, {'json': {"extra_specs": kwargs}} |
| 27 | |
| 28 | |
| 29 | @common.function_descriptor('create', 'Flavor', 'flavor') |
| 30 | @common.send('post') |
| 31 | def create(name, vcpus, ram, disk, **kwargs): |
| 32 | """Create flavor(s).""" |
| 33 | url = '/flavors' |
| 34 | req = {'flavor': {'name': name, 'vcpus': vcpus, 'ram': ram, 'disk': disk}} |
| 35 | req['flavor'].update(kwargs) |
| 36 | return url, {'json': req} |
| 37 | |
| 38 | |
| 39 | @common.function_descriptor('delete', 'Flavor') |
| 40 | @common.send('delete') |
| 41 | def delete(flavor_id, **kwargs): |
| 42 | """Delete flavor.""" |
| 43 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 44 | url = '/flavors/{flavor_id}'.format(flavor_id=flavor_id) |
| 45 | return url, {} |
| 46 | |
| 47 | |
| 48 | @common.function_descriptor('update', 'Flavor extra specs') |
| 49 | @common.send('delete') |
| 50 | def delete_extra_spec(flavor_id, key_name, **kwargs): |
| 51 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 52 | url = '/flavors/{flavor_id}/os-extra_specs/{key_name}'.format( |
| 53 | flavor_id=flavor_id, key_name=key_name) |
| 54 | return url, {} |
| 55 | |
| 56 | |
| 57 | @common.function_descriptor('find', 'Flavor', 'flavor') |
| 58 | @common.send('get') |
| 59 | def get(flavor_id, **kwargs): |
| 60 | """Return one flavor.""" |
| 61 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 62 | url = '/flavors/{flavor_id}'.format(flavor_id=flavor_id) |
| 63 | return url, {} |
| 64 | |
| 65 | |
| 66 | @common.function_descriptor('find', 'Flavor extra specs', 'extra_specs') |
| 67 | @common.send('get') |
| 68 | def get_extra_specs(flavor_id, **kwargs): |
| 69 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 70 | url = '/flavors/{flavor_id}/os-extra_specs'.format(flavor_id=flavor_id) |
| 71 | return url, {} |
| 72 | |
| 73 | |
| 74 | @common.function_descriptor('find', 'Flavor', 'flavors') |
| 75 | @common.send('get') |
| 76 | def list_(detail=False, **kwargs): |
| 77 | """Return list of flavors.""" |
| 78 | url = '/flavors' |
| 79 | if detail: |
| 80 | url = '%s/detail' % url |
| 81 | return url, {} |