Ejemplo n.º 1
0
    def _process_answers(self):
        """
        Processes answer files to load data from them and then merges
        any cli provided answers into the config.

        NOTE: This function should be called once on startup and then
        once more after the application has been extracted, but only
        if answers file wasn't found on the first invocation. The idea
        is to allow for people to embed an answers file in the application
        if they want, which won't be available until after extraction.

        Returns:
            None
        """

        # If the user didn't provide an answers file then check the app
        # dir to see if one exists.
        if not self.answers_file:
            f = os.path.join(self.app_path, ANSWERS_FILE)
            if os.path.isfile(f):
                self.answers_file = f

        # At this point if we have an answers file, load it
        if self.answers_file:
            self.answers = Utils.loadAnswers(self.answers_file)

        # If there is answers data from the cli then merge it in now
        if self.cli_answers:
            for k, v in self.cli_answers.iteritems():
                self.answers[GLOBAL_CONF][k] = v
Ejemplo n.º 2
0
    def install(self, nodeps=False, update=False, dryrun=False, answers_format=ANSWERS_FILE_SAMPLE_FORMAT, **kwargs):
        """
        Installs (unpacks) a Nulecule application from a Nulecule image
        to a target path.

        Args:
            answers (dict or str): Answers data or local path to answers file
            nodeps (bool): Install the nulecule application without installing
                           external dependencies
            update (bool): Pull requisite Nulecule image and install or
                           update already installed Nulecule application
            dryrun (bool): Do not make any change to the host system if True
            answers_format (str): File format for writing sample answers file
            kwargs (dict): Extra keyword arguments

        Returns:
            None
        """
        if self.answers_file:
            self.answers = Utils.loadAnswers(self.answers_file)
        self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT

        # Call unpack. If the app doesn't exist it will be pulled. If
        # it does exist it will be just be loaded and returned
        self.nulecule = self.unpack(update, dryrun, config=self.answers)

        self.nulecule.load_config(config=self.nulecule.config, skip_asking=True)
        runtime_answers = self._get_runtime_answers(self.nulecule.config, None)
        # write sample answers file
        self._write_answers(os.path.join(self.app_path, ANSWERS_FILE_SAMPLE), runtime_answers, answers_format)
Ejemplo n.º 3
0
    def stop(self, cli_provider, **kwargs):
        """
        Stops a running Nulecule application.

        Args:
            cli_provider (str): Provider running the Nulecule application
            kwargs (dict): Extra keyword arguments
        """
        # For stop we use the generated answer file from the run
        self.answers = Utils.loadAnswers(os.path.join(self.app_path, ANSWERS_RUNTIME_FILE))

        dryrun = kwargs.get("dryrun") or False
        self.nulecule = Nulecule.load_from_path(self.app_path, config=self.answers, dryrun=dryrun)
        self.nulecule.load_config(config=self.answers)
        self.nulecule.render(cli_provider, dryrun=dryrun)
        self.nulecule.stop(cli_provider, dryrun)
Ejemplo n.º 4
0
    def _process_answers(self):
        """
        Processes answer files to load data from them and then merges
        any cli provided answers into the config.

        NOTE: This function should be called once on startup and then
        once more after the application has been extracted, but only
        if answers file wasn't found on the first invocation. The idea
        is to allow for people to embed an answers file in the application
        if they want, which won't be available until after extraction.

        Returns:
            None
        """
        app_path_answers = os.path.join(self.app_path, ANSWERS_FILE)

        # If the user didn't provide an answers file then check the app
        # dir to see if one exists.
        if not self.answers_file:
            if os.path.isfile(app_path_answers):
                self.answers_file = app_path_answers

        # At this point if we have an answers file, load it
        if self.answers_file:

            # If this is a url then download answers file to app directory
            if urlparse.urlparse(self.answers_file).scheme != "":
                logger.debug("Retrieving answers file from: {}".format(
                    self.answers_file))
                with open(app_path_answers, 'w+') as f:
                    stream = urllib.urlopen(self.answers_file)
                    f.write(stream.read())
                self.answers_file = app_path_answers

            # Check to make sure the file exists
            if not os.path.isfile(self.answers_file):
                raise NuleculeException(
                    "Provided answers file doesn't exist: {}".format(
                        self.answers_file))

            # Load answers
            self.answers = Utils.loadAnswers(self.answers_file)

        # If there is answers data from the cli then merge it in now
        if self.cli_answers:
            for k, v in self.cli_answers.iteritems():
                self.answers[GLOBAL_CONF][k] = v
