Sergey Otpuschennikov | 8399670 | 2017-11-23 17:10:57 +0400 | [diff] [blame^] | 1 | import logging |
| 2 | |
| 3 | logger = logging.getLogger(__name__) |
| 4 | |
| 5 | def __virtual__(): |
| 6 | ''' |
| 7 | Only load if jenkins_common module exist. |
| 8 | ''' |
| 9 | if 'jenkins_common.call_groovy_script' not in __salt__: |
| 10 | return ( |
| 11 | False, |
| 12 | 'The jenkins_gerrit state module cannot be loaded: ' |
| 13 | 'jenkins_common not found') |
| 14 | return True |
| 15 | |
| 16 | |
| 17 | def present(name, hostname, username, frontendurl, auth_key_file, authkey, |
| 18 | port="29418", auth_key_file_password=None, email="", proxy=""): |
| 19 | """ |
| 20 | Jenkins gerrit-trigger state method |
| 21 | |
| 22 | :param name: server name |
| 23 | :param host: server hostname |
| 24 | :param username: username |
| 25 | :param email: trigger email (optional) |
| 26 | :param port: server ssh port |
| 27 | :param proxy: proxy url (optional) |
| 28 | :param frontendurl: server frontend URL |
| 29 | :param auth_key_file: path to key file |
| 30 | :param authkey: ssh key |
| 31 | :param auth_key_file_password: password for keyfile (optional) |
| 32 | :returns: salt-specified state dict |
| 33 | """ |
| 34 | template = __salt__['jenkins_common.load_template']( |
| 35 | 'salt://jenkins/files/groovy/gerrit.template', |
| 36 | __env__) |
| 37 | return __salt__['jenkins_common.api_call'](name, template, |
| 38 | ["CREATED", "EXISTS"], |
| 39 | { |
| 40 | "name": name, |
| 41 | "hostname": hostname, |
| 42 | "port": port if port else "29418", |
| 43 | "proxy": proxy if proxy else "", |
| 44 | "username": username, |
| 45 | "email": email if email else "", |
| 46 | "frontendurl": frontendurl, |
| 47 | "auth_key_file": auth_key_file, |
| 48 | "authkey": authkey, |
| 49 | "auth_key_file_password": auth_key_file_password if auth_key_file_password else None |
| 50 | }, |
| 51 | "Gerrit server") |