commit 8e8d4230eccd4239cc93576e795f8661ea94623d
Author: W. David Ashley <w.david.ashley(a)gmail.com>
Date: Sun Jul 5 11:41:58 2015 -0500
Domains Chapter
Autostart section
- converted the section to Python
- added example 25
en-US/Guest_Domains.xml | 14 ++++++++++----
en-US/extras/Domains-Example-25.py | 21 +++++++++++++++++++++
2 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/en-US/Guest_Domains.xml b/en-US/Guest_Domains.xml
index b633cf9..8039ccb 100644
--- a/en-US/Guest_Domains.xml
+++ b/en-US/Guest_Domains.xml
@@ -719,11 +719,17 @@
<title>Autostart</title>
<para>
- A guest domain can be configured to autostart on a particular hypervisor,
either by the hypervisor itself or libvirt. In combination with managed save, this allows
the operating system on a guest domain to withstand host reboots without ever considering
itself to have rebooted. When libvirt restarts, the guest domain will be automatically
restored. This is handled by an API separate to regular save and restore, because paths
must be known to libvirt without user input.
- </para>
- <para>
- TODO: code example.
+ A guest domain can be configured to autostart on a particular hypervisor,
either by the
+ hypervisor itself or libvirt. In combination with managed save, this allows
the operating
+ system on a guest domain to withstand host reboots without ever considering
itself to have
+ rebooted. When libvirt restarts, the guest domain will be automatically
restored. This is
+ handled by an API separate to regular save and restore, because paths must be
known to
+ libvirt without user input.
</para>
+ <example>
+ <title>Set Autostart for a Domain</title>
+ <programlisting language="Python"><xi:include
href="extras/Domains-Example-25.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
</section>
</section>
diff --git a/en-US/extras/Domains-Example-25.py b/en-US/extras/Domains-Example-25.py
new file mode 100644
index 0000000..12c8e1a
--- /dev/null
+++ b/en-US/extras/Domains-Example-25.py
@@ -0,0 +1,21 @@
+# Example-25.py
+from __future__ import print_function
+import sys
+import libvirt
+
+domName = 'Fedora22-x86_64-1'
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByID(6)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+dom.setAutostart(1) # turn on autostart
+
+conn.close()
+exit(0)