예제 #1
0
def config_logger():
    logfile = get_cli_log_file()
    logging_config = {
        "version": 1,
        "disable_existing_loggers": True,
        "formatters": {
            "standard": {
                "format": "%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s:%(funcName)s() - %(message)s"
            },
            "console": {"format": "%(message)s"},
        },
        "handlers": {
            "default": {
                "level": "DEBUG",
                "formatter": "standard",
                "class": "logging.handlers.RotatingFileHandler",
                "filename": logfile,
                "maxBytes": 5 * 1024 * 1024,
                "backupCount": 3,
            },
        },
        "loggers": {
            "": {"handlers": ["default"], "level": "WARNING", "propagate": False},  # root logger
            "pcluster": {"handlers": ["default"], "level": "INFO", "propagate": False},
        },
    }
    os.makedirs(os.path.dirname(logfile), exist_ok=True)
    logging.config.dictConfig(logging_config)
예제 #2
0
def config_logger():
    logger = logging.getLogger("pcluster")
    file_only_logger = logging.getLogger("cli_log_file")
    logger.setLevel(logging.DEBUG)

    log_stream_handler = logging.StreamHandler(sys.stdout)
    log_stream_handler.setLevel(logging.INFO)
    log_stream_handler.setFormatter(logging.Formatter("%(message)s"))
    logger.addHandler(log_stream_handler)

    logfile = utils.get_cli_log_file()
    try:
        os.makedirs(os.path.dirname(logfile))
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise  # can safely ignore EEXISTS for this purpose...

    log_file_handler = RotatingFileHandler(logfile,
                                           maxBytes=5 * 1024 * 1024,
                                           backupCount=1)
    log_file_handler.setLevel(logging.DEBUG)
    log_file_handler.setFormatter(
        logging.Formatter(
            "%(asctime)s - %(levelname)s - %(module)s - %(message)s"))
    logger.addHandler(log_file_handler)
    file_only_logger.addHandler(log_file_handler)
예제 #3
0
def config_logger():
    logfile = get_cli_log_file()
    logging_config = {
        "version": 1,
        "disable_existing_loggers": True,
        "formatters": {
            "standard": {
                "format":
                "%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s:%(funcName)s() - %(message)s"
            },
            "console": {
                "format": "%(message)s"
            },
        },
        "handlers": {
            "default": {
                "level": "DEBUG",
                "formatter": "standard",
                "class": "logging.handlers.RotatingFileHandler",
                "filename": logfile,
                "maxBytes": 5 * 1024 * 1024,
                "backupCount": 3,
            },
            "console": {
                "level": "DEBUG",
                "formatter": "standard",
                "class": "logging.StreamHandler",
                "stream": sys.__stdout__,
            },
        },
        "loggers": {
            "": {
                "handlers": ["default"],
                "level": "WARNING",
                "propagate": False
            },  # root logger
            "pcluster": {
                "handlers": ["default"],
                "level": "INFO",
                "propagate": False
            },
        },
    }
    if os.environ.get("PCLUSTER_LOG_TO_STDOUT"):
        for logger in logging_config["loggers"].values():
            logger["handlers"] = ["console"]
    os.makedirs(os.path.dirname(logfile), exist_ok=True)
    logging.config.dictConfig(logging_config)
예제 #4
0
def _create_network_stack(configuration, parameters):
    print("Creating CloudFormation stack...")
    print("Do not leave the terminal until the process has finished")
    stack_name = "parallelclusternetworking-{0}{1}".format(
        configuration.stack_name_prefix, TIMESTAMP)
    try:
        cfn_client = boto3.client("cloudformation")
        stack = cfn_client.create_stack(
            StackName=stack_name,
            TemplateURL=get_templates_bucket_path() +
            "networking/%s-%s.cfn.json" %
            (configuration.template_name, get_installed_version()),
            Parameters=parameters,
            Capabilities=["CAPABILITY_IAM"],
        )
        print("Stack Name: %s (id: %s)", stack_name, stack.get("StackId"))
        if not verify_stack_status(stack_name,
                                   waiting_states=["CREATE_IN_PROGRESS"],
                                   successful_states=["CREATE_COMPLETE"]):
            print("Could not create the network configuration")
            sys.exit(0)
        print()
        print("The stack has been created")
        return AWSApi.instance().cfn.describe_stack(stack_name).get("Outputs")
    except KeyboardInterrupt:
        print()
        print(
            "Unable to update the configuration file with the selected network configuration. "
            "Please manually check the status of the CloudFormation stack: %s",
            stack_name,
        )
        sys.exit(0)
    except Exception as e:  # Any exception is a problem
        print()
        print(
            "An exception occured while creating the CloudFormation stack: %s. "
            "For details please check log file: %s",
            stack_name,
            get_cli_log_file(),
        )
        LOGGER.critical(e)
        sys.exit(1)
def _create_network_stack(configuration, parameters):
    LOGGER.info("Creating CloudFormation stack...")
    LOGGER.info("Do not leave the terminal until the process has finished")
    stack_name = "parallelclusternetworking-{0}{1}".format(configuration.stack_name_prefix, TIMESTAMP)
    version = pkg_resources.get_distribution("aws-parallelcluster").version
    try:
        cfn_client = boto3.client("cloudformation")
        stack = cfn_client.create_stack(
            StackName=stack_name,
            TemplateURL=get_templates_bucket_path()
            + "networking/%s-%s.cfn.json" % (configuration.template_name, version),
            Parameters=parameters,
            Capabilities=["CAPABILITY_IAM"],
        )
        LOGGER.debug("StackId: {0}".format(stack.get("StackId")))
        LOGGER.info("Stack Name: {0}".format(stack_name))
        if not verify_stack_creation(stack_name, cfn_client):
            LOGGER.error("Could not create the network configuration")
            sys.exit(0)
        print()
        LOGGER.info("The stack has been created")
        return get_stack(stack_name, cfn_client).get("Outputs")
    except KeyboardInterrupt:
        print()
        LOGGER.info(
            "Unable to update the configuration file with the selected network configuration. "
            "Please manually check the status of the CloudFormation stack: {0}".format(stack_name)
        )
    except Exception as e:  # Any exception is a problem
        print()
        LOGGER.error(
            "An exception occured while creating the CloudFormation stack: {0}. "
            "For details please check log file: {1}".format(stack_name, get_cli_log_file())
        )
        LOGGER.critical(e)
        sys.exit(1)