aif-ng/aif/network/net.py

27 lines
1003 B
Python
Raw Normal View History

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':
import aif.network.netctl as handler
2019-11-11 21:42:58 -05:00
elif self.provider == 'nm':
import aif.network.networkmanager as handler
2019-11-11 21:42:58 -05:00
elif self.provider == 'systemd':
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 = []
self._initConns()
2019-11-11 21:42:58 -05:00
def _initConns(self):
for e in self.xml.xpath('ethernet|wireless'):
conn = None
if e.tag == 'ethernet':
conn = self.provider.Ethernet(e)
elif e.tag == 'wireless':
conn = self.provider.Wireless(e)
self.connections.append(conn)