commit 7b043a5f613dcddfcf7b8b3f89802ea78fd8a613
Author: W. David Ashley <w.david.ashley(a)gmail.com>
Date: Wed Aug 5 13:39:41 2015 -0500
Virtual Networks chapter
- added example 3
- aaded support text for example 3
- this should finish this chapter
en-US/Virtual_Networks.xml | 14 ++++++++++-
en-US/extras/VirtualNetworks-Example-3.py | 35 +++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/en-US/Virtual_Networks.xml b/en-US/Virtual_Networks.xml
index 09f610f..217ccec 100644
--- a/en-US/Virtual_Networks.xml
+++ b/en-US/Virtual_Networks.xml
@@ -78,15 +78,25 @@
<title>Lifecycle control</title>
<para>
The following example shows how to use the
<literal>networkCreateXML</literal>,
- <literal>networkDefineXML</literal> and the <literal>
+ <literal>networkDefineXML</literal> and the
<literal>destroy</literal> methods.
</para>
+ <example>
+ <title>Creating and destroying virtual networks</title>
+ <programlisting language="Python"><xi:include
href="extras/VirtualNetworks-Example-2.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
</section>
<section
id="libvirt_application_development_guide_using_python-Virtual_Networks-Config">
<title>Network configuration</title>
<para>
- TBD
+ The following example shows how to use the
<literal>XMLDesc</literal>, <literal>autostart</literal>,
+ <literal>isActive</literal>,
<literal>isPersistent</literal> and the
<literal>setAutostart</literal>
+ methods.
</para>
+ <example>
+ <title>Configuring virtual networks</title>
+ <programlisting language="Python"><xi:include
href="extras/VirtualNetworks-Example-3.py" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting>
+ </example>
</section>
</chapter>
diff --git a/en-US/extras/VirtualNetworks-Example-3.py
b/en-US/extras/VirtualNetworks-Example-3.py
new file mode 100644
index 0000000..25fb589
--- /dev/null
+++ b/en-US/extras/VirtualNetworks-Example-3.py
@@ -0,0 +1,35 @@
+# Example-1.py
+from __future__ import print_function
+import sys
+import libvirt
+
+conn = libvirt.open('qemu:///system')
+if conn == None:
+ print('Failed to open connection to qemu:///system', file=sys.stderr)
+ exit(1)
+
+# lookup the default network by name
+network = conn.networkLookupByName('default')
+print('Virtual network default:')
+print(' name: '+network.name())
+print(' UUID: '+network.UUIDString())
+print(' bridge: '+network.bridgeName())
+print(' autostart: '+str(network.autostart()))
+print(' is active: '+str(network.isActive()))
+print(' is persistent: '+str(network.isPersistent()))
+print()
+
+print('Unsetting autostart')
+network.setAutostart(0)
+print(' autostart: '+str(network.autostart()))
+print('Setting autostart')
+network.setAutostart(1)
+print(' autostart: '+str(network.autostart()))
+print()
+
+xml = network.XMLDesc(0)
+print('XML description:')
+print(xml)
+
+conn.close()
+exit(0)