示例#1
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("-e", "--server_stage", dest="stage", default="prod", help="This option is deprecated")
    parser.add_argument(
        "-f", "--config-file", dest="config_file", required=False, help="the deploy agent config file path."
    )
    parser.add_argument(
        "-d", "--daemon", dest="daemon", action="store_true", help="Run deploy agent in daemon mode. Default is false."
    )
    parser.add_argument(
        "-n",
        "--host",
        dest="hostname",
        required=False,
        default=None,
        help="Host name being used when interact with Teletraan service. "
        "This is optional. By default the hostname defined in host-info "
        "file will be used",
    )
    parser.add_argument(
        "-g",
        "--group",
        dest="hostgroup",
        required=False,
        default=None,
        help="Group name being used when interact with Teletraan service. "
        "This is optional. By default the group name defined in host-info "
        "file will be used",
    )
    parser.add_argument("--use-facter", dest="use_facter", action="store_true", default=False)

    args = parser.parse_args()
    config = Config(args.config_file)
    utils.run_prereqs(config)

    if IS_PINTEREST:
        import pinlogger

        pinlogger.initialize_logger(logger_filename="deploy-agent.log")
        pinlogger.LOG_TO_STDERR = True
    else:
        log_filename = os.path.join(config.get_log_directory(), "deploy-agent.log")
        logging.basicConfig(filename=log_filename, level=config.get_log_level())

    log.info("Start to run deploy-agent.")
    client = Client(config=config, hostname=args.hostname, hostgroup=args.hostgroup, use_facter=args.use_facter)
    agent = DeployAgent(client=client, conf=config)
    utils.listen()
    if args.daemon:
        logger = logging.getLogger()
        handles = []
        for handler in logger.handlers:
            handles.append(handler.stream.fileno())
        with daemon.DaemonContext(files_preserve=handles):
            agent.serve_forever()
    else:
        agent.serve_once()
示例#2
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-e', '--server_stage', dest='stage', default='prod',
                        help="This option is deprecated")
    parser.add_argument('-f', '--config-file', dest='config_file', required=False,
                        help="the deploy agent config file path.")
    parser.add_argument('-d', '--daemon', dest="daemon", action='store_true',
                        help="Run deploy agent in daemon mode. Default is false.")
    parser.add_argument('-n', '--host', dest="hostname", required=False, default=None,
                        help="Host name being used when interact with Teletraan service. "
                             "This is optional. By default the hostname defined in host-info "
                             "file will be used")
    parser.add_argument('-g', '--group', dest='hostgroup', required=False, default=None,
                        help="Group name being used when interact with Teletraan service. "
                             "This is optional. By default the group name defined in host-info "
                             "file will be used")
    args = parser.parse_args()
    config = Config(args.config_file)
    utils.run_prereqs(config)

    if IS_PINTEREST:
        import pinlogger

        pinlogger.initialize_logger(logger_filename='deploy-agent.log')
        pinlogger.LOG_TO_STDERR = True
    else:
        log_filename = os.path.join(config.get_log_directory(), 'deploy-agent.log')
        logging.basicConfig(filename=log_filename, level=config.get_log_level())

    log.info("Start to run deploy-agent.")
    client = Client(config=config, hostname=args.hostname, hostgroup=args.hostgroup)
    agent = DeployAgent(client=client, conf=config)
    utils.listen()
    if args.daemon:
        logger = logging.getLogger()
        handles = []
        for handler in logger.handlers:
            handles.append(handler.stream.fileno())
        with daemon.DaemonContext(files_preserve=handles):
            agent.serve_forever()
    else:
        agent.serve_once()
