Ejemplo n.º 1
0
    def checkArtifacts(self, component, check_provider=None):
        checked_providers = []
        artifacts = self.getArtifacts(component)
        if not artifacts:
            logger.debug("No artifacts for %s", component)
            return []

        for provider, artifact_list in artifacts.iteritems():
            if (check_provider and not provider == check_provider) \
                    or provider in checked_providers:
                continue

            logger.debug("Provider: %s", provider)
            for artifact in artifact_list:
                if "inherit" in artifact:
                    self._checkInherit(component, artifact["inherit"], checked_providers)
                    continue
                path = os.path.join(self.target_path, Utils.sanitizePath(artifact))
                if os.path.isfile(path):
                    printStatus("Artifact %s: OK." % (artifact))
                else:
                    printErrorStatus("Missing artifact %s." % (artifact))
                    raise Exception("Missing artifact %s (%s)" % (artifact, path))
            checked_providers.append(provider)

        return checked_providers
Ejemplo n.º 2
0
    def checkArtifacts(self, component, check_provider=None):
        checked_providers = []
        artifacts = self.getArtifacts(component)
        if not artifacts:
            logger.debug("No artifacts for %s", component)
            return []

        for provider, artifact_list in artifacts.iteritems():
            if (check_provider and not provider == check_provider) \
                    or provider in checked_providers:
                continue

            logger.debug("Provider: %s", provider)
            for artifact in artifact_list:
                if "inherit" in artifact:
                    self._checkInherit(component, artifact["inherit"],
                                       checked_providers)
                    continue
                path = os.path.join(self.target_path,
                                    Utils.sanitizePath(artifact))
                if os.path.isfile(path):
                    printStatus("Artifact %s: OK." % (artifact))
                else:
                    printErrorStatus("Missing artifact %s." % (artifact))
                    raise Exception("Missing artifact %s (%s)" %
                                    (artifact, path))
            checked_providers.append(provider)

        return checked_providers
Ejemplo n.º 3
0
    def _processComponent(self, component, graph_item):
        logger.debug(
            "Processing component '%s' and graph item '%s'", component, graph_item)
        provider_class = self.plugin.getProvider(self.nulecule_base.provider)
        dst_dir = os.path.join(self.utils.workdir, component)
        if self.stop:
            component_values = self.nulecule_base.getValues(component, skip_asking=True)
        else:
            component_values = self.nulecule_base.getValues(component)
        provider = provider_class(component_values, dst_dir, self.dryrun)
        if provider:
            printStatus("Deploying component %s ..." % component)
            logger.info("Using provider %s for component %s",
                        self.nulecule_base.provider, component)
        else:
            raise Exception("Something is broken - couldn't get the provider")

        provider.artifacts, dst_dir = self._processArtifacts(component, provider)

        try:
            provider.init()
            if self.stop:
                provider.undeploy()
            else:
                provider.deploy()
        except ProviderFailedException as ex:
            printErrorStatus(ex)
            logger.error(ex)
            raise
Ejemplo n.º 4
0
    def _applyTemplate(self, data, component):
        template = Template(data)
        if self.stop:
            config = self.nulecule_base.getValues(component, skip_asking=True)
        else:
            config = self.nulecule_base.getValues(component)
        logger.debug("Config: %s ", config)

        output = None
        while not output:
            try:
                logger.debug(config)
                output = template.substitute(config)
            except KeyError as ex:
                name = ex.args[0]
                logger.debug(
                    "Artifact contains unknown parameter %s, asking for it", name)
                try:
                    config[name] = self.utils.askFor(
                        name,
                        {"description":
                         "Missing parameter '%s', provide the value or fix your %s" % (
                             name, MAIN_FILE)})
                except EOFError:
                    raise Exception("Artifact contains unknown parameter %s" % name)
                if not len(config[name]):
                    printErrorStatus("Artifact contains unknown parameter %s." % name)
                    raise Exception("Artifact contains unknown parameter %s" % name)
                self.nulecule_base.loadAnswers({component: {name: config[name]}})

        return output
