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()
|
2019-11-30 01:22:28 -05:00
|
|
|
self.provider = self.xml.attrib.get('provider', 'networkd').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-30 01:22:28 -05:00
|
|
|
elif self.provider == 'networkd':
|
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)
|
2019-12-02 22:06:27 -05:00
|
|
|
for iface in self.connections:
|
|
|
|
for src, dest in iface.services.items():
|
|
|
|
realdest = os.path.join(chroot_base, dest)
|
|
|
|
os.symlink(src, realdest)
|
|
|
|
iface.writeConf(chroot_base)
|
2019-11-30 01:05:20 -05:00
|
|
|
return()
|