Example #1
0
def set_json(domain, action, filename=False, record=False):
    """Convert text file to JSON.

    Arguments:

        domain:   domain name of updating target
        action:   True ; for PUT/POST HTTP method
                  False; for DELETE HTTP method
        filename: text file of bulk updating (default is False)
        record:   json record of updating single record (default is False)
    """
    o = JSONConverter(domain)

    if filename:
        # for 'bulk_create/bulk_delete'
        with open(filename, 'r') as f:
            o.separate_input_file(f)
            for item in o.separated_list:
                o.read_records(item.splitlines())
                o.generata_data(action)

    elif record:
        # for 'create/delete'
        o.read_records(record)
        o.generata_data(action)

    return o.dict_records
Example #2
0
def set_json(domain, action, filename=False, record=False):
    """Convert text file to JSON.

    Arguments:

        domain:   domain name of updating target
        action:   True ; for PUT/POST HTTP method
                  False; for DELETE HTTP method
        filename: text file of bulk updating (default is False)
        record:   json record of updating single record (default is False)
    """
    o = JSONConverter(domain)

    if filename:
        # for 'bulk_create/bulk_delete'
        with open(filename, 'r') as f:
            o.separate_input_file(f)
            for item in o.separated_list:
                o.read_records(item.splitlines())
                o.generata_data(action)

    elif record:
        # for 'create/delete'
        o.read_records(record)
        o.generata_data(action)

    return o.dict_records
Example #3
0
def update_soa_serial(server, token, soa_content):
    """Update SOA serial

    Argument:

        server:      TonicDNS API server
        token:       TonicDNS API authentication token
        soa_content: SOA record data

    x-authentication-token: token
    Get SOA record
    `cur_soa` is current SOA record.
    `new_soa` is incremental serial SOA record.
    """
    method = 'GET'
    uri = 'https://' + server + '/zone/' + soa_content.get('domain')
    cur_soa, new_soa = connect.tonicdns_client(uri,
                                               method,
                                               token,
                                               data=False,
                                               keyword='serial',
                                               content=soa_content)
    # set JSON

    domain = soa_content.get('domain')
    cur_o = JSONConverter(domain)
    new_o = JSONConverter(domain)
    cur_o.records = [cur_soa]
    new_o.records = [new_soa]
    cur_o.generata_data(False)
    new_o.generata_data(True)

    # Create new SOA record
    uri = 'https://' + server + '/zone/' + domain
    method = 'PUT'
    connect.tonicdns_client(uri, method, token, new_o.dict_records[0])

    # Delete current SOA record why zone has only one SOA record.
    method = 'DELETE'
    uri = 'https://' + server + '/zone'
    connect.tonicdns_client(uri, method, token, cur_o.dict_records[0])
Example #4
0
def update_soa_serial(server, token, soa_content):
    """Update SOA serial

    Argument:

        server:      TonicDNS API server
        token:       TonicDNS API authentication token
        soa_content: SOA record data

    x-authentication-token: token
    Get SOA record
    `cur_soa` is current SOA record.
    `new_soa` is incremental serial SOA record.
    """
    method = 'GET'
    uri = 'https://' + server + '/zone/' + soa_content.get('domain')
    cur_soa, new_soa = connect.tonicdns_client(
        uri, method, token, data=False, keyword='serial', content=soa_content)
    # set JSON

    domain = soa_content.get('domain')
    cur_o = JSONConverter(domain)
    new_o = JSONConverter(domain)
    cur_o.records = [cur_soa]
    new_o.records = [new_soa]
    cur_o.generata_data(False)
    new_o.generata_data(True)

    # Create new SOA record
    uri = 'https://' + server + '/zone/' + domain
    method = 'PUT'
    connect.tonicdns_client(uri, method, token, new_o.dict_records[0])

    # Delete current SOA record why zone has only one SOA record.
    method = 'DELETE'
    uri = 'https://' + server + '/zone'
    connect.tonicdns_client(uri, method, token, cur_o.dict_records[0])