Ejemplo n.º 5
0
    def _getValue(self, param, name, skip_asking = False):
        value = None

        if type(param) == dict:
            if "default" in param:
                value = param["default"]
            if not skip_asking and (self.ask or not value) and "description" in param: #FIXME
                printErrorStatus("%s is missing in answers.conf ." % (name))
                logger.debug("Ask for %s: %s", name, param["description"])
                value = Utils.askFor(name, param)
            elif not skip_asking and not value:
                logger.debug("Skipping %s", name)
                value = param
        else:
            value = param

        return value
Ejemplo n.º 6
0
    def _getValue(self, param, name, skip_asking=False):
        value = None

        if type(param) == dict:
            if "default" in param:
                value = param["default"]
            if not skip_asking and (self.ask or not value) and \
                    "description" in param:  # FIXME
                printErrorStatus("%s is missing in answers.conf ." % (name))
                logger.debug("Ask for %s: %s", name, param["description"])
                value = Utils.askFor(name, param)
            elif not skip_asking and not value:
                logger.debug("Skipping %s", name)
                value = param
        else:
            value = param

        return value
Ejemplo n.º 7
0
    def _dispatchGraph(self):
        if not "graph" in self.nulecule_base.mainfile_data:
            printErrorStatus("Graph not specified in %s." % MAIN_FILE)
            raise Exception("Graph not specified in %s" % MAIN_FILE)

        for graph_item in self.nulecule_base.mainfile_data["graph"]:
            component = graph_item.get("name")
            if not component:
                printErrorStatus("Component name missing in graph.")
                raise ValueError("Component name missing in graph")

            if self.utils.isExternal(graph_item):
                self.kwargs["image"] = self.utils.getSourceImage(graph_item)
                component_run = Run(self.answers_file, self.utils.getExternalAppDir(component), self.dryrun, self.debug, self.stop, **self.kwargs)
                ret = component_run.run()
                if self.answers_output:
                    self.nulecule_base.loadAnswers(ret)
            else:
                self._processComponent(component, graph_item)
Ejemplo n.º 8
0
    def pullApp(self, image = None, update = None):
        if not image:
            image = self.app
        if not update:
            update = self.update

        image = self.getImageURI(image)
        if not update:
            check_cmd = ["docker", "images", "-q", image]
            image_id = subprocess.check_output(check_cmd)
            logger.debug("Output of docker images cmd: %s", image_id)
            if len(image_id) != 0:
                logger.debug("Image %s already present with id %s. Use --update to re-pull.", image, image_id.strip())
                return

        pull = ["docker", "pull", image]
        printStatus("Pulling image %s ..." % image)
        if subprocess.call(pull) != 0:
            printErrorStatus("Couldn't pull %s." % image)
            raise Exception("Couldn't pull %s" % image)
Ejemplo n.º 9
0
    def _dispatchGraph(self):
        if "graph" not in self.nulecule_base.mainfile_data:
            printErrorStatus("Graph not specified in %s." % MAIN_FILE)
            raise Exception("Graph not specified in %s" % MAIN_FILE)

        for graph_item in self.nulecule_base.mainfile_data["graph"]:
            component = graph_item.get("name")
            if not component:
                printErrorStatus("Component name missing in graph.")
                raise ValueError("Component name missing in graph")

            if self.utils.isExternal(graph_item):
                self.kwargs["image"] = self.utils.getSourceImage(graph_item)
                component_run = Run(self.answers_file, self.utils.getExternalAppDir(
                    component), self.dryrun, self.debug, self.stop, **self.kwargs)
                ret = component_run.run()
                if self.answers_output:
                    self.nulecule_base.loadAnswers(ret)
            else:
                self._processComponent(component, graph_item)
Ejemplo n.º 10
0
    def pullApp(self, image=None, update=None):
        if not image:
            image = self.app
        if not update:
            update = self.update

        image = self.getImageURI(image)
        if not update:
            check_cmd = ["docker", "images", "-q", image]
            image_id = subprocess.check_output(check_cmd)
            logger.debug("Output of docker images cmd: %s", image_id)
            if len(image_id) != 0:
                logger.debug(
                    "Image %s already present with id %s. Use --update to re-pull.",
                    image, image_id.strip())
                return

        pull = ["docker", "pull", image]
        printStatus("Pulling image %s ..." % image)
        if subprocess.call(pull) != 0:
            printErrorStatus("Couldn't pull %s." % image)
            raise Exception("Couldn't pull %s" % image)