Пример #1
0
def get_and_print_ip(cached_ip, v):
    external_ip = get_external_ip(v)
    message("Cached IP: %s" % cached_ip)
    if external_ip is None:
        error("Could not retreive external IP")
        return
    message("External IP: %s" % external_ip)
Пример #2
0
def update_records(config, v):
    # First gather records and current IP from the web
    external_records = get_records(config.api_key, v)
    external_ip = get_external_ip(v)

    # Check if current external ip differs from cached ip
    if external_ip != config.ip:
        message("External IP Changed. Saving %s to config" % external_ip)
        config.ip = external_ip
        config.save()

    # If records have been saved in the config
    has_records = len(config.records.keys()) > 0
    if not has_records:
        # User has no records stored in the config, return
        error("No records saved in config. Try using the --configure flag")
        return

    # Cycle through returned external records.
    # Filter so we only have records we are interested in updating
    stored_hosts = config.records.keys()
    for e_record in [x for x in external_records if x.host in stored_hosts]:
        if e_record.address == config.ip:
            info(v, "%s does not need to be updated" % e_record.host)
            continue
        # External record has different ip then our currently cached ip
        # Update the record
        update_record(e_record, config.ip, v)