2019-11-30 01:05:20 -05:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
2019-11-11 21:42:58 -05:00
|
|
|
class Network(object):
|
|
|
|
def __init__(self, network_xml):
|
|
|
|
self.xml = network_xml
|
2019-11-30 01:05:20 -05:00
|
|
|
self.hostname = self.xml.attrib['hostname'].strip()
|
|
|
|
self.provider = self.xml.attrib.get('provider', 'systemd').strip()
|
2019-11-11 21:42:58 -05:00
|
|
|
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)
|
2019-11-30 01:05:20 -05:00
|
|
|
|
|
|
|
def apply(self, chroot_base):
|
|
|
|
cfg = os.path.join(chroot_base, 'etc', 'hostname')
|
|
|
|
with open(cfg, 'w') as fh:
|
|
|
|
fh.write('{0}\n'.format(self.hostname))
|
|
|
|
os.chown(cfg, 0, 0)
|
|
|
|
os.chmod(cfg, 0o0644)
|
|
|
|
# TODO: symlinks for systemd for provider
|
|
|
|
# TODO: writeConf for provider
|
|
|
|
|
|
|
|
return()
|