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 | |
Dzmitry Stremkouski | d37f2c8 | 2020-09-11 13:13:58 +0200 | [diff] [blame^] | 13 | import six.moves.urllib.parse as urllib_parse |
| 14 | |
Vladyslav Drok | cb8d0fb | 2018-06-27 19:28:14 +0300 | [diff] [blame] | 15 | import common |
| 16 | |
| 17 | # Function alias to not shadow built-ins |
| 18 | __func_alias__ = { |
| 19 | 'list_': 'list' |
| 20 | } |
| 21 | |
| 22 | |
| 23 | @common.function_descriptor('update', 'Flavor extra specs', 'extra_specs') |
| 24 | @common.send('post') |
| 25 | def add_extra_specs(flavor_id, **kwargs): |
| 26 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 27 | url = '/flavors/{flavor_id}/os-extra_specs'.format(flavor_id=flavor_id) |
| 28 | return url, {'json': {"extra_specs": kwargs}} |
| 29 | |
| 30 | |
| 31 | @common.function_descriptor('create', 'Flavor', 'flavor') |
| 32 | @common.send('post') |
| 33 | def create(name, vcpus, ram, disk, **kwargs): |
| 34 | """Create flavor(s).""" |
| 35 | url = '/flavors' |
| 36 | req = {'flavor': {'name': name, 'vcpus': vcpus, 'ram': ram, 'disk': disk}} |
| 37 | req['flavor'].update(kwargs) |
| 38 | return url, {'json': req} |
| 39 | |
| 40 | |
| 41 | @common.function_descriptor('delete', 'Flavor') |
| 42 | @common.send('delete') |
| 43 | def delete(flavor_id, **kwargs): |
| 44 | """Delete flavor.""" |
| 45 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 46 | url = '/flavors/{flavor_id}'.format(flavor_id=flavor_id) |
| 47 | return url, {} |
| 48 | |
| 49 | |
| 50 | @common.function_descriptor('update', 'Flavor extra specs') |
| 51 | @common.send('delete') |
| 52 | def delete_extra_spec(flavor_id, key_name, **kwargs): |
| 53 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 54 | url = '/flavors/{flavor_id}/os-extra_specs/{key_name}'.format( |
| 55 | flavor_id=flavor_id, key_name=key_name) |
| 56 | return url, {} |
| 57 | |
| 58 | |
| 59 | @common.function_descriptor('find', 'Flavor', 'flavor') |
| 60 | @common.send('get') |
| 61 | def get(flavor_id, **kwargs): |
| 62 | """Return one flavor.""" |
| 63 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 64 | url = '/flavors/{flavor_id}'.format(flavor_id=flavor_id) |
| 65 | return url, {} |
| 66 | |
| 67 | |
| 68 | @common.function_descriptor('find', 'Flavor extra specs', 'extra_specs') |
| 69 | @common.send('get') |
| 70 | def get_extra_specs(flavor_id, **kwargs): |
| 71 | # NOTE: flavor_id can be any string, don't convert flavor name to uuid |
| 72 | url = '/flavors/{flavor_id}/os-extra_specs'.format(flavor_id=flavor_id) |
| 73 | return url, {} |
| 74 | |
| 75 | |
| 76 | @common.function_descriptor('find', 'Flavor', 'flavors') |
| 77 | @common.send('get') |
| 78 | def list_(detail=False, **kwargs): |
| 79 | """Return list of flavors.""" |
| 80 | url = '/flavors' |
| 81 | if detail: |
| 82 | url = '%s/detail' % url |
Dzmitry Stremkouski | d37f2c8 | 2020-09-11 13:13:58 +0200 | [diff] [blame^] | 83 | url = '%(base_url)s?%(query_args)s' % { |
| 84 | "base_url": url, "query_args": urllib_parse.urlencode(kwargs)} |
Vladyslav Drok | cb8d0fb | 2018-06-27 19:28:14 +0300 | [diff] [blame] | 85 | return url, {} |