blob: 6606c3ea9281f3b3716caea829fc4c539bf4085f [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 six.moves.urllib.parse as urllib_parse
14
15import common
16
17# Function alias to not shadow built-ins
18__func_alias__ = {
19 'list_': 'list'
20}
21
22
23@common.send('get')
24def list_(**kwargs):
25 """Return list of servers."""
26 url = '/servers?{}'.format(urllib_parse.urlencode(kwargs))
27 return url, {}
28
29
30@common.send('post')
31def create(name, flavor, **kwargs):
32 """Create server(s)."""
33 # TODO: add something useful :)
34 url = '/servers'
35 req = {'server': {'name': name, 'flavor': flavor}}
36 req['server'].update(kwargs)
37 return url, {'json': req}
38
39
40@common.get_by_name_or_uuid(list_, 'servers')
41@common.send('delete')
42def delete(server_id, **kwargs):
43 """Delete server."""
44 url = '/servers/{server_id}'.format(server_id=server_id)
45 return url, {}
46
47
48@common.get_by_name_or_uuid(list_, 'servers')
49@common.send('get')
50def get(server_id, **kwargs):
51 """Return one server."""
52 url = '/servers/{server_id}'.format(server_id=server_id)
53 return url, {}
54
55
56@common.get_by_name_or_uuid(list_, 'servers')
57@common.send('post')
58def lock(server_id, **kwargs):
59 """Lock server."""
60 url = '/servers/{server_id}/action'.format(server_id=server_id)
61 req = {"lock": None}
62 return url, {"json": req}
63
64
65@common.get_by_name_or_uuid(list_, 'servers')
66@common.send('post')
67def resume(server_id, **kwargs):
68 """Resume server after suspend."""
69 url = '/servers/{server_id}/action'.format(server_id=server_id)
70 req = {"resume": None}
71 return url, {"json": req}
72
73
74@common.get_by_name_or_uuid(list_, 'servers')
75@common.send('post')
76def suspend(server_id, **kwargs):
77 """Suspend server."""
78 url = '/servers/{server_id}/action'.format(server_id=server_id)
79 req = {"suspend": None}
80 return url, {"json": req}
81
82
83@common.get_by_name_or_uuid(list_, 'servers')
84@common.send('post')
85def unlock(server_id, **kwargs):
86 """Unlock server."""
87 url = '/servers/{server_id}/action'.format(server_id=server_id)
88 req = {"unlock": None}
89 return url, {"json": req}