mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Fixes icinga2 module return code (#38987)
* Fixes icinga2 module return code * Remove unused os import
This commit is contained in:
parent
d5d39321c8
commit
86821ee70a
@ -10,6 +10,7 @@ Module to provide icinga2 compatibility to salt.
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils
|
||||
@ -30,6 +31,18 @@ def __virtual__():
|
||||
return (False, 'Icinga2 not installed.')
|
||||
|
||||
|
||||
def _execute(cmd, ret_code=False):
|
||||
process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
if ret_code:
|
||||
return process.wait()
|
||||
output, error = process.communicate()
|
||||
if output:
|
||||
log.debug(output)
|
||||
return output
|
||||
log.debug(error)
|
||||
return error
|
||||
|
||||
|
||||
def generate_ticket(domain):
|
||||
'''
|
||||
Generate and save an icinga2 ticket.
|
||||
@ -44,7 +57,7 @@ def generate_ticket(domain):
|
||||
salt '*' icinga2.generate_ticket domain.tld
|
||||
|
||||
'''
|
||||
result = __salt__['cmd.run']("icinga2 pki ticket --cn {0}".format(domain))
|
||||
result = _execute(["icinga2", "pki", "ticket", "--cn", domain])
|
||||
return result
|
||||
|
||||
|
||||
@ -62,7 +75,7 @@ def generate_cert(domain):
|
||||
salt '*' icinga2.generate_cert domain.tld
|
||||
|
||||
'''
|
||||
result = __salt__['cmd.run']("icinga2 pki new-cert --cn {0} --key /etc/icinga2/pki/{0}.key --cert /etc/icinga2/pki/{0}.crt".format(domain))
|
||||
result = _execute(["icinga2", "pki", "new-cert", "--cn", domain, "--key", "/etc/icinga2/pki/{0}.key".format(domain), "--cert", "/etc/icinga2/pki/{0}.crt".format(domain)], ret_code=True)
|
||||
return result
|
||||
|
||||
|
||||
@ -80,8 +93,8 @@ def save_cert(domain, master):
|
||||
salt '*' icinga2.save_cert domain.tld master.domain.tld
|
||||
|
||||
'''
|
||||
result = __salt__['cmd.run']("icinga2 pki save-cert --key /etc/icinga2/pki/{0}.key --cert /etc/icinga2/pki/{0}.cert --trustedcert /etc/icinga2/pki/trusted-master.crt \
|
||||
--host {1}".format(domain, master))
|
||||
result = _execute(["icinga2", "pki", "save-cert", "--key", "/etc/icinga2/pki/{0}.key".format(domain), "--cert", "/etc/icinga2/pki/{0}.cert".format(domain), "--trustedcert",
|
||||
"/etc/icinga2/pki/trusted-master.crt", "--host", master], ret_code=True)
|
||||
return result
|
||||
|
||||
|
||||
@ -100,8 +113,8 @@ def request_cert(domain, master, ticket, port):
|
||||
salt '*' icinga2.request_cert domain.tld master.domain.tld TICKET_ID
|
||||
|
||||
'''
|
||||
result = __salt__['cmd.run']("icinga2 pki request --host {0} --port {1} --ticket {2} --key /etc/icinga2/pki/{3}.key --cert \
|
||||
/etc/icinga2/pki/{3}.crt --trustedcert /etc/icinga2/pki/trusted-master.crt --ca /etc/icinga2/pki/ca.crt".format(master, port, ticket, domain))
|
||||
result = _execute(["icinga2", "pki", "request", "--host", master, "--port", port, "--ticket", ticket, "--key", "/etc/icinga2/pki/{0}.key".format(domain), "--cert",
|
||||
"/etc/icinga2/pki/{0}.crt".format(domain), "--trustedcert", "/etc/icinga2/pki/trusted-master.crt", "--ca", "/etc/icinga2/pki/ca.crt"], ret_code=True)
|
||||
return result
|
||||
|
||||
|
||||
@ -120,5 +133,6 @@ def node_setup(domain, master, ticket):
|
||||
salt '*' icinga2.node_setup domain.tld master.domain.tld TICKET_ID
|
||||
|
||||
'''
|
||||
result = __salt__['cmd.run']("icinga2 node setup --ticket {0} --endpoint {1} --zone {2} --master_host {1} --trustedcert /etc/icinga2/pki/trusted-master.crt".format(ticket, master, domain))
|
||||
result = _execute(["icinga2", "node", "setup", "--ticket", ticket, "--endpoint", master, "--zone", domain, "--master_host", master, "--trustedcert", "/etc/icinga2/pki/trusted-master.crt"],
|
||||
ret_code=True)
|
||||
return result
|
||||
|
Loading…
Reference in New Issue
Block a user