commit 88d529159eea084ff825b6c0ffb37817975f0f47
Author: W. David Ashley <w.david.ashley(a)gmail.com>
Date: Fri Jul 3 20:53:32 2015 -0500
Domains Chapter
Migration section
- Finished converting the section to Python
- added examples 22-24
en-US/Guest_Domains.xml | 23 +++++++++++++++--------
en-US/extras/Domains-Example-22.py | 32 ++++++++++++++++++++++++++++++++
en-US/extras/Domains-Example-23.py | 26 ++++++++++++++++++++++++++
en-US/extras/Domains-Example-24.py | 32 ++++++++++++++++++++++++++++++++
4 files changed, 105 insertions(+), 8 deletions(-)
---
diff --git a/en-US/Guest_Domains.xml b/en-US/Guest_Domains.xml
index 808cdec..e1c66eb 100644
--- a/en-US/Guest_Domains.xml
+++ b/en-US/Guest_Domains.xml
@@ -643,28 +643,35 @@
</section>
- <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Lifecycle-Migration">
+ <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Lifecycle-Migration">
<title>Migration</title>
<para>
- Migration is the process of taking the image of a guest domain and moving it
somewhere, typically from a hypervisor on one node to a hypervisor on another node. There
are two APIs for migration. The <literal>virDomainMigrate</literal> command
takes an established hypervisor connection, and instructs the domain to migrate to this
connection. The <literal>virMigrateToUri</literal> command takes a URI
specifying a hypervisor connection, opens the connection, then instructions the domain to
migrate to this connection. Both these commands can be passed a parameter to specify live
migration. For migration to complete successfully, storage needs to be shared between the
source and target hypervisors.
+ Migration is the process of taking the image of a guest domain and moving it
somewhere,
+ typically from a hypervisor on one node to a hypervisor on another node.
There are two
+ methods for migration. The <literal>migrate</literal> method
takes an established
+ hypervisor connection, and instructs the domain to migrate to this
connection. The
+ <literal>migrateToUri</literal> method takes a URI specifying a
hypervisor connection,
+ opens the connection, then instructions the domain to migrate to this
connection. Both
+ these methods can be passed a parameter to specify live migration. For
migration to
+ complete successfully, storage needs to be shared between the source and
target hypervisors.
</para>
<para>
- TODO: Add 2 cold examples, 1 live example.
+ TODO: Add 2 cold examples, 1 live example.
</para>
- </section>
+ </section>
- <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Lifecycle-Autostart">
+ <section
id="libvirt_application_development_guide_using_python-Guest_Domains-Lifecycle-Autostart">
<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.
+ 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.
+ TODO: code example.
</para>
- </section>
+ </section>
</section>
diff --git a/en-US/extras/Domains-Example-22.py b/en-US/extras/Domains-Example-22.py
new file mode 100644
index 0000000..7093685
--- /dev/null
+++ b/en-US/extras/Domains-Example-22.py
@@ -0,0 +1,32 @@
+# Example-22.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)
+
+dest_conn = libvirt.open('qemu+ssh://desthost/system')
+if conn == None:
+ print('Failed to open connection to qemu+ssh://desthost/system',
file=sys.stderr)
+ exit(1)
+
+dom = conn.lookupByName(domName)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+new_dom = dom.migrate(dest_conn, 0, None, None, 0)
+if new_dom == None:
+ print('Could not migrate to the new domain', file=sys.stderr)
+ exit(1)
+
+print('Domain was migrated successfully.', file=sys.stderr)
+
+destconn.close()
+conn.close()
+exit(0)
diff --git a/en-US/extras/Domains-Example-23.py b/en-US/extras/Domains-Example-23.py
new file mode 100644
index 0000000..da5a37c
--- /dev/null
+++ b/en-US/extras/Domains-Example-23.py
@@ -0,0 +1,26 @@
+# Example-23.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.lookupByName(domName)
+if dom == None:
+ print('Failed to find the domain '+domName, file=sys.stderr)
+ exit(1)
+
+new_dom = dom.migrateToURI('qemu+ssh://desthost/system', 0, None, 0)
+if new_dom == None:
+ print('Could not migrate to the new domain', file=sys.stderr)
+ exit(1)
+
+print('Domain was migrated successfully.', file=sys.stderr)
+
+conn.close()
+exit(0)
diff --git a/en-US/extras/Domains-Example-24.py b/en-US/extras/Domains-Example-24.py
new file mode 100644
index 0000000..f2274dd
--- /dev/null
+++ b/en-US/extras/Domains-Example-24.py
@@ -0,0 +1,32 @@
+# Example-24.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)
+
+dest_conn = libvirt.open('qemu+ssh://desthost/system')
+if conn == None:
+ print('Failed to open connection to qemu+ssh://desthost/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)
+
+new_dom = dom.migrate(dest_conn, libvirt.VIR_MIGRATE_LIVE, None, None, 0)
+if new_dom == None:
+ print('Could not migrate to the new domain', file=sys.stderr)
+ exit(1)
+
+print('Domain was migrated successfully.', file=sys.stderr)
+
+destconn.close()
+conn.close()
+exit(0)