diff --git a/aif.xsd b/aif.xsd index 2024912..d8be9dc 100644 --- a/aif.xsd +++ b/aif.xsd @@ -219,25 +219,35 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -749,11 +759,7 @@ - - - - - + diff --git a/aif/network/net.py b/aif/network/net.py index cadfe6f..42fbe03 100644 --- a/aif/network/net.py +++ b/aif/network/net.py @@ -5,15 +5,20 @@ class Network(object): self.provider = self.xml.attrib.get('provider', 'netctl') handler = None if self.provider == 'netctl': - from . import netctl as handler + import aif.network.netctl as handler elif self.provider == 'nm': - from . import networkmanager as handler + import aif.network.networkmanager as handler elif self.provider == 'systemd': - from . import networkd as handler + import aif.network.networkd as handler self.provider = handler if not self.provider: raise RuntimeError('Could not determine handler') self.connections = [] def _initConns(self): - pass + for e in self.xml.xpath('ethernet|wireless'): + if e.tag == 'ethernet': + conn = self.provider.Ethernet(e) + elif e.tag == 'wireless': + conn = self.provider.Wireless(e) + self.connections.append(conn) diff --git a/aif/network/networkmanager.py b/aif/network/networkmanager.py index 23a8350..5d3e70b 100644 --- a/aif/network/networkmanager.py +++ b/aif/network/networkmanager.py @@ -1,3 +1,5 @@ +import ipaddress +## from . import _common _NM = _common.NM @@ -9,6 +11,36 @@ class Connection(object): self.connection_type = None self.provider_type = 'NetworkManager' self.client = _NM.Client.new() + self.addrs = {'ipv4': [], + 'ipv6': []} + self.resolvers = [] + self._initAddrs() + self._initResolvers() + + def _initAddrs(self): + for t in ('ipv4', 'ipv6'): + for a in self.xml.findall('addresses/{0}/address'.format(t)): + if a.text in ('dhcp', 'dhcp6', 'slaac'): + addr = net = None + else: + components = a.text.split('/') + if len(components) > 2: + raise ValueError('Invalid IP/CIDR format: {0}'.format(a.text)) + if len(components) == 1: + addr = components[0] + if t == 'ipv4': + components.append('24') + elif t == 'ipv6': + components.append('64') + addr = ipaddress.ip_address(components[0]) + net = ipaddress.ip_network('/'.join(components), strict = False) + self.addrs[t].append((addr, net)) + return() + + def _initResolvers(self): + for r in self.xml.findall('resolvers/resolver'): + self.resolvers.append(ipaddress.ip_address(r.text)) + return() class Ethernet(Connection): diff --git a/examples/aif.xml b/examples/aif.xml index d8e9a52..f7cb16f 100644 --- a/examples/aif.xml +++ b/examples/aif.xml @@ -124,6 +124,7 @@
dhcp
+
192.168.1.5/24
slaac
@@ -135,6 +136,11 @@ + + +
dhcp
+
+
wpa2 personal