示例#1
0
def get_dependencies():
    if os.getenv("DATADOG_API_KEY"):
        options['api_key'] = os.getenv("DATADOG_API_KEY")
    else:
        print(red("DATADOG_API_KEY missing from environment variables"))
        exit()
    if os.getenv("DATADOG_APP_KEY"):
        options['app_key'] = os.getenv("DATADOG_APP_KEY")
    else:
        print(red("DATADOG_APP_KEY missing from environment variables"))
        exit()
    return options
示例#2
0
def procede(msg):
    reply = input("%s (%s/%s/%s) " %
                  (msg, green('y'), red('n'), blue('q'))).lower()
    if reply in ['y', 'yes']:
        return True
    if reply in ['n', 'no']:
        return False
    exit()
示例#3
0
def config_cmd(args):
    options = get_dependencies()
    for k, v in options.items():
        print("%s: %s" % (k, v))
    if os.getenv("JENKINS_URL"):
        print("JENKINS_URL: %s" % os.getenv("JENKINS_URL"))
    else:
        print(
            red("Failed to get JENKINS_URL. Be sure to have it set as an environment variable"
                ))
示例#4
0
def scrape_host(host):
    try:
        host = host['tags_by_source']
        box = Provision()
        box.instance_size = get_tag(host, 'instance-type',
                                    'Amazon Web Services')
        box.zk_cluster = get_tag(host, 'zk_cluster', 'Chef')
        box.kafka_cluster = get_tag(host, 'kafka_cluster', 'Chef')
        box.kafka_topic = get_tag(host, 'kafka_topic', 'Chef')
        box.partitions = get_partitions(host, 'kafka_partition', 'Chef')
        return box
    except:
        print(red('There was an error parsing host from Datadog'))
        raise
示例#5
0
def confirm_params(params, cmd_type, override):
    validated = False
    confirmed = False
    while not confirmed:
        if not override:
            while not validated:
                validated, details = params.validate()
                if not validated:
                    print(
                        red("Your parameters are invalid. Details: %s" %
                            details))
                    params = edit_file(params, cmd_type)
                    validated = False
            print(green("Validation PASSED"))
        print(params)
        confirmed = procede("Does this look right to you?")
        if not confirmed:
            params = edit_file(params, cmd_type)
            validated = False
    return params
示例#6
0
def edit_file(params, cmd_type, ask_edit=True):
    if ask_edit:
        if not procede("Would you like to edit your params?"):
            return params
    MARKER = '# Everything below is ignored'
    edited = click.edit(str(params) + '\n' + MARKER)
    if edited is None:
        return params
    try:
        tag_lines = edited.split('\n')
        ignore_index = len(tag_lines)
        for i in range(len(tag_lines)):
            if tag_lines[i] == MARKER:
                ignore_index = i
                break
        tag_lines = tag_lines[:ignore_index]
        params = [tag.split(': ') for tag in tag_lines]
        box = cmd_type(params)
    except:
        print(red("There was an error with your edits."))
        raise
    assert box != None
    return box