Example #1
0
    def main(self, argv):
        self.parser = self.get_base_parser()
        run_setup.add_arguments(self.parser)
        (options, args) = self.parser.parse_known_args(argv)
        utils.setup_debugging(options.debug)

        LOG.debug('Starting clearstack')

        if not argv or options.help:
            self.do_help(options)
            return 0

        if options.gen_keys:
            LOG.debug('generating ssh keys')
            utils.generate_ssh_keys(options.gen_keys)

        # todo: fix
        # if options.allinone:
        #     LOG.debug('testing root access')
        #     if os.geteuid() != 0:
        #         LOG.error("clearstack: error: you need to have root access")
        #         sys.exit(1)

        """ Save user's variables, used to read/write answerfile """
        variables_cmd = {k: v for (k, v) in options.__dict__.items()
                         if v is not None and k.startswith("CONFIG_")}

        ansfile = AnswerFile.get()
        if options.gen_answer_file:
            LOG.debug('generating answer file')
            ansfile.generate(options.gen_answer_file, variables_cmd)

        if options.answer_file:
            try:
                LOG.debug('Reading answer file')
                ansfile.read(options.answer_file, variables_cmd)
                LOG.debug('Running all sequences')
                run_setup.run_all_sequences()
            except Exception as e:
                LOG.error("clearstack: {0}".format(str(e)))
                sys.exit(1)
            LOG.debug('Generating admin-openrc')
            run_setup.generate_admin_openrc()
Example #2
0
    def run_recipe(self, recipe_file, host):
        connection = None
        interpreter = "python3"
        if recipe_file.endswith('.sh'):
            interpreter = "bash -f"

        try:
            connection = self.connect(self.ssh_user, self.ssh_private_key,
                                      host)
            cmd = "source /root/.bashrc 2> /dev/null;" \
                  "source /usr/share/defaults/etc/profile 2> /dev/null;" \
                  "{0} {1}".format(interpreter, recipe_file)
            stdin, stdout, stderr = self.run_command(connection, cmd)
        except Exception as e:
            LOG.error("clearstack: an error has occurred in {0},"
                      " please check logs for more information"
                      .format(host))
            raise e
        finally:
            if connection:
                connection.close()