Skip to content

Commit 25763e9

Browse files
author
David Scott
committed
Move the VM import/export text from overview to import/export
Signed-off-by: David Scott <[email protected]>
1 parent b669564 commit 25763e9

File tree

2 files changed

+245
-248
lines changed

2 files changed

+245
-248
lines changed

xen-api/importexport.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,251 @@ title: VM import/export
33
layout: default
44
---
55

6+
VMs can be exported to a file and later imported to any XenServer host. The export protocol is a simple HTTP(S) GET, which should be performed on the master if the VM is on a pool member. Authorization is either standard HTTP basic authentication, or if a session has already been obtained, this can be used. The VM to export is specified either by UUID or by reference. To keep track of the export, a task can be created and passed in using its reference. The request might result in a redirect if the VM's disks are only accessible on a pool member.
7+
8+
The following arguments are passed on the command line:
9+
10+
<table>
11+
<col width="28%" />
12+
<col width="68%" />
13+
<thead>
14+
<tr class="header">
15+
<th align="left">Argument</th>
16+
<th align="left">Description</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr class="odd">
21+
<td align="left">session_id</td>
22+
<td align="left">the reference of the session being used to authenticate; required only when not using HTTP basic authentication</td>
23+
</tr>
24+
<tr class="even">
25+
<td align="left">task_id</td>
26+
<td align="left">the reference of the task object with which to keep track of the operation; optional, required only if you have created a task object to keep track of the export</td>
27+
</tr>
28+
<tr class="odd">
29+
<td align="left">ref</td>
30+
<td align="left">the reference of the VM; required only if not using the UUID</td>
31+
</tr>
32+
<tr class="even">
33+
<td align="left">uuid</td>
34+
<td align="left">the UUID of the VM; required only if not using the reference</td>
35+
</tr>
36+
</tbody>
37+
</table>
38+
39+
For example, using the Linux command line tool cURL:
40+
41+
curl http://root:foo@myxenserver1/export?uuid=<vm_uuid> -o <exportfile>
42+
43+
will export the specified VM to the file `exportfile`.
44+
45+
To export just the metadata, use the URI `http://server/export_metadata`.
46+
47+
The import protocol is similar, using HTTP(S) PUT. The `session_id` and `task_id` arguments are as for the export. The `ref` and `uuid` are not used; a new reference and uuid will be generated for the VM. There are some additional parameters:
48+
49+
<table>
50+
<col width="28%" />
51+
<col width="68%" />
52+
<thead>
53+
<tr class="header">
54+
<th align="left">Argument</th>
55+
<th align="left">Description</th>
56+
</tr>
57+
</thead>
58+
<tbody>
59+
<tr class="odd">
60+
<td align="left">restore</td>
61+
<td align="left">if <em>true</em>, the import is treated as replacing the original VM - the implication of this currently is that the MAC addresses on the VIFs are exactly as the export was, which will lead to conflicts if the original VM is still being run.</td>
62+
</tr>
63+
<tr class="even">
64+
<td align="left">force</td>
65+
<td align="left">if <em>true</em>, any checksum failures will be ignored (the default is to destroy the VM if a checksum error is detected)</td>
66+
</tr>
67+
<tr class="odd">
68+
<td align="left">sr_id</td>
69+
<td align="left">the reference of an SR into which the VM should be imported. The default behavior is to import into the <em>Pool.default_SR</em>.</td>
70+
</tr>
71+
</tbody>
72+
</table>
73+
74+
For example, again using cURL:
75+
76+
curl -T <exportfile> http://root:foo@myxenserver2/import
77+
78+
will import the VM to the default SR on the server.
79+
80+
> **Note**
81+
>
82+
> Note that if no default SR has been set, and no sr\_uuid is specified, the error message "DEFAULT\_SR\_NOT\_FOUND" is returned.
83+
84+
Another example:
85+
86+
curl -T <exportfile> http://root:foo@myxenserver2/import?sr_id=<opaque_ref_of_sr>
87+
88+
will import the VM to the specified SR on the server.
89+
90+
To import just the metadata, use the URI `http://server/import_metadata`
91+
92+
### Xen Virtual Appliance (XVA) VM Import Format
93+
94+
XenServer supports a human-readable legacy VM input format called XVA. This section describes the syntax and structure of XVA.
95+
96+
An XVA consists of a directory containing XML metadata and a set of disk images. A VM represented by an XVA is not intended to be directly executable. Data within an XVA package is compressed and intended for either archiving on permanent storage or for being transmitted to a VM server - such as a XenServer host - where it can be decompressed and executed.
97+
98+
XVA is a hypervisor-neutral packaging format; it should be possible to create simple tools to instantiate an XVA VM on any other platform. XVA does not specify any particular runtime format; for example disks may be instantiated as file images, LVM volumes, QCoW images, VMDK or VHD images. An XVA VM may be instantiated any number of times, each instantiation may have a different runtime format.
99+
100+
XVA does not:
101+
102+
- specify any particular serialization or transport format
103+
104+
- provide any mechanism for customizing VMs (or templates) on install
105+
106+
- address how a VM may be upgraded post-install
107+
108+
- define how multiple VMs, acting as an appliance, may communicate
109+
110+
These issues are all addressed by the related Open Virtual Appliance specification.
111+
112+
An XVA is a directory containing, at a minimum, a file called `ova.xml`. This file describes the VM contained within the XVA and is described in Section 3.2. Disks are stored within sub-directories and are referenced from the ova.xml. The format of disk data is described later in Section 3.3.
113+
114+
The following terms will be used in the rest of the chapter:
115+
116+
- HVM: a mode in which unmodified OS kernels run with the help of virtualization support in the hardware.
117+
118+
- PV: a mode in which specially modified "paravirtualized" kernels run explicitly on top of a hypervisor without requiring hardware support for virtualization.
119+
120+
The "ova.xml" file contains the following elements:
121+
122+
<appliance version="0.1">
123+
124+
The number in the attribute "version" indicates the version of this specification to which the XVA is constructed; in this case version 0.1. Inside the \<appliance\> there is exactly one \<vm\>: (in the OVA specification, multiple \<vm\>s are permitted)
125+
126+
<vm name="name">
127+
128+
Each \<vm\> element describes one VM. The "name" attribute is for future internal use only and must be unique within the ova.xml file. The "name" attribute is permitted to be any valid UTF-8 string. Inside each \<vm\> tag are the following compulsory elements:
129+
130+
<label>... text ... </label>
131+
132+
A short name for the VM to be displayed in a UI.
133+
134+
<shortdesc> ... description ... </shortdesc>
135+
136+
A description for the VM to be displayed in the UI. Note that for both \<label\> and \<shortdesc\> contents, leading and trailing whitespace will be ignored.
137+
138+
<config mem_set="268435456" vcpus="1"/>
139+
140+
The `<config>` element has attributes which describe the amount of memory in bytes (mem\_set) and number of CPUs (VCPUs) the VM should have.
141+
142+
Each `<vm>` has zero or more \<vbd\> elements representing block devices which look like the following:
143+
144+
<vbd device="sda" function="root" mode="w" vdi="vdi_sda"/>
145+
146+
The attributes have the following meanings:
147+
148+
device
149+
name of the physical device to expose to the VM. For linux guests we use "sd[a-z]" and for windows guests we use "hd[a-d]".
150+
151+
function
152+
if marked as "root", this disk will be used to boot the guest. (NB this does not imply the existence of the Linux root i.e. / filesystem) Only one device should be marked as "root". See Section 3.4 describing VM booting. Any other string is ignored.
153+
154+
mode
155+
either "w" or "ro" if the device is to be read/write or read-only
156+
157+
vdi
158+
the name of the disk image (represented by a \<vdi\> element) to which this block device is connected
159+
160+
Each \<vm\> may have an optional \<hacks\> section like the following: \<hacks is\_hvm="false" kernel\_boot\_cmdline="root=/dev/sda1 ro"/\> The \<hacks\> element is present in the XVA files generated by XenServer but will be removed in future. The attribute "is\_hvm" is either "true" or "false", depending on whether the VM should be booted in HVM or not. The "kernel\_boot\_cmdline" contains additional kernel commandline arguments when booting a guest using pygrub.
161+
162+
In addition to a \<vm\> element, the \<appliance\> will contain zero or more \<vdi\> elements like the following:
163+
164+
<vdi name="vdi_sda" size="5368709120" source="file://sda"
165+
type="dir-gzipped-chunks">
166+
167+
Each \<vdi\> corresponds to a disk image. The attributes have the following meanings:
168+
169+
- name: name of the VDI, referenced by the vdi attribute of \<vbd\> elements. Any valid UTF-8 string is permitted.
170+
171+
- size: size of the required image in bytes
172+
173+
- source: a URI describing where to find the data for the image, only file:// URIs are currently permitted and must describe paths relative to the directory containing the ova.xml
174+
175+
- type: describes the format of the disk data (see Section 3.3)
176+
177+
A single disk image encoding is specified in which has type "dir-gzipped-chunks": Each image is represented by a directory containing a sequence of files as follows:
178+
179+
-rw-r--r-- 1 dscott xendev 458286013 Sep 18 09:51 chunk000000000.gz
180+
-rw-r--r-- 1 dscott xendev 422271283 Sep 18 09:52 chunk000000001.gz
181+
-rw-r--r-- 1 dscott xendev 395914244 Sep 18 09:53 chunk000000002.gz
182+
-rw-r--r-- 1 dscott xendev 9452401 Sep 18 09:53 chunk000000003.gz
183+
-rw-r--r-- 1 dscott xendev 1096066 Sep 18 09:53 chunk000000004.gz
184+
-rw-r--r-- 1 dscott xendev 971976 Sep 18 09:53 chunk000000005.gz
185+
-rw-r--r-- 1 dscott xendev 971976 Sep 18 09:53 chunk000000006.gz
186+
-rw-r--r-- 1 dscott xendev 971976 Sep 18 09:53 chunk000000007.gz
187+
-rw-r--r-- 1 dscott xendev 573930 Sep 18 09:53 chunk000000008.gz
188+
189+
Each file (named "chunk-XXXXXXXXX.gz") is a gzipped file containing exactly 1e9 bytes (1GB, not 1GiB) of raw block data. The small size was chosen to be safely under the maximum file size limits of several filesystems. If the files are gunzipped and then concatenated together, the original image is recovered.
190+
191+
XenServer provides two mechanisms for booting a VM: (i) using a paravirtualized kernel extracted through pygrub; and (ii) using HVM. The current implementation uses the "is\_hvm" flag within the \<hacks\> section to decide which mechanism to use.
192+
193+
This rest of this section describes a very simple Debian VM packaged as an XVA. The VM has two disks, one with size 5120MiB and used for the root filesystem and used to boot the guest using pygrub and the other of size 512MiB which is used for swap. The VM has 512MiB of memory and uses one virtual CPU.
194+
195+
At the topmost level the simple Debian VM is represented by a single directory:
196+
197+
$ ls -l
198+
total 4
199+
drwxr-xr-x 3 dscott xendev 4096 Oct 24 09:42 very simple Debian VM
200+
201+
Inside the main XVA directory are two sub-directories - one per disk - and the single file: ova.xml:
202+
203+
$ ls -l very\ simple\ Debian\ VM/
204+
total 8
205+
-rw-r--r-- 1 dscott xendev 1016 Oct 24 09:42 ova.xml
206+
drwxr-xr-x 2 dscott xendev 4096 Oct 24 09:42 sda
207+
drwxr-xr-x 2 dscott xendev 4096 Oct 24 09:53 sdb
208+
209+
Inside each disk sub-directory are a set of files, each file contains 1GB of raw disk block data compressed using gzip:
210+
211+
$ ls -l very\ simple\ Debian\ VM/sda/
212+
total 2053480
213+
-rw-r--r-- 1 dscott xendev 202121645 Oct 24 09:43 chunk-000000000.gz
214+
-rw-r--r-- 1 dscott xendev 332739042 Oct 24 09:45 chunk-000000001.gz
215+
-rw-r--r-- 1 dscott xendev 401299288 Oct 24 09:48 chunk-000000002.gz
216+
-rw-r--r-- 1 dscott xendev 389585534 Oct 24 09:50 chunk-000000003.gz
217+
-rw-r--r-- 1 dscott xendev 624567877 Oct 24 09:53 chunk-000000004.gz
218+
-rw-r--r-- 1 dscott xendev 150351797 Oct 24 09:54 chunk-000000005.gz
219+
220+
$ ls -l very\ simple\ Debian\ VM/sdb
221+
total 516
222+
-rw-r--r-- 1 dscott xendev 521937 Oct 24 09:54 chunk-000000000.gz
223+
224+
The example simple Debian VM would have an XVA file like the following:
225+
226+
<?xml version="1.0" ?>
227+
<appliance version="0.1">
228+
<vm name="vm">
229+
<label>
230+
very simple Debian VM
231+
</label>
232+
<shortdesc>
233+
the description field can contain any valid UTF-8
234+
</shortdesc>
235+
<config mem_set="536870912" vcpus="1"/>
236+
<hacks is_hvm="false" kernel_boot_cmdline="root=/dev/sda1 ro ">
237+
<!--This section is temporary and will be ignored in future. Attribute
238+
is_hvm ("true" or "false") indicates whether the VM will be booted in HVM mode. In
239+
future this will be autodetected. Attribute kernel_boot_cmdline contains the kernel
240+
commandline for the case where a proper grub menu.lst is not present. In future
241+
booting shall only use pygrub.-->
242+
</hacks>
243+
<vbd device="sda" function="root" mode="w" vdi="vdi_sda"/>
244+
<vbd device="sdb" function="swap" mode="w" vdi="vdi_sdb"/>
245+
</vm>
246+
<vdi name="vdi_sda" size="5368709120" source="file://sda" type="dir-gzippedchunks"/>
247+
<vdi name="vdi_sdb" size="536870912" source="file://sdb" type="dir-gzippedchunks"/>
248+
</appliance>
249+
250+
6251
Because the import and export of VMs can take some time to complete, an
7252
asynchronous HTTP interface to the import and export operations is
8253
provided. To perform an export using the XenServer API, construct

0 commit comments

Comments
 (0)