Ejemplo n.º 1
0
    ncs.logger.setLevel(logging.INFO)
    logger.debug('the logger is configured')

    ap = argparse.ArgumentParser(description=__doc__,
                                 fromfile_prefix_chars='@')
    ap.add_argument('inFilePath',
                    help='file path of json instance descriptions')
    ap.add_argument(
        '--authToken',
        help='the NCS authorization token to use (default uses env var)')
    args = ap.parse_args()

    # use authToken env var if none given as arg
    authToken = args.authToken or os.getenv('NCS_AUTH_TOKEN')

    inFilePath = args.inFilePath
    if os.path.isdir(inFilePath):
        inFilePath = os.path.join(inFilePath, 'recruitLaunched.json')
        logger.info('a directory path was given; reading from %s', inFilePath)
    with open(inFilePath) as inFile:
        instances = json.load(inFile)
        if instances:
            jobId = instances[0]['job']
            # terminate only if there's an authtoken
            if authToken:
                ncs.terminateJobInstances(authToken, jobId)
            else:
                logger.info('no authToken given, so not terminating')
            ncs.purgeKnownHosts(instances)
    logger.info('finished')
Ejemplo n.º 2
0
        help='the NCS authorization token to use (default uses env var)')
    args = ap.parse_args()

    # use authToken env var if none given as arg
    authToken = args.authToken or os.getenv('NCS_AUTH_TOKEN')
    if not authToken:
        logger.error('no authToken given, so not terminating')
        sys.exit(1)
    inFilePath = args.inFilePath
    if os.path.isdir(inFilePath):
        inFilePath = os.path.join(inFilePath, 'recruitLaunched.json')
        logger.info('a directory path was given; reading from %s', inFilePath)
    respCode = None
    with open(inFilePath) as inFile:
        instances = json.load(inFile)
        if instances:
            jobId = instances[0]['job']
            # terminate only if there's an authtoken
            if authToken:
                logger.info('terminating instances for job %s', jobId)
                respCode = ncs.terminateJobInstances(authToken, jobId)
            else:
                logger.info('no authToken given, so not terminating')
            ncs.purgeKnownHosts(instances)
    logger.info('finished')
    if respCode in [200, 204]:
        sys.exit(0)
    else:
        logger.error('error from server: %d', respCode)
        sys.exit(2)