Debian Codegraph @

adjutantclient/v1/tasks.py

raw
1 # Copyright (C) 2016 Catalyst IT Ltd
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from urllib import parse
16
17 from adjutantclient.common import base
18
19
20 class Task(base.Resource):
21 pass
22
23
24 class TaskManager(base.ManagerWithFind):
25 resource_class = Task
26
27 def get(self, task_id):
28 return self._get("/tasks/%s" % base.getid(task_id))
29
30 def list(self, **kwargs):
31 """Get a list of tasks.
32
33 :rtype: list of :class:`Task`
34 """
35 url = '/tasks?%(params)s' % {
36 'params': parse.urlencode(kwargs, True)
37 }
38 return self._list(url, 'tasks')
39
40 def update(self, task_id, data):
41 """Update a task with new data and rerun pre-approve validation."""
42 url = 'tasks/%s' % task_id
43 return self._put(url, data)
44
45 def approve(self, task_id):
46 """Approve a task.
47
48 If already approved will rerun post-approve validation
49 and reissue/resend token.
50 """
51 data = {'approved': True}
52 url = 'tasks/%s' % task_id
53 return self._post(url, data)
54
55 def cancel(self, task_id):
56 """Cancel a task."""
57 url = 'tasks/%s' % task_id
58 return self._delete(url)