Ejemplo n.º 5
0
    def _process_answers(self):
        """
        Processes answer files to load data from them and then merges
        any cli provided answers into the config.

        NOTE: This function should be called once on startup and then
        once more after the application has been extracted, but only
        if answers file wasn't found on the first invocation. The idea
        is to allow for people to embed an answers file in the application
        if they want, which won't be available until after extraction.

        Returns:
            None
        """
        app_path_answers = os.path.join(self.app_path, ANSWERS_FILE)

        # If the user didn't provide an answers file then check the app
        # dir to see if one exists.
        if not self.answers_file:
            if os.path.isfile(app_path_answers):
                self.answers_file = app_path_answers

        # At this point if we have an answers file, load it
        if self.answers_file:

            # If this is a url then download answers file to app directory
            if urlparse.urlparse(self.answers_file).scheme != "":
                logger.debug("Retrieving answers file from: {}"
                             .format(self.answers_file))
                with open(app_path_answers, 'w+') as f:
                    stream = urllib.urlopen(self.answers_file)
                    f.write(stream.read())
                self.answers_file = app_path_answers

            # Check to make sure the file exists
            if not os.path.isfile(self.answers_file):
                raise NuleculeException(
                    "Provided answers file doesn't exist: {}".format(self.answers_file))

            # Load answers
            self.answers = Utils.loadAnswers(self.answers_file)

        # If there is answers data from the cli then merge it in now
        if self.cli_answers:
            for k, v in self.cli_answers.iteritems():
                self.answers[GLOBAL_CONF][k] = v
Ejemplo n.º 6
0
    def stop(self, cli_provider, **kwargs):
        """
        Stops a running Nulecule application.

        Args:
            cli_provider (str): Provider running the Nulecule application
            kwargs (dict): Extra keyword arguments
        """
        self.answers = Utils.loadAnswers(
            os.path.join(self.app_path, ANSWERS_RUNTIME_FILE))
        dryrun = kwargs.get('dryrun') or False
        self.nulecule = Nulecule.load_from_path(self.app_path,
                                                config=self.answers,
                                                dryrun=dryrun)
        self.nulecule.load_config(config=self.answers)
        self.nulecule.render(cli_provider, dryrun=dryrun)
        self.nulecule.stop(cli_provider, dryrun)
Ejemplo n.º 7
0
    def run(self,
            answers,
            cli_provider,
            answers_output,
            ask,
            answers_format=ANSWERS_FILE_SAMPLE_FORMAT,
            **kwargs):
        """
        Runs a Nulecule application from a local path or a Nulecule image
        name.

        Args:
            answers (dict or str): Answers data or local path to answers file
            cli_provider (str): Provider to use to run the Nulecule
                                application
            answers_output (str): Path to file to export runtime answers data
                                  to
            ask (bool): Ask for values for params with default values from
                        user, if True
            answers_format (str): File format for writing sample answers file
            kwargs (dict): Extra keyword arguments

        Returns:
            None
        """
        self.answers = Utils.loadAnswers(
            answers or os.path.join(self.app_path, ANSWERS_FILE))
        self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT
        dryrun = kwargs.get('dryrun') or False

        # Call unpack. If the app doesn't exist it will be pulled. If
        # it does exist it will be just be loaded and returned
        self.nulecule = self.unpack(dryrun=dryrun, config=self.answers)

        self.nulecule.load_config(config=self.nulecule.config, ask=ask)
        self.nulecule.render(cli_provider, dryrun)
        self.nulecule.run(cli_provider, dryrun)
        runtime_answers = self._get_runtime_answers(self.nulecule.config,
                                                    cli_provider)
        self._write_answers(os.path.join(self.app_path, ANSWERS_RUNTIME_FILE),
                            runtime_answers,
                            self.answers_format,
                            dryrun=dryrun)
        if answers_output:
            self._write_answers(answers_output, runtime_answers,
                                self.answers_format, dryrun)
