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)
def get_and_print_records(api_key, v): records = get_records(api_key, v) if records is None: error("Could not retreive records") return for record in records: message(record)
def configure_config_file(config, v): # First gather records from the web external_records = get_records(config.api_key, v) message("Found %s Records" % len(external_records)) # Prompt to delete current records has_records = len(config.records.keys()) > 0 if has_records and get_yes_no("Delete all records (y/n): "): debug(v, "Deleting all records") for key in config.records.keys(): extra(v, "Deleting Record: %s" % config.records[key]) del(config.records[key]) # Go through each record and prompt the user to save it for new_record in external_records: if get_yes_no("Save %s to config file (y/n): " % new_record.host): config.records[new_record.host] = new_record.updateKey() extra(v, "Saving New Record: %s" % config.records[new_record.host]) config.save()