diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index 20ce7456..d75d7c03 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -271,27 +271,6 @@ class BaseVM(qubes.PropertyHolder): # xml serialising methods # - @staticmethod - def lvxml_net_dev(ip, mac, backend): - '''Return ```` node for libvirt xml. - - This was previously _format_net_dev - - :param str ip: IP address of the frontend - :param str mac: MAC (Ethernet) address of the frontend - :param qubes.vm.qubesvm.QubesVM backend: Backend domain - :rtype: lxml.etree._Element - ''' - - interface = lxml.etree.Element('interface', type='ethernet') - interface.append(lxml.etree.Element('mac', address=mac)) - interface.append(lxml.etree.Element('ip', address=ip)) - interface.append(lxml.etree.Element('backenddomain', name=backend.name)) - interface.append(lxml.etree.Element('script', path="vif-route-qubes")) - - return interface - - def create_config_file(self, file_path=None, prepare_dvm=False): '''Create libvirt's XML domain config file diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py index b3b08c66..c537b464 100644 --- a/qubes/vm/mix/net.py +++ b/qubes/vm/mix/net.py @@ -26,7 +26,6 @@ import re -import lxml.etree import libvirt import qubes @@ -204,7 +203,6 @@ class NetVMMixin(qubes.events.Emitter): pass - # TODO maybe this should be other way: backend.devices['net'].attach(self) def attach_network(self): '''Attach network in this machine to it's netvm.''' @@ -217,8 +215,8 @@ class NetVMMixin(qubes.events.Emitter): self.netvm.start() self.libvirt_domain.attachDevice( - lxml.etree.tostring(lxml.etree.ElementTree( - self.lvxml_net_dev(self.ip, self.mac, self.netvm)))) + self.app.env.get_template('libvirt/devices/net.xml').render( + vm=self)) def detach_network(self): @@ -228,9 +226,9 @@ class NetVMMixin(qubes.events.Emitter): raise qubes.exc.QubesVMNotRunningError(self) assert self.netvm is not None - self.libvirt_domain.detachDevice( - lxml.etree.tostring(lxml.etree.ElementTree( - self.lvxml_net_dev(self.ip, self.mac, self.netvm)))) + self.libvirt_domain.attachDevice( + self.app.env.get_template('libvirt/devices/net.xml').render( + vm=self)) def is_networked(self): diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 18e5e7ef..bc4a6ef8 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -339,6 +339,7 @@ fi %attr(2770,root,qubes) %dir /var/lib/qubes/vm-kernels /usr/share/qubes/templates/libvirt/xen.xml /usr/share/qubes/templates/libvirt/devices/pci.xml +/usr/share/qubes/templates/libvirt/devices/net.xml /usr/lib/tmpfiles.d/qubes.conf /usr/lib/qubes/qubes-prepare-saved-domain.sh /usr/lib/qubes/qubes-update-dispvm-savefile-with-progress.sh diff --git a/templates/libvirt/devices/net.xml b/templates/libvirt/devices/net.xml new file mode 100644 index 00000000..dd51f714 --- /dev/null +++ b/templates/libvirt/devices/net.xml @@ -0,0 +1,13 @@ + + + + + + + +{# vim : set ft=jinja ts=4 sts=4 sw=4 et : #} diff --git a/templates/libvirt/xen.xml b/templates/libvirt/xen.xml index dfdffa09..9547e93b 100644 --- a/templates/libvirt/xen.xml +++ b/templates/libvirt/xen.xml @@ -90,17 +90,7 @@ {% endfor %} {% if vm.netvm %} - - - - - - + {% include 'libvirt/devices/net.xml' %} {% endif %} {% for device in vm.devices.pci %}