minor changes to xml, small additions to network
This commit is contained in:
parent
5371ae2361
commit
8ee5137059
54
aif.xsd
54
aif.xsd
@ -219,25 +219,35 @@
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="addresses" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element name="ipv4">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="address" type="aif:t_address_ip4"
|
||||
minOccurs="1" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="gateway" type="aif:t_address_ip4" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="ipv6">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="address" type="aif:t_address_ip6"
|
||||
minOccurs="1" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="gateway" type="aif:t_address_ip6" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:sequence>
|
||||
<xs:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element name="ipv4">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="address" type="aif:t_address_ip4"
|
||||
minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="gateway" type="aif:t_address_ip4" use="optional"/>
|
||||
</xs:complexType>
|
||||
<xs:unique name="uniq_ipv4_addr">
|
||||
<xs:selector xpath="aif:address"/>
|
||||
<xs:field xpath="."/>
|
||||
</xs:unique>
|
||||
</xs:element>
|
||||
<xs:element name="ipv6">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="address" type="aif:t_address_ip6"
|
||||
minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="gateway" type="aif:t_address_ip6" use="optional"/>
|
||||
</xs:complexType>
|
||||
<xs:unique name="uniq_ipv6_addr">
|
||||
<xs:selector xpath="aif:address"/>
|
||||
<xs:field xpath="."/>
|
||||
</xs:unique>
|
||||
</xs:element>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
@ -749,11 +759,7 @@
|
||||
<xs:attribute name="provider" type="aif:t_netprov" use="optional" default="netctl"/>
|
||||
</xs:complexType>
|
||||
<xs:unique name="uniq_iface_eth">
|
||||
<xs:selector xpath="aif:ethernet"/>
|
||||
<xs:field xpath="@device"/>
|
||||
</xs:unique>
|
||||
<xs:unique name="uniq_iface_wlan">
|
||||
<xs:selector xpath="aif:wireless"/>
|
||||
<xs:selector xpath="aif:ethernet|aif:wireless"/>
|
||||
<xs:field xpath="@device"/>
|
||||
</xs:unique>
|
||||
</xs:element>
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -124,6 +124,7 @@
|
||||
<addresses>
|
||||
<ipv4>
|
||||
<address>dhcp</address>
|
||||
<address>192.168.1.5/24</address>
|
||||
</ipv4>
|
||||
<ipv6>
|
||||
<address>slaac</address>
|
||||
@ -135,6 +136,11 @@
|
||||
</resolvers>
|
||||
</ethernet>
|
||||
<wireless device="wlp2s0" essid="MyWirelessLan" bssid="00-00-5E-00-53-00" defroute="false">
|
||||
<addresses>
|
||||
<ipv4>
|
||||
<address>dhcp</address>
|
||||
</ipv4>
|
||||
</addresses>
|
||||
<encryption>
|
||||
<type>wpa2</type>
|
||||
<mode>personal</mode>
|
||||
|
Loading…
Reference in New Issue
Block a user