blob: 2e877a6b21e99b6bc7bbc98b524f81d4e6d6b43f [file] [log] [blame]
Ilya Kharinaa03d4e2017-04-18 17:25:53 +04001import logging
2
3LOG = logging.getLogger(__name__)
4
5
6def present(name, description=''):
7 ret = {
8 'name': name,
9 'changes': {},
10 'result': False,
11 'comment': '',
12 'pchanges': {},
13 }
14 if __opts__['test'] == True:
15 ret['comment'] = 'Nothing to change in the test mode.'
16 ret['result'] = None
17 return ret
18 params = {
19 "description": description,
20 }
21 project = __salt__['rundeck.get_project'](name)
22 if project:
23 config = __salt__['rundeck.create_project_config'](
24 name, params, config=project["config"])
25 if project["config"] != config:
26 LOG.warning("{}: {}".format(project["config"], config))
27 __salt__['rundeck.update_project_config'](name, project, config)
28 ret['comment'] = "Project {} was updated.".format(name)
29 ret['changes'][name] = "UPDATED"
30 else:
31 ret['comment'] = "Project {} is already up to date.".format(name)
32 else:
33 __salt__['rundeck.create_project'](name, params)
34 ret['comment'] = "Project {} was created.".format(name)
35 ret['changes'][name] = "CREATED"
36 ret['result'] = True
37 return ret
38
39
40def absent(name):
41 ret = {
42 'name': name,
43 'changes': {},
44 'result': False,
45 'comment': '',
46 'pchanges': {},
47 }
48 if __opts__['test'] == True:
49 ret['comment'] = 'Nothing to remove in the test mode.'
50 ret['result'] = None
51 return ret
52 project = __salt__['rundeck.get_project'](name)
53 if project:
54 __salt__['rundeck.delete_project'](name)
55 ret['changes'][name] = 'DELETED'
56 ret['comment'] = "Project {} was removed.".format(name)
57 ret['result'] = True
58 return ret