예제 #1
0
 def __init__(self, local_full_fn, aws_connection=None, url=None):
     super(S3DownloadHelper, self).__init__(local_full_fn)
     self._s3_matcher = "^s3://(?P<BUCKET>[a-zA-Z0-9\-_]+)/(?P<KEY>[a-zA-Z0-9\-_/\.]+)/?"
     if aws_connection:
         self._aws_connection = aws_connection
     else:
         config = Config()
         aws_access_key_id = config.get_aws_access_key()
         aws_secret_access_key = config.get_aws_access_secret()
         self._aws_connection = S3Connection(aws_access_key_id,
                                             aws_secret_access_key, True)
     if url:
         self._url = url
예제 #2
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)
예제 #3
0
파일: agent.py 프로젝트: zeus911/teletraan
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()
예제 #4
0
 def __init__(self, client, estatus=None, conf=None, executor=None, helper=None):
     self._response = None
     # a map maintains env_name -> deploy_status
     self._envs = {}
     self._config = conf or Config()
     self._executor = executor
     self._helper = helper or Helper(self._config)
     self._STATUS_FILE = self._config.get_env_status_fn()
     self._client = client
     self._env_status = estatus or EnvStatus(self._STATUS_FILE)
     # load environment deploy status file from local disk
     self.load_status_file()
예제 #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
예제 #6
0
    def setUpClass(cls):
        cls.dirname = tempfile.mkdtemp()
        env_filename = os.path.join(cls.dirname, "variables")
        lines = [
            'env1 = \"test1\"\n', 'env2 =   \'test2\'\n', 'env3 = test3\n'
        ]

        with open(env_filename, 'w') as f:
            f.writelines(lines)

        config_reader = mock.Mock()
        config_reader.get = mock.Mock(return_value="/tmp")
        cls.config = Config(config_reader=config_reader)
예제 #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(),
                            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()