示例#3
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-e', '--server_stage', dest='stage', default='prod',
                        help="This option is deprecated")
    parser.add_argument('-f', '--config-file', dest='config_file', required=False,
                        help="the deploy agent config file path.")
    parser.add_argument('-d', '--daemon', dest="daemon", action='store_true',
                        help="Run deploy agent in daemon mode. Default is false.")
    parser.add_argument('-n', '--host', dest="hostname", required=False, default=None,
                        help="Host name being used when interact with Teletraan service. "
                             "This is optional. By default the hostname defined in host-info "
                             "file will be used")
    parser.add_argument('-g', '--group', dest='hostgroup', required=False, default=None,
                        help="Group name being used when interact with Teletraan service. "
                             "This is optional. By default the group name defined in host-info "
                             "file will be used")
    parser.add_argument('--use-facter', dest='use_facter', action='store_true', default=False)
    parser.add_argument('--mode', dest='mode', default=None,
                        help="Optional. 'serverless' is the only non default mode supported. "
                             "In this mode, agent can be run for one time deployment without "
                             "interacting with teletraan service.")
    parser.add_argument('--build', dest='build', default=None,
                        help="Optional. In 'serverless' mode, build information is needed in "
                             "json format.")
    parser.add_argument('--env-name', dest='env_name', default=None,
                        help="Optional. In 'serverless' mode, env_name needs to be passed in.")
    parser.add_argument('--script-variables', dest='script_variables', default='{}',
                        help="Optional. In 'serverless' mode,  script_variables is needed in "
                             "json format.")

    args = parser.parse_args()

    is_serverless_mode = AgentRunMode.is_serverless(args.mode)
    if args.daemon and is_serverless_mode:
        raise ValueError("daemon and serverless mode is mutually exclusive.")
    config = Config(args.config_file)
    utils.run_prereqs(config)

    if IS_PINTEREST:
        import pinlogger

        pinlogger.initialize_logger(logger_filename='deploy-agent.log')
        pinlogger.LOG_TO_STDERR = True
    else:
        log_filename = os.path.join(config.get_log_directory(), 'deploy-agent.log')
        logging.basicConfig(filename=log_filename, level=config.get_log_level())

    log.info("Start to run deploy-agent.")
    client = Client(config=config, hostname=args.hostname, hostgroup=args.hostgroup, use_facter=args.use_facter)
    if is_serverless_mode:
        log.info("Running agent with severless client")
        client = ServerlessClient(env_name=args.env_name, stage=args.stage, build=args.build,
                                  script_variables=args.script_variables)

    agent = DeployAgent(client=client, conf=config)
    utils.listen()
    if args.daemon:
        logger = logging.getLogger()
        handles = []
        for handler in logger.handlers:
            handles.append(handler.stream.fileno())
        with daemon.DaemonContext(files_preserve=handles):
            agent.serve_forever()
    else:
        agent.serve_once()
示例#4
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-e', '--server_stage', dest='stage', default='prod',
                        help="This option is deprecated")
    parser.add_argument('-f', '--config-file', dest='config_file', required=False,
                        help="the deploy agent config file path.")
    parser.add_argument('-d', '--daemon', dest="daemon", action='store_true',
                        help="Run deploy agent in daemon mode. Default is false.")
    parser.add_argument('-n', '--host', dest="hostname", required=False, default=None,
                        help="Host name being used when interact with Teletraan service. "
                             "This is optional. By default the hostname defined in host-info "
                             "file will be used")
    parser.add_argument('-g', '--group', dest='hostgroup', required=False, default=None,
                        help="Group name being used when interact with Teletraan service. "
                             "This is optional. By default the group name defined in host-info "
                             "file will be used")
    parser.add_argument('--use-facter', dest='use_facter', action='store_true', default=False)
    parser.add_argument('--mode', dest='mode', default=None,
                        help="Optional. 'serverless' is the only non default mode supported. "
                             "In this mode, agent can be run for one time deployment without "
                             "interacting with teletraan service.")
    parser.add_argument('--build', dest='build', default=None,
                        help="Optional. In 'serverless' mode, build information is needed in "
                             "json format.")
    parser.add_argument('--env-name', dest='env_name', default=None,
                        help="Optional. In 'serverless' mode, env_name needs to be passed in.")
    parser.add_argument('--script-variables', dest='script_variables', default='{}',
                        help="Optional. In 'serverless' mode,  script_variables is needed in "
                             "json format.")

    args = parser.parse_args()

    is_serverless_mode = AgentRunMode.is_serverless(args.mode)
    if args.daemon and is_serverless_mode:
        raise ValueError("daemon and serverless mode is mutually exclusive.")
    config = Config(args.config_file)
    utils.run_prereqs(config)

    if IS_PINTEREST:
        import pinlogger

        pinlogger.initialize_logger(logger_filename='deploy-agent.log')
        pinlogger.LOG_TO_STDERR = True
    else:
        log_filename = os.path.join(config.get_log_directory(), 'deploy-agent.log')
        logging.basicConfig(filename=log_filename, level=config.get_log_level(),
                            format='%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s')

    log.info("Start to run deploy-agent.")
    client = Client(config=config, hostname=args.hostname, hostgroup=args.hostgroup,
                    use_facter=args.use_facter)
    if is_serverless_mode:
        log.info("Running agent with severless client")
        client = ServerlessClient(env_name=args.env_name, stage=args.stage, build=args.build,
                                  script_variables=args.script_variables)

    agent = DeployAgent(client=client, conf=config)
    utils.listen()
    if args.daemon:
        logger = logging.getLogger()
        handles = []
        for handler in logger.handlers:
            handles.append(handler.stream.fileno())
        with daemon.DaemonContext(files_preserve=handles):
            agent.serve_forever()
    else:
        agent.serve_once()