Move libvirt XML network device to jinja
This commit is contained in:
		
							parent
							
								
									ba20254888
								
							
						
					
					
						commit
						677a3e51f4
					
				| @ -271,27 +271,6 @@ class BaseVM(qubes.PropertyHolder): | |||||||
|     # xml serialising methods |     # 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): |     def create_config_file(self, file_path=None, prepare_dvm=False): | ||||||
|         '''Create libvirt's XML domain config file |         '''Create libvirt's XML domain config file | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -26,7 +26,6 @@ | |||||||
| 
 | 
 | ||||||
| import re | import re | ||||||
| 
 | 
 | ||||||
| import lxml.etree |  | ||||||
| import libvirt | import libvirt | ||||||
| 
 | 
 | ||||||
| import qubes | import qubes | ||||||
| @ -204,7 +203,6 @@ class NetVMMixin(qubes.events.Emitter): | |||||||
|                     pass |                     pass | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     # TODO maybe this should be other way: backend.devices['net'].attach(self) |  | ||||||
|     def attach_network(self): |     def attach_network(self): | ||||||
|         '''Attach network in this machine to it's netvm.''' |         '''Attach network in this machine to it's netvm.''' | ||||||
| 
 | 
 | ||||||
| @ -217,8 +215,8 @@ class NetVMMixin(qubes.events.Emitter): | |||||||
|             self.netvm.start() |             self.netvm.start() | ||||||
| 
 | 
 | ||||||
|         self.libvirt_domain.attachDevice( |         self.libvirt_domain.attachDevice( | ||||||
|             lxml.etree.tostring(lxml.etree.ElementTree( |             self.app.env.get_template('libvirt/devices/net.xml').render( | ||||||
|                 self.lvxml_net_dev(self.ip, self.mac, self.netvm)))) |                 vm=self)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     def detach_network(self): |     def detach_network(self): | ||||||
| @ -228,9 +226,9 @@ class NetVMMixin(qubes.events.Emitter): | |||||||
|             raise qubes.exc.QubesVMNotRunningError(self) |             raise qubes.exc.QubesVMNotRunningError(self) | ||||||
|         assert self.netvm is not None |         assert self.netvm is not None | ||||||
| 
 | 
 | ||||||
|         self.libvirt_domain.detachDevice( |         self.libvirt_domain.attachDevice( | ||||||
|             lxml.etree.tostring(lxml.etree.ElementTree( |             self.app.env.get_template('libvirt/devices/net.xml').render( | ||||||
|                 self.lvxml_net_dev(self.ip, self.mac, self.netvm)))) |                 vm=self)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     def is_networked(self): |     def is_networked(self): | ||||||
|  | |||||||
| @ -339,6 +339,7 @@ fi | |||||||
| %attr(2770,root,qubes) %dir /var/lib/qubes/vm-kernels | %attr(2770,root,qubes) %dir /var/lib/qubes/vm-kernels | ||||||
| /usr/share/qubes/templates/libvirt/xen.xml | /usr/share/qubes/templates/libvirt/xen.xml | ||||||
| /usr/share/qubes/templates/libvirt/devices/pci.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/tmpfiles.d/qubes.conf | ||||||
| /usr/lib/qubes/qubes-prepare-saved-domain.sh | /usr/lib/qubes/qubes-prepare-saved-domain.sh | ||||||
| /usr/lib/qubes/qubes-update-dispvm-savefile-with-progress.sh | /usr/lib/qubes/qubes-update-dispvm-savefile-with-progress.sh | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								templates/libvirt/devices/net.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								templates/libvirt/devices/net.xml
									
									
									
									
									
										Normal 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 : #} | ||||||
| @ -90,17 +90,7 @@ | |||||||
|         {% endfor %} |         {% endfor %} | ||||||
| 
 | 
 | ||||||
|         {% if vm.netvm %} |         {% if vm.netvm %} | ||||||
|             <interface type="ethernet"> |             {% include 'libvirt/devices/net.xml' %} | ||||||
|                 <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> |  | ||||||
|         {% endif %} |         {% endif %} | ||||||
| 
 | 
 | ||||||
|         {% for device in vm.devices.pci %} |         {% for device in vm.devices.pci %} | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Wojtek Porczyk
						Wojtek Porczyk