samba-tool: dns: Add support to add/update/delete MX and SRV records
authorAmitay Isaacs <amitay@gmail.com>
Tue, 14 Feb 2012 02:41:45 +0000 (13:41 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Tue, 21 Feb 2012 07:24:30 +0000 (18:24 +1100)
source4/scripting/python/samba/netcmd/dns.py

index f1adc06faa6eaa43067a7260dbb5797d39f3e348..d260dcf93f227f5901cb9743a90f386d220ab9f8 100644 (file)
@@ -952,9 +952,19 @@ class cmd_roothints(Command):
 
 
 class cmd_add_record(Command):
-    """Add a DNS record"""
+    """Add a DNS record
 
-    synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS> <data>'
+       For each type data contents are as follows:
+         A      ipv4_address_string
+         AAAA   ipv6_address_string
+         PTR    fqdn_string
+         CNAME  fqdn_string
+         NS     fqdn_string
+         MX     "fqdn_string preference"
+         SRV    "fqdn_string port priority weight"
+    """
+
+    synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS|MX|SRV> <data>'
 
     takes_args = [ 'server', 'zone', 'name', 'rtype', 'data' ]
 
@@ -966,21 +976,12 @@ class cmd_add_record(Command):
 
     def run(self, server, zone, name, rtype, data, sambaopts=None, credopts=None, versionopts=None):
 
-        record_type = dns_type_flag(rtype)
-
-        if record_type == dnsp.DNS_TYPE_A:
-            rec = ARecord(data)
-        elif record_type == dnsp.DNS_TYPE_AAAA:
-            rec = AAAARecord(data)
-        elif record_type == dnsp.DNS_TYPE_PTR:
-            rec = PTRRecord(data)
-        elif record_type == dnsp.DNS_TYPE_CNAME:
-            rec = CNameRecord(data)
-        elif record_type == dnsp.DNS_TYPE_NS:
-            rec = NSRecord(data)
-        else:
+        if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SRV'):
             raise CommandError('Adding record of type %s is not supported' % rtype)
 
+        record_type = dns_type_flag(rtype)
+        rec = data_to_dns_record(record_type, data)
+
         self.lp = sambaopts.get_loadparm()
         self.creds = credopts.get_credentials(self.lp)
         dns_conn = dns_connect(server, self.lp, self.creds)
@@ -1003,9 +1004,19 @@ class cmd_add_record(Command):
 
 
 class cmd_update_record(Command):
-    """Update a DNS record"""
+    """Update a DNS record
+
+       For each type data contents are as follows:
+         A      ipv4_address_string
+         AAAA   ipv6_address_string
+         PTR    fqdn_string
+         CNAME  fqdn_string
+         NS     fqdn_string
+         MX     "fqdn_string preference"
+         SRV    "fqdn_string port priority weight"
+    """
 
-    synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS> <olddata> <newdata>'
+    synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS|MX|SRV> <olddata> <newdata>'
 
     takes_args = [ 'server', 'zone', 'name', 'rtype', 'olddata', 'newdata' ]
 
@@ -1018,20 +1029,12 @@ class cmd_update_record(Command):
     def run(self, server, zone, name, rtype, olddata, newdata,
                 sambaopts=None, credopts=None, versionopts=None):
 
-        record_type = dns_type_flag(rtype)
-        if record_type == dnsp.DNS_TYPE_A:
-            rec = ARecord(newdata)
-        elif record_type == dnsp.DNS_TYPE_AAAA:
-            rec = AAAARecord(newdata)
-        elif record_type == dnsp.DNS_TYPE_PTR:
-            rec = PTRRecord(newdata)
-        elif record_type == dnsp.DNS_TYPE_CNAME:
-            rec = CNameRecord(newdata)
-        elif record_type == dnsp.DNS_TYPE_NS:
-            rec = NSRecord(newdata)
-        else:
+        if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SRV'):
             raise CommandError('Updating record of type %s is not supported' % rtype)
 
+        record_type = dns_type_flag(rtype)
+        rec = data_to_dns_record(record_type, newdata)
+
         self.lp = sambaopts.get_loadparm()
         self.creds = credopts.get_credentials(self.lp)
         dns_conn = dns_connect(server, self.lp, self.creds)
@@ -1063,9 +1066,19 @@ class cmd_update_record(Command):
 
 
 class cmd_delete_record(Command):
-    """Delete a DNS record"""
+    """Delete a DNS record
+
+       For each type data contents are as follows:
+         A      ipv4_address_string
+         AAAA   ipv6_address_string
+         PTR    fqdn_string
+         CNAME  fqdn_string
+         NS     fqdn_string
+         MX     "fqdn_string preference"
+         SRV    "fqdn_string port priority weight"
+    """
 
-    synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS> <data>'
+    synopsis = '%prog <server> <zone> <name> <A|AAAA|PTR|CNAME|NS|MX|SRV> <data>'
 
     takes_args = [ 'server', 'zone', 'name', 'rtype', 'data' ]
 
@@ -1077,21 +1090,11 @@ class cmd_delete_record(Command):
 
     def run(self, server, zone, name, rtype, data, sambaopts=None, credopts=None, versionopts=None):
 
-        record_type = dns_type_flag(rtype)
-
-        if record_type == dnsp.DNS_TYPE_A:
-            rec = ARecord(data)
-        elif record_type == dnsp.DNS_TYPE_AAAA:
-            rec = AAAARecord(data)
-        elif record_type == dnsp.DNS_TYPE_PTR:
-            rec = PTRRecord(data)
-        elif record_type == dnsp.DNS_TYPE_CNAME:
-            rec = CNameRecord(data)
-        elif record_type == dnsp.DNS_TYPE_NS:
-            rec = NSRecord(data)
-        else:
+        if rtype.upper() not in ('A','AAAA','PTR','CNAME','NS','MX','SRV'):
             raise CommandError('Deleting record of type %s is not supported' % rtype)
 
+        record_type = dns_type_flag(rtype)
+
         self.lp = sambaopts.get_loadparm()
         self.creds = credopts.get_credentials(self.lp)
         dns_conn = dns_connect(server, self.lp, self.creds)