Ejemplo n.º 1
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)
        # Set verbosity level
        loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError, ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)
Ejemplo n.º 2
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)
        # Set verbosity level
        loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError, ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)
Ejemplo n.º 3
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)
        # Set verbosity level
        loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError as ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)

        # If no configuration file was specified and default does not exists...
        if not os.path.isfile(self.params.config):
            if self.params.config == self.default_configuration_file:
            # Copy the default configuration file to the user's home
                if not os.path.exists(os.path.dirname(self.params.config)):
                    os.mkdir(os.path.dirname(self.params.config))
                template = os.path.join(
                    sys.prefix, 'share/elasticluster/etc/config.template')
                log.warning("Deploying default configuration file to %s.",
                            self.params.config)
                shutil.copyfile(template, self.params.config)
            else:
                # Exit if supplied configuration file does not exists.
                if not os.path.isfile(self.params.config):
                    sys.stderr.write(
                        "Unable to read configuration file `%s`.\n" %
                        self.params.config)
                    sys.exit(1)


        if self.params.func:
            try:
                self.params.func.pre_run()
            except (RuntimeError, ConfigurationError) as ex:
                sys.stderr.write(str(ex).strip() + '\n')
                sys.exit(1)
Ejemplo n.º 4
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)
        # Set verbosity level
        loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError as ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)

        # If no configuration file was specified and default does not exists...
        if not os.path.isfile(self.params.config):
            if self.params.config == self.default_configuration_file:
                # Copy the default configuration file to the user's home
                if not os.path.exists(os.path.dirname(self.params.config)):
                    os.mkdir(os.path.dirname(self.params.config))
                template = os.path.join(
                    sys.prefix, 'share/elasticluster/etc/config.template')
                log.warning("Deploying default configuration file to %s.",
                            self.params.config)
                shutil.copyfile(template, self.params.config)
            else:
                # Exit if supplied configuration file does not exists.
                if not os.path.isfile(self.params.config):
                    sys.stderr.write(
                        "Unable to read configuration file `%s`.\n" %
                        self.params.config)
                    sys.exit(1)

        if self.params.func:
            try:
                self.params.func.pre_run()
            except (RuntimeError, ConfigurationError) as ex:
                sys.stderr.write(str(ex).strip() + '\n')
                sys.exit(1)
Ejemplo n.º 5
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)

        # print *all* Python warnings through the logging subsystem
        warnings.resetwarnings()
        warnings.simplefilter('once')
        utils.redirect_warnings(logger='gc3.elasticluster')

        # Set verbosity level
        loglevel = max(logging.DEBUG,
                       logging.WARNING - 10 * max(0, self.params.verbose))
        coloredlogs.install(logger=log, level=loglevel)
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError as ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)

        self.check_config_or_copy_template()

        assert self.params.func, "No subcommand defined in `ElastiCluster.setup()"
        try:
            self.params.func.pre_run()
        except (RuntimeError, ConfigurationError) as ex:
            sys.stderr.write(str(ex).strip())
            sys.stderr.write('\n')
            sys.exit(1)
Ejemplo n.º 6
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)

        # print *all* Python warnings through the logging subsystem
        warnings.resetwarnings()
        warnings.simplefilter('once')
        utils.redirect_warnings(logger='gc3.elasticluster')

        # Set verbosity level
        loglevel = max(logging.DEBUG, logging.WARNING - 10 * max(0, self.params.verbose))
        coloredlogs.install(logger=log, level=loglevel)
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError as ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)

        self.check_config_or_copy_template()

        assert self.params.func, "No subcommand defined in `ElastiCluster.setup()"
        try:
            self.params.func.pre_run()
        except (RuntimeError, ConfigurationError) as ex:
            sys.stderr.write(str(ex).strip())
            sys.stderr.write('\n')
            sys.exit(1)
Ejemplo n.º 7
0
    def main(self):
        """
        Elasticluster will start, stop, grow, shrink clusters on an EC2 cloud.
        """
        # This is the main entry point of the elasticluster.  First the
        # central configuration is created, which can be altered through
        # the command line interface. Then the given command from the
        # command line interface is called.

        # Set verbosity level
        loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
        log.setLevel(loglevel)

        # call the subcommand function (ususally execute)
        try:
            return self.params.func()
        except (MultipleInvalid, Invalid) as e:
            print("Error validating configuration file '%s': `%s`" % (self.params.config, e))
            sys.exit(1)
