Commit 27479691 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Added possibility to have DHCP and static addresses

parent 57581457
......@@ -17,37 +17,49 @@ def get_uuid(device):
pass
def is_static(interface):
if interface._static_:
def interface_is_static(i):
if i._static_:
return True
if interface._ip_._dhcpserver_:
if i._ip_._dhcpserver_:
return True
if interface._ipv6_._dhcpserver_:
if i._ipv6_._dhcpserver_:
return True
return False
def address_is_static(a):
if interface_is_static(a._parent):
return True
if a.static[0] != None and a.static[0].lower() in [ 'yes', '1' ]:
return True
return False
def generate_ifcfgv4(tree, interface, search, nameservers):
config = []
if not is_static(interface):
if not interface_is_static(interface):
config.append('BOOTPROTO=dhcp')
pass
else:
config.append('BOOTPROTO=none')
index = ''
for ip in filter(util.address, interface._ip_):
a = util.address(ip)
netmask = None
network = None
broadcast = None
gateway = None
for s in filter(util.network, tree._subnet_ ):
n = util.network(s)
if a in n:
netmask = n.netmask
network = n.network
broadcast = n.broadcast
gateway = s.gateway[0]
pass
index = ''
for ip in filter(util.address, interface._ip_):
if not address_is_static(ip):
continue
a = util.address(ip)
netmask = None
network = None
broadcast = None
gateway = None
for s in filter(util.network, tree._subnet_ ):
n = util.network(s)
if a in n:
netmask = n.netmask
network = n.network
broadcast = n.broadcast
gateway = s.gateway[0]
if interface_is_static(interface):
if s.name_servers[0]:
nameservers.extend(re.split('[, ]+', s.name_servers[0]))
pass
......@@ -56,33 +68,33 @@ def generate_ifcfgv4(tree, interface, search, nameservers):
pass
pass
pass
if ip.netmask[0]: netmask = ip.netmask[0]
if ip.network[0]: network = ip.network[0]
if ip.broadcast[0]: broadcast = ip.broadcast[0]
if ip.gateway[0]: gateway = ip.gateway[0]
if ip.search[0]: search.update(ip.search[0].split())
config.append('IPADDR%s=%s' % (index, a))
if netmask:
config.append('NETMASK%s=%s' % (index, netmask))
pass
if gateway:
config.append('GATEWAY%s=%s' % (index, gateway))
pass
if network:
config.append('NETWORK%s=%s' % (index, network))
pass
if broadcast:
config.append('BROADCAST%s=%s' % (index, broadcast))
pass
index = int('0%s' % index)+1
pass
if ip.netmask[0]: netmask = ip.netmask[0]
if ip.network[0]: network = ip.network[0]
if ip.broadcast[0]: broadcast = ip.broadcast[0]
if ip.gateway[0]: gateway = ip.gateway[0]
if ip.search[0]: search.update(ip.search[0].split())
config.append('IPADDR%s=%s' % (index, a))
if netmask:
config.append('NETMASK%s=%s' % (index, netmask))
pass
if gateway:
config.append('GATEWAY%s=%s' % (index, gateway))
pass
if network:
config.append('NETWORK%s=%s' % (index, network))
pass
if broadcast:
config.append('BROADCAST%s=%s' % (index, broadcast))
pass
index = int('0%s' % index)+1
pass
return config
def generate_ifcfgv6(tree, interface, search, nameservers):
config = []
if not is_static(interface):
if not interface_is_static(interface):
config.append('IPV6INIT=yes')
config.append('IPV6_AUTOCONF=yes')
config.append('IPV6_DEFROUTE=yes')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment