Move libvirt XML network device to jinja

This commit is contained in:
Wojtek Porczyk 2016-06-15 19:41:11 +02:00
parent ba20254888
commit 677a3e51f4
5 changed files with 20 additions and 39 deletions

View File

@ -271,27 +271,6 @@ class BaseVM(qubes.PropertyHolder):
# xml serialising methods
#
@staticmethod
def lvxml_net_dev(ip, mac, backend):
'''Return ``<interface>`` 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

View File

@ -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):

View File

@ -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

View File

@ -0,0 +1,13 @@
<interface type="ethernet">
<mac address="{{ vm.mac }}" />
<ip address="
{%- if prepare_dvm -%}
%IP%
{%- else -%}
{{ vm.ip }}
{%- endif %}" />
<backenddomain name="{{ vm.netvm.name }}" />
<script path="vif-route-qubes"></script>
</interface>
{# vim : set ft=jinja ts=4 sts=4 sw=4 et : #}

View File

@ -90,17 +90,7 @@
{% endfor %}
{% if vm.netvm %}
<interface type="ethernet">
<mac address="{{ vm.mac }}" />
<ip address="
{%- if prepare_dvm -%}
%IP%
{%- else -%}
{{ vm.ip }}
{%- endif %}" />
<backenddomain name="{{ vm.netvm.name }}" />
<script path="vif-route-qubes"></script>
</interface>
{% include 'libvirt/devices/net.xml' %}
{% endif %}
{% for device in vm.devices.pci %}