/
libvirt.xsl
293 lines (282 loc) · 13.8 KB
/
libvirt.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?xml version="1.0" encoding="UTF-8"?>
<!--
This XSL-T file is used to construct two types of XML documents:
- one that libvirt can use to launch a Eucalyptus instance (the
job formerly performed by gen_*libvirt_xml Perl scripts). As input
it assumes an XML document produced the the Node Controller
that describes a Eucalyptus instance to be launched.
- one that libvirt can use to attach a disk to an instance
-->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:template match="/instance">
<!-- sanity check on the hypervisor type - we only know 'kvm' and 'xen' -->
<xsl:if test="/instance/hypervisor/@type != 'kvm' and /instance/hypervisor/@type != 'xen'">
<xsl:message terminate="yes">ERROR: invalid or unset /instance/hypervisor/@type parameter</xsl:message>
</xsl:if>
<domain>
<xsl:attribute name="type">
<xsl:value-of select="/instance/hypervisor/@type"/>
</xsl:attribute>
<name>
<xsl:value-of select="/instance/name"/>
</name>
<description>Eucalyptus instance <xsl:value-of select="/instance/name"/></description>
<os>
<xsl:choose>
<xsl:when test="/instance/os/@platform = 'linux' and /instance/backing/root/@type = 'image'">
<!-- for Linux image-store-based instances -->
<xsl:if test="/instance/hypervisor/@type = 'xen'">
<type>linux</type>
</xsl:if>
<xsl:if test="/instance/hypervisor/@type = 'kvm'">
<type>hvm</type>
</xsl:if>
<xsl:if test="/instance/ramdisk!=''">
<initrd>
<xsl:value-of select="/instance/ramdisk"/>
</initrd>
</xsl:if>
<xsl:if test="/instance/kernel!=''">
<kernel>
<xsl:value-of select="/instance/kernel"/>
</kernel>
</xsl:if>
<xsl:choose>
<xsl:when test="/instance/hypervisor/@type = 'kvm' and /instance/os/@virtioRoot = 'true'">
<cmdline>root=/dev/vda1 console=ttyS0</cmdline>
<root>/dev/vda1</root>
</xsl:when>
<xsl:otherwise>
<cmdline>root=/dev/sda1 console=ttyS0</cmdline>
<root>/dev/sda1</root>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="/instance/os/@platform = 'windows' or /instance/backing/root/@type = 'ebs'">
<!-- for all Windows and EBS-backed-root Linux instances -->
<type>hvm</type>
<xsl:if test="/instance/hypervisor/@type = 'xen'">
<loader>/usr/lib/xen/boot/hvmloader</loader>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">ERROR: invalid or unset /instance/os/@platform or /instance/backing/root/@type parameter</xsl:message>
</xsl:otherwise>
</xsl:choose>
</os>
<features>
<acpi/>
<xsl:if test="/instance/hypervisor/@type = 'xen' and ( /instance/os/@platform = 'windows' or /instance/backing/root/@type = 'ebs' )">
<apic/>
<pae/>
</xsl:if>
</features>
<clock offset="localtime"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<vcpu>
<xsl:value-of select="/instance/cores"/>
</vcpu>
<memory>
<xsl:value-of select="/instance/memoryKB"/>
</memory>
<devices>
<xsl:if test="/instance/hypervisor/@type = 'xen' and ( /instance/os/@platform = 'windows' or /instance/backing/root/@type = 'ebs' )">
<xsl:choose>
<xsl:when test="/instance/hypervisor/@bitness = '32'">
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
</xsl:when>
<xsl:otherwise>
<emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!-- disks or partitions (Xen) -->
<xsl:for-each select="/instance/disks/diskPath">
<disk>
<xsl:attribute name="device">
<xsl:value-of select="@targetDeviceType"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@sourceType"/>
</xsl:attribute>
<source>
<xsl:choose>
<xsl:when test="@sourceType = 'file'">
<xsl:attribute name="file">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
<xsl:when test="@sourceType = 'block'">
<xsl:attribute name="dev">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">ERROR: invalid or unset /instance/disks/disk/@sourcetype parameter</xsl:message>
</xsl:otherwise>
</xsl:choose>
</source>
<target>
<xsl:choose>
<xsl:when test="/instance/hypervisor/@type='kvm' and /instance/os/@platform='windows'">
<xsl:attribute name="bus">virtio</xsl:attribute>
<xsl:attribute name="dev">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@targetDeviceName"/>
<xsl:with-param name="replace" select="'sd'"/>
<xsl:with-param name="by" select="'vd'"/>
</xsl:call-template>
</xsl:attribute>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type='xen' and ( /instance/os/@platform='windows' or /instance/backing/root/@type = 'ebs' )">
<xsl:attribute name="bus">xen</xsl:attribute>
<xsl:attribute name="dev">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@targetDeviceName"/>
<xsl:with-param name="replace" select="'sd'"/>
<xsl:with-param name="by" select="'xvd'"/>
</xsl:call-template>
</xsl:attribute>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'kvm' and /instance/os/@virtioRoot = 'true'">
<xsl:attribute name="bus">virtio</xsl:attribute>
<xsl:attribute name="dev">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@targetDeviceName"/>
<xsl:with-param name="replace" select="'sd'"/>
<xsl:with-param name="by" select="'vd'"/>
</xsl:call-template>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="dev">
<xsl:value-of select="@targetDeviceName"/>
</xsl:attribute>
<xsl:attribute name="bus">
<xsl:value-of select="@targetDeviceBus"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</target>
</disk>
</xsl:for-each>
<xsl:if test="/instance/disks/floppyPath != ''">
<disk type="file" device="floppy">
<source>
<xsl:attribute name="file">
<xsl:value-of select="/instance/disks/floppyPath"/>
</xsl:attribute>
</source>
<target dev="fda"/>
</disk>
</xsl:if>
<!-- network cards -->
<xsl:for-each select="/instance/nics/nic">
<interface type="bridge">
<source>
<xsl:attribute name="bridge">
<xsl:value-of select="@bridgeDeviceName"/>
</xsl:attribute>
</source>
<mac>
<xsl:attribute name="address">
<xsl:value-of select="@mac"/>
</xsl:attribute>
</mac>
<xsl:choose>
<xsl:when test="/instance/hypervisor/@type = 'kvm' and /instance/os/@platform = 'windows'">
<model type="virtio"/>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'kvm' and /instance/os/@virtioNet = 'true'">
<model type="virtio"/>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'kvm' and /instance/os/@platform = 'linux'">
<model type="e1000"/>
</xsl:when>
</xsl:choose>
<xsl:if test="/instance/hypervisor/@type = 'xen'">
<script path="/etc/xen/scripts/vif-bridge"/>
</xsl:if>
</interface>
</xsl:for-each>
<!-- console -->
<xsl:choose>
<xsl:when test="/instance/hypervisor/@type = 'kvm'">
<serial type="file">
<source>
<xsl:attribute name="path">
<xsl:value-of select="/instance/consoleLogPath"/>
</xsl:attribute>
</source>
<target port="1"/>
</serial>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'xen' and /instance/os/@platform = 'windows'">
<serial type="pty">
<source path="/dev/pts/3"/>
<target port="0"/>
</serial>
<input type="tablet" bus="usb"/>
<input type="mouse" bus="ps2"/>
</xsl:when>
<xsl:when test="/instance/hypervisor/@type = 'xen' and /instance/backing/root/@type = 'ebs'">
<console type="pty"/>
</xsl:when>
</xsl:choose>
<!-- <graphics type='vnc' port='-1' autoport='yes' keymap='en-us' listen='0.0.0.0'/> -->
</devices>
</domain>
</xsl:template>
<xsl:template match="/volume">
<disk type="block">
<driver>
<xsl:choose>
<xsl:when test="/volume/hypervisor/@type='xen'">
<xsl:attribute name="name">phy</xsl:attribute>
</xsl:when>
<xsl:when test="/volume/hypervisor/@type='kvm'">
<xsl:attribute name="name">qemu</xsl:attribute>
</xsl:when>
</xsl:choose>
</driver>
<source>
<xsl:attribute name="dev">
<xsl:value-of select="/volume/diskPath"/>
</xsl:attribute>
</source>
<target>
<xsl:attribute name="dev">
<xsl:value-of select="/volume/diskPath/@targetDeviceName"/>
</xsl:attribute>
<xsl:if test="/volume/hypervisor/@type = 'kvm'">
<xsl:if test="( /volume/os/@virtioDisk = 'true' and contains(/volume/diskPath/@targetDeviceName, 'vd') ) or /volume/os/@platform = 'windows'">
<xsl:attribute name="bus">virtio</xsl:attribute>
</xsl:if>
</xsl:if>
</target>
</disk>
</xsl:template>
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text"
select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>