blob: 29dc76aaa75889e70106247e2f97a1267dc68f06 [file] [log] [blame]
Ilya Kharinaa03d4e2017-04-18 17:25:53 +04001import logging
2
3LOG = logging.getLogger(__name__)
4
5
Ilya Kharin722ecd42017-04-26 17:06:41 +04006def __virtual__():
7 if 'rundeck.get_project' not in __salt__:
8 return (
9 False,
10 'The rundeck_project state module cannot be loaded: rundeck is '
11 'unavailable',
12 )
13 return True
14
15
Ilya Kharinaa03d4e2017-04-18 17:25:53 +040016def present(name, description=''):
17 ret = {
18 'name': name,
19 'changes': {},
20 'result': False,
21 'comment': '',
22 'pchanges': {},
23 }
24 if __opts__['test'] == True:
25 ret['comment'] = 'Nothing to change in the test mode.'
26 ret['result'] = None
27 return ret
28 params = {
29 "description": description,
30 }
31 project = __salt__['rundeck.get_project'](name)
32 if project:
33 config = __salt__['rundeck.create_project_config'](
34 name, params, config=project["config"])
35 if project["config"] != config:
36 LOG.warning("{}: {}".format(project["config"], config))
37 __salt__['rundeck.update_project_config'](name, project, config)
38 ret['comment'] = "Project {} was updated.".format(name)
Ilya Kharin9be40682017-05-02 16:43:51 +040039 ret['changes'][name] = 'UPDATED'
Ilya Kharinaa03d4e2017-04-18 17:25:53 +040040 else:
41 ret['comment'] = "Project {} is already up to date.".format(name)
42 else:
43 __salt__['rundeck.create_project'](name, params)
44 ret['comment'] = "Project {} was created.".format(name)
Ilya Kharin9be40682017-05-02 16:43:51 +040045 ret['changes'][name] = 'CREATED'
Ilya Kharinaa03d4e2017-04-18 17:25:53 +040046 ret['result'] = True
47 return ret
48
49
50def absent(name):
51 ret = {
52 'name': name,
53 'changes': {},
54 'result': False,
55 'comment': '',
56 'pchanges': {},
57 }
58 if __opts__['test'] == True:
59 ret['comment'] = 'Nothing to remove in the test mode.'
60 ret['result'] = None
61 return ret
62 project = __salt__['rundeck.get_project'](name)
63 if project:
64 __salt__['rundeck.delete_project'](name)
65 ret['changes'][name] = 'DELETED'
66 ret['comment'] = "Project {} was removed.".format(name)
67 ret['result'] = True
68 return ret