diff --git a/update-record.py b/update-record.py index 67c4fcc..ea075e4 100755 --- a/update-record.py +++ b/update-record.py @@ -65,10 +65,21 @@ print('subdomain id: ' + str(subId)) # end if - if (subId < 0): - ret = inwx_conn.nameserver.createRecord({'domain': domain, 'name': sub, 'type': args.record_type, 'content': str(args.content), 'ttl': args.ttl}) + if (args.delete): + if (subId < 0): + raise RuntimeError("Can not delete unexisting entry.") + else: + if (verbose): + print ("delete id: " + str(subId)) + # end if + ret = inwx_conn.nameserver.deleteRecord({'id': subId}) + # end if else: - ret = inwx_conn.nameserver.updateRecord({'id': subId, 'type': args.record_type, 'content': str(args.content), 'ttl': args.ttl}) + if (subId < 0): + ret = inwx_conn.nameserver.createRecord({'domain': domain, 'name': sub, 'type': args.record_type, 'content': str(args.content), 'ttl': args.ttl}) + else: + ret = inwx_conn.nameserver.updateRecord({'id': subId, 'type': args.record_type, 'content': str(args.content), 'ttl': args.ttl}) + # end if # end if if (verbose): @@ -82,8 +93,9 @@ parser = argparse.ArgumentParser(description='inwx subdomain update') parser.add_argument('domain', metavar='domain', help='full domain like subdomain.example.com') - parser.add_argument('content', metavar='content', help='ip or string to fill into sub domain entry') + parser.add_argument('content', metavar='content', nargs='?', default=None, help='ip or string to fill into sub domain entry') parser.add_argument('-r', '--record-type', metavar='type', required=True, choices=['A', 'AAAA', 'TXT', 'CNAME'], help='record type (A, AAAA, TXT, CNAME)') + parser.add_argument('--delete', action='store_true', required=False, help='delete existing record') parser.add_argument('-c', '--config_file', metavar='path', default='./conf.cfg', help='path to configuration file') parser.add_argument('-t', '--ttl', default=3600, type=int, help='TTL (time to live) of the nameserver record in seconds (default 3600)') @@ -94,6 +106,12 @@ args = parser.parse_args() + + # check if content is needed + if (not args.delete and not args.content): + raise ValueError("Missing content for domain entry.") + # end if + if (args.debug): main(args) else: