blob: 9f61f2d32085acded675b8548888c58bcf012077 [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
13import common
14
15# Function alias to not shadow built-ins
16__func_alias__ = {
17 'list_': 'list'
18}
19
20
21@common.function_descriptor('find', 'Host aggregate', 'aggregates')
22@common.send('get')
23def list_(**kwargs):
24 """List host aggregates"""
25 url = '/os-aggregates'
26 return url, {}
27
28
29@common.function_descriptor('update', 'Host aggregate', 'aggregate')
30@common.get_by_name_or_uuid(list_, 'aggregates')
31@common.send('post')
32def add_host(aggregate_id, host, **kwargs):
33 """Add host to a host aggregate"""
34 url = '/os-aggregates/%s/action' % aggregate_id
35 return url, {'json': {'add_host': {'host': host}}}
36
37
38@common.function_descriptor('create', 'Host aggregate', 'aggregate')
39@common.send('post')
40def create(name, availability_zone, **kwargs):
41 """Create a host aggregate"""
42 url = '/os-aggregates'
43 req = {'name': name, 'availability_zone': availability_zone}
44 return url, {'json': {'aggregate': req}}
45
46
47@common.function_descriptor('delete', 'Host aggregate')
48@common.get_by_name_or_uuid(list_, 'aggregates')
49@common.send('delete')
50def delete(aggregate_id, **kwargs):
51 """Delete a host aggregate"""
52 url = '/os-aggregates/%s' % aggregate_id
53 return url, {}
54
55
56@common.function_descriptor('find', 'Host aggregate', 'aggregate')
57@common.get_by_name_or_uuid(list_, 'aggregates')
58@common.send('get')
59def get(aggregate_id, **kwargs):
60 """Get a host aggregate"""
61 url = '/os-aggregates/%s' % aggregate_id
62 return url, {}
63
64
65@common.function_descriptor('update', 'Host aggregate', 'aggregate')
66@common.get_by_name_or_uuid(list_, 'aggregates')
67@common.send('post')
68def remove_host(aggregate_id, host, **kwargs):
69 """Remove host from a host aggregate"""
70 url = '/os-aggregates/%s/action' % aggregate_id
71 return url, {'json': {'remove_host': {'host': host}}}
72
73
74@common.function_descriptor('update', 'Host aggregate', 'aggregate')
75@common.get_by_name_or_uuid(list_, 'aggregates')
76@common.send('post')
77def set_metadata(aggregate_id, **kwargs):
78 """Set host aggregate metadata"""
79 url = '/os-aggregates/%s/action' % aggregate_id
80 return url, {'json': {'set_metadata': {'metadata': kwargs}}}