Ejemplo n.º 8
0
    def run(self, cli_provider, answers_output, ask,
            answers_format=ANSWERS_FILE_SAMPLE_FORMAT, **kwargs):
        """
        Runs a Nulecule application from a local path or a Nulecule image
        name.

        Args:
            answers (dict or str): Answers data or local path to answers file
            cli_provider (str): Provider to use to run the Nulecule
                                application
            answers_output (str): Path to file to export runtime answers data
                                  to
            ask (bool): Ask for values for params with default values from
                        user, if True
            answers_format (str): File format for writing sample answers file
            kwargs (dict): Extra keyword arguments

        Returns:
            None
        """
        if self.answers_file:
            self.answers = Utils.loadAnswers(self.answers_file)
        self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT
        dryrun = kwargs.get('dryrun') or False

        # Call unpack. If the app doesn't exist it will be pulled. If
        # it does exist it will be just be loaded and returned
        self.nulecule = self.unpack(dryrun=dryrun, config=self.answers)

        # Unless otherwise specified with CLI arguments we will
        # default to the first provider available
        providers = Utils.getSupportedProviders(self.app_path)
        if cli_provider is None and len(providers) == 1:
            self.answers[GLOBAL_CONF][PROVIDER_KEY] = providers[0]

        self.nulecule.load_config(config=self.nulecule.config, ask=ask)
        self.nulecule.render(cli_provider, dryrun)
        self.nulecule.run(cli_provider, dryrun)
        runtime_answers = self._get_runtime_answers(
            self.nulecule.config, cli_provider)
        self._write_answers(
            os.path.join(self.app_path, ANSWERS_RUNTIME_FILE),
            runtime_answers, self.answers_format)
        if answers_output:
            self._write_answers(answers_output, runtime_answers,
                                self.answers_format)
Ejemplo n.º 9
0
    def install(self,
                answers,
                nodeps=False,
                update=False,
                dryrun=False,
                answers_format=ANSWERS_FILE_SAMPLE_FORMAT,
                **kwargs):
        """
        Installs (unpacks) a Nulecule application from a Nulecule image
        to a target path.

        Args:
            answers (dict or str): Answers data or local path to answers file
            nodeps (bool): Install the nulecule application without installing
                           external dependencies
            update (bool): Pull requisite Nulecule image and install or
                           update already installed Nulecule application
            dryrun (bool): Do not make any change to the host system if True
            answers_format (str): File format for writing sample answers file
            kwargs (dict): Extra keyword arguments

        Returns:
            None
        """
        self.answers = Utils.loadAnswers(
            answers or os.path.join(self.app_path, ANSWERS_FILE))
        self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT

        # Call unpack. If the app doesn't exist it will be pulled. If
        # it does exist it will be just be loaded and returned
        self.nulecule = self.unpack(update, dryrun, config=self.answers)

        self.nulecule.load_config(config=self.nulecule.config,
                                  skip_asking=True)
        runtime_answers = self._get_runtime_answers(self.nulecule.config, None)
        # write sample answers file
        self._write_answers(os.path.join(self.app_path, ANSWERS_FILE_SAMPLE),
                            runtime_answers,
                            answers_format,
                            dryrun=dryrun)
Ejemplo n.º 10
0
    def run(self, answers, cli_provider, answers_output, ask,
            answers_format=ANSWERS_FILE_SAMPLE_FORMAT, **kwargs):
        """
        Runs a Nulecule application from a local path or a Nulecule image
        name.

        Args:
            answers (dict or str): Answers data or local path to answers file
            cli_provider (str): Provider to use to run the Nulecule
                                application
            answers_output (str): Path to file to export runtime answers data
                                  to
            ask (bool): Ask for values for params with default values from
                        user, if True
            answers_format (str): File format for writing sample answers file
            kwargs (dict): Extra keyword arguments

        Returns:
            None
        """
        self.answers = Utils.loadAnswers(
            answers or os.path.join(self.app_path, ANSWERS_FILE))
        self.answers_format = answers_format or ANSWERS_FILE_SAMPLE_FORMAT
        dryrun = kwargs.get('dryrun') or False

        # Call unpack. If the app doesn't exist it will be pulled. If
        # it does exist it will be just be loaded and returned
        self.nulecule = self.unpack(dryrun=dryrun, config=self.answers)

        self.nulecule.load_config(config=self.nulecule.config, ask=ask)
        self.nulecule.render(cli_provider, dryrun)
        self.nulecule.run(cli_provider, dryrun)
        runtime_answers = self._get_runtime_answers(
            self.nulecule.config, cli_provider)
        self._write_answers(
            os.path.join(self.app_path, ANSWERS_RUNTIME_FILE),
            runtime_answers, self.answers_format, dryrun=dryrun)
        if answers_output:
            self._write_answers(answers_output, runtime_answers,
                                self.answers_format, dryrun)