import datetime
import locale
import ssl
+import pipes
+import subprocess
from http.client import HTTPSConnection
locale.setlocale(locale.LC_ALL, self.locale)
os.environ['LANG'] = self.locale
+ return True
+
# -------------------------------------------------------------------------
def run(self):
"""Main routine."""
LOG.info("Starting {} ...".format(self.appname))
+ if not self.exec_r10k():
+ return
+
ssl_context = ssl.SSLContext()
ssl_context.verify_mode = ssl.CERT_NONE
+ # -------------------------------------------------------------------------
+ def exec_r10k(self):
+
+ res = True
+
+ r10k_loglevel = 'info'
+ if self.verbose:
+ if self.verbose > 2:
+ r10k_loglevel = 'debug2'
+ elif self.verbose > 1:
+ r10k_loglevel = 'debug1'
+ else:
+ r10k_loglevel = 'debug'
+
+ cmd = []
+ if self.do_sudo:
+ cmd = ['sudo', '-n']
+
+ cmd += [
+ self.r10k_bin, 'deploy', 'environment',
+ self.ref, '--puppetfile', '--verbose', r10k_loglevel
+ ]
+ cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd))
+ if self.verbose > 2:
+ LOG.debug("Cmd: {}".format(pp(cmd)))
+ LOG.debug("Executing: {}".format(cmd_str))
+
+ if self.simulate:
+ LOG.info("Simulation mode, don't executing {!r}.".format(self.r10k_bin))
+ return res
+
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (stdoutdata, stderrdata) = proc.communicate()
+ ret_val = proc.wait()
+
+ LOG.debug("Return value: {}".format(ret_val))
+ if stdoutdata:
+ msg = "Output:\n{}".format(to_str(stdoutdata))
+ LOG.debug(msg)
+ self.print_out(msg)
+ else:
+ LOG.debug("No output.")
+ if stderrdata:
+ msg = "Error messages on '{c}':\n{e}".format(c=cmd_str, e=to_str(stderrdata))
+ if ret_val:
+ LOG.warn(msg)
+ self.error_data.append(msg)
+ res = False
+ else:
+ LOG.debug(msg)
+ self.print_out(msg)
+
+ return res
# =============================================================================