2019-11-11 21:42:58 -05:00
|
|
|
class Network(object):
|
|
|
|
def __init__(self, network_xml):
|
|
|
|
self.xml = network_xml
|
|
|
|
self.hostname = self.xml.attrib['hostname']
|
|
|
|
self.provider = self.xml.attrib.get('provider', 'netctl')
|
|
|
|
handler = None
|
|
|
|
if self.provider == 'netctl':
|
2019-11-12 01:27:48 -05:00
|
|
|
import aif.network.netctl as handler
|
2019-11-11 21:42:58 -05:00
|
|
|
elif self.provider == 'nm':
|
2019-11-12 01:27:48 -05:00
|
|
|
import aif.network.networkmanager as handler
|
2019-11-11 21:42:58 -05:00
|
|
|
elif self.provider == 'systemd':
|
2019-11-12 01:27:48 -05:00
|
|
|
import aif.network.networkd as handler
|
2019-11-11 21:42:58 -05:00
|
|
|
self.provider = handler
|
|
|
|
if not self.provider:
|
|
|
|
raise RuntimeError('Could not determine handler')
|
|
|
|
self.connections = []
|
2019-11-25 05:05:51 -05:00
|
|
|
self._initConns()
|
2019-11-11 21:42:58 -05:00
|
|
|
|
|
|
|
def _initConns(self):
|
2019-11-12 01:27:48 -05:00
|
|
|
for e in self.xml.xpath('ethernet|wireless'):
|
2019-11-25 05:05:51 -05:00
|
|
|
conn = None
|
2019-11-12 01:27:48 -05:00
|
|
|
if e.tag == 'ethernet':
|
|
|
|
conn = self.provider.Ethernet(e)
|
|
|
|
elif e.tag == 'wireless':
|
|
|
|
conn = self.provider.Wireless(e)
|
|
|
|
self.connections.append(conn)
|