blob: 7cf62fa990e9a1436e1ff7006050de04b3aa0792 [file] [log] [blame]
Vladyslav Drokcb8d0fb2018-06-27 19:28:14 +03001# 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 Stremkouskid37f2c82020-09-11 13:13:58 +020013import six.moves.urllib.parse as urllib_parse
14
Vladyslav Drokcb8d0fb2018-06-27 19:28:14 +030015import 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')
25def 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')
33def 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')
43def 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')
52def 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')
61def 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')
70def 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')
78def list_(detail=False, **kwargs):
79 """Return list of flavors."""
80 url = '/flavors'
81 if detail:
82 url = '%s/detail' % url
Dzmitry Stremkouskid37f2c82020-09-11 13:13:58 +020083 url = '%(base_url)s?%(query_args)s' % {
84 "base_url": url, "query_args": urllib_parse.urlencode(kwargs)}
Vladyslav Drokcb8d0fb2018-06-27 19:28:14 +030085 return url, {}