Ejemplo n.º 8
0
    def main(self):
        """
        Elasticluster will start, stop, grow, shrink clusters on an EC2 cloud.
        """
        # This is the main entry point of the elasticluster.  First the
        # central configuration is created, which can be altered through
        # the command line interface. Then the given command from the
        # command line interface is called.

        # Set verbosity level
        loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
        log.setLevel(loglevel)
        # initialize configuration singleton with given global parameters
        try:
            Configuration.Instance().file_path = self.params.config
            Configuration.Instance().storage_path = self.params.storage
        except Exception as ex:
            print "please specify a valid configuration file"
            sys.exit(1)

        # call the subcommand function (ususally execute)
        return self.params.func()
Ejemplo n.º 9
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)

        # print *all* Python warnings through the logging subsystem
        warnings.resetwarnings()
        warnings.simplefilter('once')
        utils.redirect_warnings(logger='gc3.elasticluster')

        # Set verbosity level
        loglevel = max(logging.DEBUG, logging.WARNING - 10 * max(0, self.params.verbose))
        coloredlogs.install(logger=log, level=loglevel)
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError as ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)

        # If no configuration file was specified and default does not exists and the user did not create a config dir...
        if not os.path.isfile(self.params.config) and not os.path.isdir(self.params.config + '.d'):
            if self.params.config == self.default_configuration_file:
            # Copy the default configuration file to the user's home
                if not os.path.exists(os.path.dirname(self.params.config)):
                    os.mkdir(os.path.dirname(self.params.config))
                template = resource_filename(
                    'elasticluster', 'share/etc/config.template')
                log.warning("Deploying default configuration file to %s.",
                            self.params.config)
                shutil.copyfile(template, self.params.config)
            else:
                # Exit if supplied configuration file does not exists.
                if not os.path.isfile(self.params.config):
                    sys.stderr.write(
                        "Unable to read configuration file `%s`.\n" %
                        self.params.config)
                    sys.exit(1)

        assert self.params.func, ("No subcommand defined in `ElastiCluster.setup()")
        try:
            self.params.func.pre_run()
        except (RuntimeError, ConfigurationError) as ex:
            sys.stderr.write(str(ex).strip())
            sys.stderr.write('\n')
            sys.exit(1)
Ejemplo n.º 10
0
    def pre_run(self):
        # Hack around http://bugs.python.org/issue9253 ?
        if "--version" in sys.argv:
            import pkg_resources
            version = pkg_resources.get_distribution("elasticluster").version
            print("elasticluster version %s" % version)
            sys.exit(0)

        cli.app.CommandLineApp.pre_run(self)

        # print *all* Python warnings through the logging subsystem
        warnings.resetwarnings()
        warnings.simplefilter('once')
        utils.redirect_warnings(logger='gc3.elasticluster')

        # Set verbosity level
        loglevel = max(logging.DEBUG,
                       logging.WARNING - 10 * max(0, self.params.verbose))
        coloredlogs.install(logger=log, level=loglevel)
        log.setLevel(loglevel)

        # In debug mode, avoid forking
        if self.params.verbose > 3:
            log.DO_NOT_FORK = True
            log.raiseExceptions = True

        if not os.path.isdir(self.params.storage):
            # We do not create *all* the parents, but we do create the
            # directory if we can.
            try:
                os.makedirs(self.params.storage)
            except OSError as ex:
                sys.stderr.write("Unable to create storage directory: "
                                 "%s\n" % (str(ex)))
                sys.exit(1)

        # If no configuration file was specified and default does not exists and the user did not create a config dir...
        if not os.path.isfile(
                self.params.config) and not os.path.isdir(self.params.config +
                                                          '.d'):
            if self.params.config == self.default_configuration_file:
                # Copy the default configuration file to the user's home
                if not os.path.exists(os.path.dirname(self.params.config)):
                    os.mkdir(os.path.dirname(self.params.config))
                template = resource_filename('elasticluster',
                                             'share/etc/config.template')
                log.warning("Deploying default configuration file to %s.",
                            self.params.config)
                shutil.copyfile(template, self.params.config)
            else:
                # Exit if supplied configuration file does not exists.
                if not os.path.isfile(self.params.config):
                    sys.stderr.write(
                        "Unable to read configuration file `%s`.\n" %
                        self.params.config)
                    sys.exit(1)

        assert self.params.func, (
            "No subcommand defined in `ElastiCluster.setup()")
        try:
            self.params.func.pre_run()
        except (RuntimeError, ConfigurationError) as ex:
            sys.stderr.write(str(ex).strip())
            sys.stderr.write('\n')
            sys.exit(1)