Ilya Kharin | aa03d4e | 2017-04-18 17:25:53 +0400 | [diff] [blame] | 1 | import logging |
| 2 | |
| 3 | LOG = logging.getLogger(__name__) |
| 4 | |
| 5 | |
Ilya Kharin | 722ecd4 | 2017-04-26 17:06:41 +0400 | [diff] [blame] | 6 | def __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 Kharin | aa03d4e | 2017-04-18 17:25:53 +0400 | [diff] [blame] | 16 | def 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 Kharin | 9be4068 | 2017-05-02 16:43:51 +0400 | [diff] [blame^] | 39 | ret['changes'][name] = 'UPDATED' |
Ilya Kharin | aa03d4e | 2017-04-18 17:25:53 +0400 | [diff] [blame] | 40 | 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 Kharin | 9be4068 | 2017-05-02 16:43:51 +0400 | [diff] [blame^] | 45 | ret['changes'][name] = 'CREATED' |
Ilya Kharin | aa03d4e | 2017-04-18 17:25:53 +0400 | [diff] [blame] | 46 | ret['result'] = True |
| 47 | return ret |
| 48 | |
| 49 | |
| 50 | def 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 |