cgi_bin_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
base_dir = os.path.dirname(cgi_bin_dir)
+ puppetlabs_cfg_dir = os.sep + os.path.join('etc', 'puppetlabs')
+ puppet_envs_dir = os.path.join(puppetlabs_cfg_dir, 'code', 'environments')
+ fileserver_dir = os.path.join(puppetlabs_cfg_dir, 'code', 'fileserver')
+
special_chars_re = re.compile(r'[^a-z0-9_\-]', re.IGNORECASE)
dev_re = re.compile(r'^dev')
"""The logfile for STDERR of this application."""
return os.path.join(self.log_directory, self.appname + '.error.log')
+ # -----------------------------------------------------------
+ @property
+ def env_dir(self):
+ """The directory containing the current r10k environment."""
+ cur_env = getattr(self, 'ref', None)
+ if cur_env is None:
+ return None
+ return os.path.join(self.puppet_envs_dir, cur_env)
+
# -------------------------------------------------------------------------
def __str__(self):
"""
res['log_directory'] = self.log_directory
res['error_logfile'] = self.error_logfile
res['logfile'] = self.logfile
+ res['puppetlabs_cfg_dir'] = self.puppetlabs_cfg_dir
+ res['puppet_envs_dir'] = self.puppet_envs_dir
+ res['env_dir'] = self.env_dir
+ res['fileserver_dir'] = self.fileserver_dir
return res
os.environ['REQUEST_METHOD'] = 'GET'
if self.cmdline_args.simulate:
+ sys.stderr.write("\nSimulation mode - nothing is really done.\n\n")
self.simulate = True
# -------------------------------------------------------------------------
v=config['verbose'], f=yaml_file, e=e)
LOG.warn(msg)
- if 'simulate' in config:
+ if 'simulate' in config and not self.simulate:
self.simulate = config['simulate']
if 'do_sudo' in config:
LOG.info("Executing webhook {a!r} for Git SSH URL {u!r}, branch {b!r}.".format(
a=self.appname, u=self.git_ssh_url, b=self.ref))
+ LOG.debug("Environment directory should be {!r}.".format(self.env_dir))
+
return True
# -------------------------------------------------------------------------
import pipes
import subprocess
import urllib.parse
+import time
# Third party modules
LOG.warn("Executing {!r} was not successful.".format(self.r10k_bin))
return
+ return self.del_env_cache()
+
+ # -------------------------------------------------------------------------
+ def del_env_cache(self):
+
+ if self.env_dir is None:
+ raise RuntimeError("No environment defined.")
+
+ LOG.debug("Searching for environment directory {!r} ...".format(self.env_dir))
+ if not os.path.isdir(self.env_dir):
+ LOG.info("Environment directory {!r} does not exists.".format(self.env_dir))
+ return
+
key_file = os.path.join(
self.puppetmaster_ssl_dir, 'private_keys', self.puppetmaster_host + '.pem')
cert_file = os.path.join(
LOG.info("Executing: {}".format(cmd_str))
if self.simulate:
- LOG.info("Simulation mode, don't executing {!r}.".format(self.r10k_bin))
+ LOG.warn("Simulation mode, don't executing {!r}.".format(self.r10k_bin))
+ time.sleep(3)
return res
+ LOG.debug("Really executing ...")
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdoutdata, stderrdata) = proc.communicate()
ret_val = proc.wait()