Beispiel #1
0
def main():

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-f', '--config-file', dest='config_file', default=None,
                        help="the deploy agent conf file filename path. If none, "
                             "/etc/deployagent.conf will be used")
    parser.add_argument('-v', '--build-version', dest='build', required=True,
                        help="the current deploying build version for the current environment.")
    parser.add_argument('-u', '--url', dest='url', required=True,
                        help="the url of the source code where the downloader would download from. "
                             "The url can start"
                             "with s3:// or https://")
    parser.add_argument('-e', '--env-name', dest='env_name', required=True,
                        help="the environment name currently in deploy.")
    args = parser.parse_args()
    config = Config(args.config_file)
    logging.basicConfig(level=config.get_log_level())

    log.info("Start to download the package.")
    status = Downloader(config, args.build, args.url, args.env_name).download()
    if status != Status.SUCCEEDED:
        log.error("Download failed.")
        sys.exit(1)
    else:
        log.info("Download succeeded.")
        sys.exit(0)
Beispiel #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",
    )
    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()
Beispiel #3
0
def main():

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        '-f',
        '--config-file',
        dest='config_file',
        default=None,
        help="the deploy agent conf file filename path. If none, "
        "/etc/deployagent.conf will be used")
    parser.add_argument(
        '-v',
        '--build-version',
        dest='build',
        required=True,
        help="the current deploying build version for the current environment."
    )
    parser.add_argument(
        '-u',
        '--url',
        dest='url',
        required=True,
        help=
        "the url of the source code where the downloader would download from. "
        "The url can start"
        "with s3:// or https://")
    parser.add_argument('-e',
                        '--env-name',
                        dest='env_name',
                        required=True,
                        help="the environment name currently in deploy.")
    args = parser.parse_args()
    config = Config(args.config_file)
    logging.basicConfig(level=config.get_log_level())

    log.info("Start to download the package.")
    status = Downloader(config, args.build, args.url, args.env_name).download()
    if status != Status.SUCCEEDED:
        log.error("Download failed.")
        sys.exit(1)
    else:
        log.info("Download succeeded.")
        sys.exit(0)
Beispiel #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")
    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()
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-f', '--config-file', dest='config_file', default=None,
                        help="the deploy agent conf file filename path. If none, "
                             "/etc/deployagent.conf will be used")
    parser.add_argument('-v', '--build-id', dest='build', required=True,
                        help="the current deploying build version for the current environment.")
    parser.add_argument('-t', '--target', dest='target', required=True,
                        help="The deploy target directory name.")
    parser.add_argument('-e', '--env-name', dest='env_name', required=True,
                        help="the environment name currently in deploy.")
    args = parser.parse_args()
    config = Config(args.config_file)
    logging.basicConfig(level=config.get_log_level())

    log.info("Start to stage the package.")
    result = Stager(config=config, build=args.build,
                    target=args.target, env_name=args.env_name).enable_package()
    if result == Status.SUCCEEDED:
        return 0
    else:
        return 1
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-f', '--config-file', dest='config_file', default=None,
                        help="the deploy agent conf file filename path. If none, "
                             "/etc/deployagent.conf will be used")
    parser.add_argument('-v', '--build-id', dest='build', required=True,
                        help="the current deploying build version for the current environment.")
    parser.add_argument('-t', '--target', dest='target', required=True,
                        help="The deploy target directory name.")
    parser.add_argument('-e', '--env-name', dest='env_name', required=True,
                        help="the environment name currently in deploy.")
    args = parser.parse_args()
    config = Config(args.config_file)
    logging.basicConfig(level=config.get_log_level())

    log.info("Start to stage the package.")
    result = Stager(config=config, build=args.build,
                    target=args.target, env_name=args.env_name).enable_package()
    if result == Status.SUCCEEDED:
        return 0
    else:
        return 1
Beispiel #7
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()
Beispiel #8
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()