chnyda | 124ca04 | 2017-08-03 16:40:51 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
chnyda | d6f7635 | 2017-08-07 12:49:34 +0200 | [diff] [blame] | 3 | try: |
| 4 | import jenkins |
| 5 | HAS_JENKINS = True |
| 6 | except ImportError: |
| 7 | HAS_JENKINS = False |
chnyda | 124ca04 | 2017-08-03 16:40:51 +0200 | [diff] [blame] | 8 | import salt.config |
| 9 | |
| 10 | def main(): |
chnyda | d6f7635 | 2017-08-07 12:49:34 +0200 | [diff] [blame] | 11 | if not HAS_JENKINS: |
| 12 | return {} |
| 13 | |
chnyda | 124ca04 | 2017-08-03 16:40:51 +0200 | [diff] [blame] | 14 | output = { "jenkins_plugins" : {} } |
| 15 | opts = salt.config.minion_config('/etc/salt/minion') |
chnyda | ea19043 | 2017-08-08 15:37:29 +0200 | [diff] [blame] | 16 | try: |
| 17 | url = opts['jenkins']['url'] |
| 18 | except KeyError: |
| 19 | return {} |
| 20 | |
| 21 | try: |
| 22 | user = opts['jenkins']['user'] |
| 23 | password = opts['jenkins']['password'] |
| 24 | except KeyError: |
| 25 | user = None |
| 26 | password = None |
chnyda | 124ca04 | 2017-08-03 16:40:51 +0200 | [diff] [blame] | 27 | |
Dennis Dmitriev | 9be80b0 | 2018-02-13 12:01:29 +0200 | [diff] [blame^] | 28 | try: |
| 29 | server = jenkins.Jenkins(url, username=user, password=password) |
| 30 | plugins = server.get_plugins(depth=1) |
| 31 | except jenkins.JenkinsException: |
| 32 | return {} |
| 33 | |
chnyda | 124ca04 | 2017-08-03 16:40:51 +0200 | [diff] [blame] | 34 | for plugin_name, plugin_dict in plugins.iteritems(): |
chnyda | 9c05a3d | 2017-08-07 22:37:25 +0200 | [diff] [blame] | 35 | output["jenkins_plugins"][plugin_name[0]] = {"version" : (plugin_dict["version"] or 0)} |
chnyda | 124ca04 | 2017-08-03 16:40:51 +0200 | [diff] [blame] | 36 | return output |