xen.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <domain type="xen">
  2. {% block basic %}
  3. <name>{{ vm.name }}</name>
  4. <uuid>{{ vm.uuid }}</uuid>
  5. {% if ((vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list)
  6. or vm.maxmem == 0) -%}
  7. <memory unit="MiB">{{ vm.memory }}</memory>
  8. {% else -%}
  9. <memory unit="MiB">{{ vm.maxmem }}</memory>
  10. {% endif -%}
  11. <currentMemory unit="MiB">{{ vm.memory }}</currentMemory>
  12. <vcpu placement="static">{{ vm.vcpus }}</vcpu>
  13. {% endblock %}
  14. {% block cpu %}
  15. {% if vm.virt_mode != 'pv' %}
  16. <cpu mode='host-passthrough'>
  17. <!-- disable nested HVM -->
  18. <feature name='vmx' policy='disable'/>
  19. <feature name='svm' policy='disable'/>
  20. <!-- disable SMAP inside VM, because of Linux bug -->
  21. <feature name='smap' policy='disable'/>
  22. </cpu>
  23. {% endif %}
  24. {% endblock %}
  25. <os>
  26. {% block os %}
  27. {% if vm.virt_mode == 'hvm' %}
  28. <type arch="x86_64" machine="xenfv">hvm</type>
  29. <!--
  30. For the libxl backend libvirt switches between OVMF (UEFI)
  31. and SeaBIOS based on the loader type. This has nothing to
  32. do with the hvmloader binary.
  33. -->
  34. <loader type="{{ "pflash" if vm.features.check_with_template('uefi', False) else "rom" }}">hvmloader</loader>
  35. <boot dev="cdrom" />
  36. <boot dev="hd" />
  37. {% else %}
  38. {% if vm.virt_mode == 'pvh' %}
  39. <type arch="x86_64" machine="xenpvh">xenpvh</type>
  40. {% else %}
  41. <type arch="x86_64" machine="xenpv">linux</type>
  42. {% endif %}
  43. <kernel>{{ vm.storage.kernels_dir }}/vmlinuz</kernel>
  44. <initrd>{{ vm.storage.kernels_dir }}/initramfs</initrd>
  45. {% endif %}
  46. {% if vm.kernel %}
  47. {% if vm.features.check_with_template('no-default-kernelopts', False) -%}
  48. <cmdline>{{ vm.kernelopts }}</cmdline>
  49. {% else -%}
  50. <cmdline>{{ vm.kernelopts_common }}{{ vm.kernelopts }}</cmdline>
  51. {% endif -%}
  52. {% endif %}
  53. {% endblock %}
  54. </os>
  55. <features>
  56. {% block features %}
  57. {% if vm.virt_mode != 'pv' %}
  58. <pae/>
  59. <acpi/>
  60. <apic/>
  61. <viridian/>
  62. {% endif %}
  63. {% if vm.devices['pci'].persistent() | list
  64. and vm.features.get('pci-e820-host', True) %}
  65. <xen>
  66. <e820_host state="on"/>
  67. </xen>
  68. {% endif %}
  69. {% endblock %}
  70. </features>
  71. {% block clock %}
  72. {% if vm.virt_mode == 'hvm' %}
  73. {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
  74. {% if timezone == 'localtime' %}
  75. <clock offset="variable" adjustment="0" basis="localtime" />
  76. {% elif timezone.isdigit() %}
  77. <clock offset="variable" adjustment="{{ timezone }}" basis="utc" />
  78. {% else %}
  79. <clock offset="variable" adjustment="0" basis="utc" />
  80. {% endif %}
  81. {% else %}
  82. <clock offset='utc' adjustment='reset'>
  83. <timer name="tsc" mode="native"/>
  84. </clock>
  85. {% endif %}
  86. {% endblock %}
  87. {% block on %}
  88. <on_poweroff>destroy</on_poweroff>
  89. <on_reboot>destroy</on_reboot>
  90. <on_crash>destroy</on_crash>
  91. {% endblock %}
  92. <devices>
  93. {% block devices %}
  94. {#
  95. HACK: The letter counter is implemented in this way because
  96. Jinja does not allow you to increment variables in a loop
  97. anymore. As of Jinja 2.10, we will be able to replace this
  98. with:
  99. {% set counter = namespace(i=0) %}
  100. {% set counter.i = counter.i + 1 %}
  101. #}
  102. {% set counter = {'i': 0} %}
  103. {# TODO Allow more volumes out of the box #}
  104. {% set dd = ['e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  105. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y']
  106. %}
  107. {% for device in vm.block_devices %}
  108. <disk type="block" device="{{ device.devtype }}">
  109. <driver name="phy" />
  110. <source dev="{{ device.path }}" />
  111. {% if device.name == 'root' %}
  112. <target dev="xvda" />
  113. {% elif device.name == 'private' %}
  114. <target dev="xvdb" />
  115. {% elif device.name == 'volatile' %}
  116. <target dev="xvdc" />
  117. {% elif device.name == 'kernel' %}
  118. <target dev="xvdd" />
  119. {% else %}
  120. <target dev="xvd{{dd[counter.i]}}" />
  121. {% if counter.update({'i': counter.i + 1}) %}{% endif %}
  122. {% endif %}
  123. {% if not device.rw %}
  124. <readonly />
  125. {% endif %}
  126. {% if device.domain %}
  127. <backenddomain name="{{ device.domain }}" />
  128. {% endif %}
  129. {% if device.script %}
  130. <script path="{{ device.script }}" />
  131. {% endif %}
  132. </disk>
  133. {% endfor %}
  134. {# start external devices from xvdi #}
  135. {% set counter = {'i': 4} %}
  136. {% for assignment in vm.devices.block.assignments(True) %}
  137. {% set device = assignment.device %}
  138. {% set options = assignment.options %}
  139. {% include 'libvirt/devices/block.xml' %}
  140. {% endfor %}
  141. {% if vm.netvm %}
  142. {% include 'libvirt/devices/net.xml' with context %}
  143. {% endif %}
  144. {% for assignment in vm.devices.pci.assignments(True) %}
  145. {% set device = assignment.device %}
  146. {% set options = assignment.options %}
  147. {% include 'libvirt/devices/pci.xml' %}
  148. {% endfor %}
  149. {% if vm.virt_mode == 'hvm' %}
  150. <!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
  151. <emulator
  152. {% if vm.features.check_with_template('linux-stubdom', True) %}
  153. type="stubdom-linux"
  154. {% else %}
  155. type="stubdom"
  156. {% endif %}
  157. {% if vm.netvm %}
  158. {% if vm.features.check_with_template('linux-stubdom', True) %}
  159. cmdline="-qubes-net:client_ip={{ vm.ip -}}
  160. ,dns_0={{ vm.dns[0] -}}
  161. ,dns_1={{ vm.dns[1] -}}
  162. ,gw={{ vm.netvm.gateway -}}
  163. ,netmask={{ vm.netmask }}"
  164. {% else %}
  165. cmdline="-net lwip,client_ip={{ vm.ip -}}
  166. ,server_ip={{ vm.dns[1] -}}
  167. ,dns={{ vm.dns[0] -}}
  168. ,gw={{ vm.netvm.gateway -}}
  169. ,netmask={{ vm.netmask }}"
  170. {% endif %}
  171. {% endif %}
  172. {% if vm.stubdom_mem %}
  173. memory="{{ vm.stubdom_mem * 1024 -}}"
  174. {% endif %}
  175. />
  176. <input type="tablet" bus="usb"/>
  177. <video>
  178. <model type="{{ vm.features.check_with_template('video-model', 'vga') }}"/>
  179. </video>
  180. {% if vm.features.check_with_template('linux-stubdom', True) %}
  181. {# TODO only add qubes gui if gui-agent is not installed in HVM #}
  182. <graphics type="qubes"/>
  183. {% endif %}
  184. {% endif %}
  185. <console type="pty">
  186. <target type="xen" port="0"/>
  187. </console>
  188. {% endblock %}
  189. </devices>
  190. </domain>
  191. <!-- vim: set ft=jinja ts=4 sts=4 sw=4 et tw=80 : -->