def _callK8s(self, path): cmd = [self.kubectl, "create", "-f", path, "--namespace=%s" % self.namespace] if self.dryrun: logger.info("DRY-RUN: %s", " ".join(cmd)) else: try: p = Popen(cmd, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() logger.debug("stdout = %s", stdout) logger.debug("stderr = %s", stderr) if stderr and stderr.strip() != "": raise Exception(str(stderr)) except Exception: printErrorStatus("cmd failed: " + " ".join(cmd)) raise
def _callK8s(self, path): cmd = [ self.kubectl, "create", "-f", path, "--namespace=%s" % self.namespace ] if self.dryrun: logger.info("DRY-RUN: %s", " ".join(cmd)) else: try: p = Popen(cmd, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() logger.debug("stdout = %s", stdout) logger.debug("stderr = %s", stderr) if stderr and stderr.strip() != "": raise Exception(str(stderr)) except Exception: printErrorStatus("cmd failed: " + " ".join(cmd)) raise
def process_k8s_artifacts(self): """Processes Kubernetes manifests files and checks if manifest under process is valid. """ for artifact in self.artifacts: data = None with open(os.path.join(self.path, artifact), "r") as fp: logger.debug(os.path.join(self.path, artifact)) try: data = anymarkup.parse(fp) except Exception: msg = "Error processing %s artifcats, Error:" % os.path.join( self.path, artifact) printErrorStatus(msg) raise if "kind" in data: self.k8s_manifests.append((data["kind"].lower(), artifact)) else: apath = os.path.join(self.path, artifact) raise ProviderFailedException("Malformed kube file: %s" % apath)
def _process_artifacts(self): """ Parse and validate Marathon artifacts Parsed artifacts are saved to self.marathon_artifacts """ for artifact in self.artifacts: logger.debug("Procesesing artifact: %s", artifact) data = None with open(os.path.join(self.path, artifact), "r") as fp: try: data = anymarkup.parse(fp) logger.debug("Parsed artifact %s", data) # every marathon app has to have id. 'id' key is also used for showing messages if "id" not in data.keys(): msg = "Error processing %s artifact. There is no id" % artifact printErrorStatus(msg) raise ProviderFailedException(msg) except anymarkup.AnyMarkupError, e: msg = "Error processing artifact - %s" % e printErrorStatus(msg) raise ProviderFailedException(msg) self.marathon_artifacts.append(data)
def _call_k8s(self, path): """Creates resource in manifest at given path by calling k8s CLI :arg path: Absolute path to Kubernetes resource manifest :raises: Exception """ cmd = [self.kubectl, "create", "-f", path, "--namespace=%s" % self.namespace] if self.dryrun: logger.info("DRY-RUN: %s", " ".join(cmd)) else: try: p = Popen(cmd, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() logger.debug("stdout = %s", stdout) logger.debug("stderr = %s", stderr) if stderr and stderr.strip() != "": raise Exception(str(stderr)) except Exception: printErrorStatus("cmd failed: " + " ".join(cmd)) raise
def _call(self, cmd): """Calls given command :arg cmd: Command to be called in a form of list :raises: Exception """ if self.dryrun: logger.info("DRY-RUN: %s", " ".join(cmd)) else: try: p = Popen(cmd, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() logger.debug("stdout = %s", stdout) logger.debug("stderr = %s", stderr) if stderr and stderr.strip() != "": raise Exception(str(stderr)) return stdout except Exception: printErrorStatus("cmd failed: " + " ".join(cmd)) raise