1 <?xml version=
"1.0" encoding=
"UTF-8"?>
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <h1>The libvirt API concepts
</h1>
7 <p> This page describes the main principles and architecture choices
8 behind the definition of the libvirt API:
</p>
12 <h2><a id=
"Objects">Objects Exposed
</a></h2>
13 <p> As defined in the
<a href=
"goals.html">goals section
</a>, the libvirt
14 API is designed to expose all the resources needed to manage the
15 virtualization support of recent operating systems. The first object
16 manipulated through the API is the
<code>virConnectPtr
</code>, which
17 represents the connection to a hypervisor. Any application using libvirt
18 is likely to start using the
19 API by calling one of
<a href=
"html/libvirt-libvirt-host.html#virConnectOpen"
20 >the virConnectOpen functions
</a>. You will note that those functions take
21 a name argument which is actually a
<a href=
"uri.html">connection URI
</a>
22 to select the right hypervisor to open.
23 A URI is needed to allow remote connections and also select between
24 different possible hypervisors. For example, on a Linux system it may be
25 possible to use both KVM and LinuxContainers on the same node. A NULL
26 name will default to a preselected hypervisor, but it's probably not a
27 wise thing to do in most cases. See the
<a href=
"uri.html">connection
28 URI
</a> page for a full descriptions of the values allowed.
</p>
29 <p> OnDevice the application obtains a
30 <a href=
"/html/libvirt-libvirt-host.html#virConnectPtr">
31 <code>virConnectPtr
</code>
33 connection to the hypervisor it can then use it to manage the hypervisor's
34 available domains and related virtualization
35 resources, such as storage and networking. All those are
36 exposed as first class objects and connected to the hypervisor connection
37 (and the node or cluster where it is available).
</p>
39 <img alt=
"first class objects exposed by the API"
40 src=
"libvirt-object-model.png"/>
42 <p> The figure above shows the five main objects exported by the API:
</p>
45 <a href=
"html/libvirt-libvirt-host.html#virConnectPtr">
46 <code>virConnectPtr
</code>
48 <p>Represents the connection to a hypervisor. Use one of the
49 <a href=
"html/libvirt-libvirt-host.html#virConnectOpen">virConnectOpen
</a>
50 functions to obtain connection to the hypervisor which is then used
51 as a parameter to other connection API's.
</p></li>
53 <a href=
"html/libvirt-libvirt-domain.html#virDomainPtr">
54 <code>virDomainPtr
</code>
56 <p>Represents one domain either active or defined (i.e. existing as
57 permanent config file and storage but not currently running on that
59 <a href=
"html/libvirt-libvirt-domain.html#virConnectListAllDomains">
60 <code>virConnectListAllDomains
</code>
62 lists all the domains for the hypervisor.
</p></li>
64 <a href=
"html/libvirt-libvirt-network.html#virNetworkPtr">
65 <code>virNetworkPtr
</code>
67 <p>Represents one network either active or defined (i.e. existing
68 as permanent config file and storage but not currently activated).
70 <a href=
"html/libvirt-libvirt-network.html#virConnectListAllNetworks">
71 <code>virConnectListAllNetworks
</code>
73 lists all the virtualization networks for the hypervisor.
</p></li>
75 <a href=
"html/libvirt-libvirt-storage.html#virStorageVolPtr">
76 <code>virStorageVolPtr
</code>
78 <p>Represents one storage volume generally used
79 as a block device available to one of the domains. The function
80 <a href=
"html/libvirt-libvirt-storage.html#virStorageVolLookupByPath">
81 <code>virStorageVolLookupByPath
</code>
83 finds the storage volume object based on its path on the node.
</p></li>
85 <a href=
"html/libvirt-libvirt-storage.html#virStoragePoolPtr">
86 <code>virStoragePoolPtr
</code>
88 <p>Represents a storage pool, which is a logical area
89 used to allocate and store storage volumes. The function
90 <a href=
"html/libvirt-libvirt-storage.html#virConnectListAllStoragePools">
91 <code>virConnectListAllStoragePools
</code>
93 lists all of the virtualization storage pools on the hypervisor.
95 <a href=
"html/libvirt-libvirt-storage.html#virStoragePoolLookupByVolume">
96 <code>virStoragePoolLookupByVolume
</code>
98 finds the storage pool containing a given storage volume.
</p></li>
100 <p> Most objects manipulated by the library can also be represented using
101 XML descriptions. This is used primarily to create those object, but is
102 also helpful to modify or save their description back.
</p>
103 <p> Domains, networks, and storage pools can be either
<code>active
</code>
104 i.e. either running or available for immediate use, or
105 <code>defined
</code> in which case they are inactive but there is
106 a permanent definition available in the system for them. Based on this
107 they can be activated dynamically in order to be used.
</p>
108 <p> Most objects can also be named in various ways:
</p>
110 <li><code>name
</code>
111 <p>A user friendly identifier but whose uniqueness
112 cannot be guaranteed between two nodes.
</p></li>
114 <p>A runtime unique identifier
115 provided by the hypervisor for one given activation of the object;
116 however, it becomes invalid once the resource is deactivated.
</p></li >
117 <li><code>UUID
</code>
118 <p> A
16 byte unique identifier
119 as defined in
<a href=
"http://www.ietf.org/rfc/rfc4122.txt">RFC
4122</a>,
120 which is guaranteed to be unique for long term usage and across a
121 set of nodes.
</p></li>
124 <h2><a id=
"Functions">Functions and Naming Conventions
</a></h2>
125 <p> The naming of the functions present in the library is usually
126 composed by a prefix describing the object associated to the function
127 and a verb describing the action on that object.
</p>
128 <p> For each first class object you will find APIs
129 for the following actions:
</p>
131 <li><b>Lookup
</b> [...LookupBy...]
132 <p>Used to perform lookups on objects by some type of identifier,
136 <a href=
"html/libvirt-libvirt-domain.html#virDomainLookupByID">
137 <code>virDomainLookupByID
</code>
141 <a href=
"html/libvirt-libvirt-domain.html#virDomainLookupByName">
142 <code>virDomainLookupByName
</code>
146 <a href=
"html/libvirt-libvirt-domain.html#virDomainLookupByUUID">
147 <code>virDomainLookupByUUID
</code>
151 <a href=
"html/libvirt-libvirt-domain.html#virDomainLookupByUUIDString">
152 <code>virDomainLookupByUUIDString
</code>
157 <li><b>Enumeration
</b> [virConnectList..., virConnectNumOf...]
158 <p>Used to enumerate a set of object available to a given
159 hypervisor connection such as:
</p>
162 <a href=
"html/libvirt-libvirt-domain.html#virConnectListDomains">
163 <code>virConnectListDomains
</code>
167 <a href=
"html/libvirt-libvirt-domain.html#virConnectNumOfDomains">
168 <code>virConnectNumOfDomains
</code>
172 <a href=
"html/libvirt-libvirt-network.html#virConnectListNetworks">
173 <code>virConnectListNetworks
</code>
177 <a href=
"html/libvirt-libvirt-storage.html#virConnectListStoragePools">
178 <code>virConnectListStoragePools
</code>
183 <li><b>Description
</b> [...GetInfo]
184 <p>Generic accessor providing a set of generic information about an
185 object, such as:
</p>
188 <a href=
"html/libvirt-libvirt-host.html#virNodeGetInfo">
189 <code>virNodeGetInfo
</code>
193 <a href=
"html/libvirt-libvirt-domain.html#virDomainGetInfo">
194 <code>virDomainGetInfo
</code>
198 <a href=
"html/libvirt-libvirt-storage.html#virStoragePoolGetInfo">
199 <code>virStoragePoolGetInfo
</code>
203 <a href=
"html/libvirt-libvirt-storage.html#virStorageVolGetInfo">
204 <code>virStorageVolGetInfo
</code>
209 <li><b>Accessors
</b> [...Get..., ...Set...]
210 <p>Specific accessors used to query or modify data for the given object,
214 <a href=
"html/libvirt-libvirt-host.html#virConnectGetType">
215 <code>virConnectGetType
</code>
219 <a href=
"html/libvirt-libvirt-domain.html#virDomainGetMaxMemory">
220 <code>virDomainGetMaxMemory
</code>
224 <a href=
"html/libvirt-libvirt-domain.html#virDomainSetMemory">
225 <code>virDomainSetMemory
</code>
229 <a href=
"html/libvirt-libvirt-domain.html#virDomainGetVcpus">
230 <code>virDomainGetVcpus
</code>
234 <a href=
"html/libvirt-libvirt-storage.html#virStoragePoolSetAutostart">
235 <code>virStoragePoolSetAutostart
</code>
239 <a href=
"html/libvirt-libvirt-network.html#virNetworkGetBridgeName">
240 <code>virNetworkGetBridgeName
</code>
245 <li><b>Creation
</b> [...Create, ...CreateXML]
246 <p>Used to create and start objects. The ...CreateXML APIs will create
247 the object based on an XML description, while the ...Create APIs will
248 create the object based on existing object pointer, such as:
</p>
251 <a href=
"html/libvirt-libvirt-domain.html#virDomainCreate">
252 <code>virDomainCreate
</code>
256 <a href=
"html/libvirt-libvirt-domain.html#virDomainCreateXML">
257 <code>virDomainCreateXML
</code>
261 <a href=
"html/libvirt-libvirt-network.html#virNetworkCreate">
262 <code>virNetworkCreate
</code>
266 <a href=
"html/libvirt-libvirt-network.html#virNetworkCreateXML">
267 <code>virNetworkCreateXML
</code>
272 <li><b>Destruction
</b> [...Destroy]
273 <p>Used to shutdown or deactivate and destroy objects, such as:
</p>
276 <a href=
"html/libvirt-libvirt-domain.html#virDomainDestroy">
277 <code>virDomainDestroy
</code>
281 <a href=
"html/libvirt-libvirt-network.html#virNetworkDestroy">
282 <code>virNetworkDestroy
</code>
286 <a href=
"html/libvirt-libvirt-storage.html#virStoragePoolDestroy">
287 <code>virStoragePoolDestroy
</code>
293 <p>Note: functions returning vir*Ptr (like the virDomainLookup functions)
294 allocate memory which needs to be freed by the caller by the corresponding
295 vir*Free function (e.g. virDomainFree for a virDomainPtr object).
297 <p> For more in-depth details of the storage related APIs see
298 <a href=
"storage.html">the storage management page
</a>.
300 <h2><a id=
"Drivers">The libvirt Drivers
</a></h2>
301 <p>Drivers are the basic building block for libvirt functionality
302 to support the capability to handle specific hypervisor driver calls.
303 Drivers are discovered and registered during connection processing as
305 <a href=
"html/libvirt-libvirt-host.html#virInitialize">
306 <code>virInitialize
</code>
309 has a registration API which loads up the driver specific function
310 references for the libvirt APIs to call. The following is a simplistic
311 view of the hypervisor driver mechanism. Consider the stacked list of
312 drivers as a series of modules that can be plugged into the architecture
313 depending on how libvirt is configured to be built.
</p>
315 <img alt=
"The libvirt driver architecture"
316 src=
"libvirt-driver-arch.png"/>
318 <p>The driver architecture is also used to support other virtualization
319 components such as storage, storage pools, host device, networking,
320 network interfaces, and network filters.
</p>
321 <p>See the
<a href=
"drivers.html">libvirt drivers
</a> page for more
322 information on hypervisor and storage specific drivers.
</p>
323 <p>Not all drivers support every virtualization function possible.
324 The
<a href=
"hvsupport.html">libvirt API support matrix
</a> lists
325 the various functions and support found in each driver by the version
326 support was added into libvirt.
328 <h2><a id=
"Remote">Daemon and Remote Access
</a></h2>
329 <p>Access to libvirt drivers is primarily handled by the libvirtd
330 daemon through the
<a href=
"remote.html">remote
</a> driver via an
331 <a href=
"internals/rpc.html">RPC
</a>. Some hypervisors do support
332 client-side connections and responses, such as Test, OpenVZ, VMware,
333 Power VM (phyp), VirtualBox (vbox), ESX, Hyper-V, Xen, and Virtuozzo.
334 The libvirtd daemon service is started on the host at system boot
335 time and can also be restarted at any time by a properly privileged
336 user, such as root. The libvirtd daemon uses the same libvirt API
337 <a href=
"html/libvirt-libvirt-host.html#virInitialize">
338 <code>virInitialize
</code>
340 sequence as applications
341 for client-side driver registrations, but then extends the registered
342 driver list to encompass all known drivers supported for all driver
343 types supported on the host.
</p>
344 <p>The libvirt client
<a href=
"apps.html">applications
</a> use a
345 <a href=
"uri.html">URI
</a> to obtain the
<code>virConnectPtr
</code>.
346 The
<code>virConnectPtr
</code> keeps track of the driver connection
347 plus a variety of other connections (network, interface, storage, etc.).
348 The
<code>virConnectPtr
</code> is then used as a parameter to other
349 virtualization
<a href=
"#Functions">functions
</a>. Depending upon the
350 driver being used, calls will be routed through the remote driver to
351 the libvirtd daemon. The daemon will reference the connection specific
352 driver in order to retrieve the requested information and then pass
353 back status and/or data through the connection back to the application.
354 The application can then decide what to do with that data, such as
355 display, write log data, etc.
<a href=
"migration.html">Migration
</a>
356 is an example of many facets of the architecture in use.
</p>
359 <img alt=
"The libvirt daemon and remote architecture"
360 src=
"libvirt-daemon-arch.png"/>
363 The key takeaway from the above diagram is that there is a remote driver
364 which handles transactions for a majority of the drivers. The libvirtd
365 daemon running on the host will receive transaction requests from the
366 remote driver and will then query the hypervisor driver as specified in
367 the
<code>virConnectPtr
</code> in order to fetch the data. The data will
368 then be returned through the remote driver to the client application
371 <p>If you are interested in contributing to libvirt, read the
372 <a href=
"http://wiki.libvirt.org/page/FAQ">FAQ
</a> and
373 <a href=
"hacking.html">hacking
</a> guidelines to gain an understanding
374 of basic rules and guidelines. In order to add new API functionality
375 follow the instructions regarding
376 <a href=
"api_extension.html">implementing a new API in libvirt
</a>.