Permalink
Browse files

First implementation of CNAMEs support working!

Preliminarily tested on the test bench, haven't tested on production system.
  • Loading branch information...
1 parent 16280b4 commit 25d0f7c924037b961c14fd5993d2848ec91b7a88 @bytecar bytecar committed Dec 19, 2012
Showing with 38 additions and 4 deletions.
  1. +1 −0 cobbler/field_info.py
  2. +11 −2 cobbler/item_system.py
  3. +24 −2 cobbler/modules/manage_bind.py
  4. +2 −0 templates/etc/zone.template
View
@@ -134,6 +134,7 @@
"*bridge_opts" : "Networking",
"*management" : "Networking",
"*dns_name" : "Networking",
+ "cname" : "Networking",
"*static_routes" : "Networking",
"*netmask" : "Networking",
"*ipv6_address" : "Networking",
View
@@ -101,6 +101,7 @@
["ldap_enabled",False,0,"LDAP Enabled",True,"(re)configure LDAP on this machine at next config update?",0,"bool"],
["ldap_type","SETTINGS:ldap_management_default_type",0,"LDAP Management Type",True,"Ex: authconfig",0,"str"],
["monit_enabled",False,0,"Monit Enabled",True,"(re)configure monit on this machine at next config update?",0,"bool"],
+ ["*cnames",[],0,"CNAMES",True,"Cannonical Name Records, should be used with --interface, In quotes, space delimited",0,"list"],
]
class System(item.Item):
@@ -162,6 +163,7 @@ def __get_interface(self,name):
"ipv6_mtu" : "",
"ipv6_static_routes" : [],
"ipv6_default_gateway" : "",
+ "cnames" : [],
}
return self.interfaces[name]
@@ -245,7 +247,7 @@ def get_mac_address(self,interface):
return intf["mac_address"].strip()
else:
return None
-
+
def get_ip_address(self,interface):
"""
Get the IP address, which may be implicit in the object name or explict with --ip-address.
@@ -292,11 +294,17 @@ def set_dns_name(self,dns_name,interface):
for x in matched:
if x.name != self.name:
raise CX("dns-name duplicated: %s" % dns_name)
-
+
intf["dns_name"] = dns_name
return True
+ def set_cnames(self,cnames,interface):
+ intf = self.__get_interface(interface)
+ data = utils.input_string_or_list(cnames)
+ intf["cnames"] = data
+ return True
+
def set_static_routes(self,routes,interface):
intf = self.__get_interface(interface)
data = utils.input_string_or_list(routes)
@@ -677,6 +685,7 @@ def modify_interface(self, hash):
if field == "ipv6mtu" : self.set_ipv6_mtu(value, interface)
if field == "ipv6staticroutes" : self.set_ipv6_static_routes(value, interface)
if field == "ipv6defaultgateway" : self.set_ipv6_default_gateway(value, interface)
+ if field == "cnames" : self.set_cnames(value, interface)
return True
@@ -306,6 +306,21 @@ def __pretty_print_host_records(self, hosts, rectype='A', rclass='IN'):
my_host = hosts[name]
s += "%s %s %s %s;\n" % (my_name, rclass, rectype, my_host)
return s
+
+ def __pretty_print_cname_records(self, hosts, rectype='CNAME'):
+ """
+ Format CNAMEs and with consistent indentation
+ """
+ s = ""
+
+ for system in self.systems:
+ for (name, interface) in system.interfaces.iteritems():
+ cnames = interface["cnames"]
+ dnsname = interface["dns_name"].split('.')[0]
+ for cname in cnames:
+ s += "%s %s %s;\n" % (cname.split('.')[0], rectype, dnsname)
@moensch

moensch Oct 8, 2013

I noticed that manage_bind automatically forces CNAMEs to be in the same domain. However, CNAMEs can point to a host in any other domain, and I have a requirement to use them this way.
I am aware that this introduces additional complexity as this makes CNAME records "arbitrary" records and may not necessarily be associated with a known system anymore.
For now, I will manually add them to my zone template.

+ return s
+
def __write_zone_files(self):
"""
@@ -352,7 +367,9 @@ def __write_zone_files(self):
'cobbler_server': cobbler_server,
'serial': serial,
'zonetype': 'forward',
+ 'cname_record': '',
'host_record': ''
+
}
# grab zone-specific template if it exists
@@ -363,8 +380,10 @@ def __write_zone_files(self):
except:
template_data = default_template_data
+ metadata['cname_record'] = self.__pretty_print_cname_records(hosts)
metadata['host_record'] = self.__pretty_print_host_records(hosts)
-
+
+
zonefilename=zonefileprefix + zone
if self.logger is not None:
self.logger.info("generating (forward) %s" % zonefilename)
@@ -375,6 +394,7 @@ def __write_zone_files(self):
'cobbler_server': cobbler_server,
'serial': serial,
'zonetype': 'reverse',
+ 'cname_record': '',
'host_record': ''
}
@@ -386,8 +406,10 @@ def __write_zone_files(self):
except:
template_data = default_template_data
+ metadata['cname_record'] = self.__pretty_print_cname_records(hosts)
metadata['host_record'] = self.__pretty_print_host_records(hosts, rectype='PTR')
-
+
+
zonefilename=zonefileprefix + zone
if self.logger is not None:
self.logger.info("generating (reverse) %s" % zonefilename)
@@ -10,4 +10,6 @@
IN NS $cobbler_server.
+$cname_record
+
$host_record

0 comments on commit 25d0f7c

Please sign in to comment.