commit f8c9886fd8a0f39f9b152acd4b0fbbc131b827c0
Author: W. David Ashley <w.david.ashley(a)gmail.com>
Date: Tue Jun 30 21:16:19 2015 -0500
Updated Gurst Domains chapter.
- Updated the section Defining and Booting a Persistent Guest Domain.
- Added Domains-Example-8.py for the Provisioning section
en-US/Guest_Domains.xml | 46 ++++++++++--------------------------
en-US/extras/Domains-Example-8.py | 25 ++++++++++++++++++++
2 files changed, 38 insertions(+), 33 deletions(-)
---
diff --git a/en-US/Guest_Domains.xml b/en-US/Guest_Domains.xml
index a02237a..dc79b5e 100644
--- a/en-US/Guest_Domains.xml
+++ b/en-US/Guest_Domains.xml
@@ -278,8 +278,8 @@
</para>
<example>
- <title>Prvisioning a Transient Guest Domain</title>
- <programlisting language="Python"><xi:include
href="extras/Domains-Example-1.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ <title>Provisioning a Transient Guest Domain</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-7.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
</example>
<para>
@@ -298,44 +298,24 @@
</section>
<section
id="libvirt_application_development_guide_using_python-Guest_Domains-Lifecycle-Provisioning-apis-persistent">
- <title>Defining and booting a persistent guest
domain</title>
+ <title>Defining and Booting a Persistent Guest
Domain</title>
<para>
- Before a persistent domain can be booted, it must have its
configuration
- defined. This again requires a connection to libvirt and a string
containing
- the XML document describing the required guest configuration. The
- <literal>virDomainPtr</literal> object obtained from
defining the guest,
- can then be used to boot it. The following example assumes that
- <literal>conn</literal> is an instance of the
<literal>virConnectPtr</literal>
- object.
+ Before a persistent domain can be booted, it must have its
configuration
+ defined. This again requires a connection to libvirt and a string
containing
+ the XML document describing the required guest configuration. The
+ <literal>virDomain</literal> object obtained from
defining the guest,
+ can then be used to boot it.
</para>
- <programlisting>
- <![CDATA[
- virDomainPtr dom;
- const char *xmlconfig = "<domain>........</domain>";
-
- dom = virConnectDefineXML(conn, xmlconfig, 0);
-
- if (!dom) {
- fprintf(stderr, "Domain definition failed");
- return;
- }
-
- if (virDomainCreate(dom) < 0) {
- virDomainFree(dom);
- fprintf(stderr, "Cannot boot guest");
- return;
- }
-
- fprintf(stderr, "Guest %s has booted", virDomainName(dom));
- virDomainFree(dom);
- ]]>
- </programlisting>
+ <example>
+ <title>Defining and Booting a Persistent Guest
Domain</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-8.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
</section>
- </section>
+ </section>
<section
id="libvirt_application_development_guide_using_python-Guest_Domains-Lifecycle-Provisioning-config">
<title>New guest provisioning techniques</title>
diff --git a/en-US/extras/Domains-Example-8.py b/en-US/extras/Domains-Example-8.py
new file mode 100644
index 0000000..aa2cda0
--- /dev/null
+++ b/en-US/extras/Domains-Example-8.py
@@ -0,0 +1,25 @@
+# Example-8.py
+from __future__ import print_function
+import sys
+import libvirt
+
+xmlconfig = '<domain>........</domain>'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.defineXML(xmlconfig, 0)
+if dom == None:
+ print('Failed to define a domain from an XML definition.', file=sys.stderr)
+ exit(1)
+
+if dom.create(dom) < 0:
+ print('Can not boot guest domain.', file=sys.stderr)
+ exit(1)
+
+print('Guest '+dom.name()+' has booted', file=sys.stderr)
+
+conn.close()
+exit(0)