From 78de9baafcfbb5445dad3222ee187c11bcb48eae Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Tue, 28 Mar 2006 14:48:57 +0000 Subject: [PATCH] Fixing the python example, Daniel --- docs/architecture.html | 2 +- docs/libvir.html | 28 +++++++++++++++------------- docs/python.html | 25 +++++++++++++------------ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/docs/architecture.html b/docs/architecture.html index f669d545e3..64ba00f997 100644 --- a/docs/architecture.html +++ b/docs/architecture.html @@ -42,4 +42,4 @@ drivers present in driver.h:

Note that a given driver may only implement a subset of those functions, for example saving a domain state to disk and restoring it is only possible though the Xen Daemon, on the other hand all interfaces allow to query the -runtime state of a given domain.

+runtime state of a given domain.

diff --git a/docs/libvir.html b/docs/libvir.html index e8b5f23b91..2daa9fae62 100644 --- a/docs/libvir.html +++ b/docs/libvir.html @@ -196,7 +196,7 @@ for example saving a domain state to disk and restoring it is only possible though the Xen Daemon, on the other hand all interfaces allow to query the runtime state of a given domain.

-

+

Downloads

@@ -316,18 +316,18 @@ will remain functional in spite of the evolution of the library.

Binding for Python

Libvirt comes with direct support for the Python language (just make sure -you installed the libvirt-python package if not compiling from sources). -Also note that Daniel Berrange provides -bindings for Perl +you installed the libvirt-python package if not compiling from sources). Also +note that Daniel Berrange provides bindings for Perl too.

-

The Python binding should be complete and are mostly automatically generated from -the formal description of the API in xml. The bindings are articulated around -2 classes virConnect and virDomain mapping to the C types. -Functions in the C API taking either type as argument then becomes methods -for the classes, their name is just stripped from the virConnect or -virDomain(Get) prefix and the first letter gets converted to lower case, for -example the C functions:

+

The Python binding should be complete and are mostly automatically +generated from the formal description of the API in xml. The bindings are +articulated around 2 classes virConnect and virDomain mapping to +the C types. Functions in the C API taking either type as argument then +becomes methods for the classes, their name is just stripped from the +virConnect or virDomain(Get) prefix and the first letter gets converted to +lower case, for example the C functions:

int virConnectNumOfDomains @@ -375,8 +375,9 @@ if conn == None: print 'Failed to open connection to the hypervisor' sys.exit(1) -dom0 = conn.lookupByName("Domain-0") -if dom0 == None: +try: + dom0 = conn.lookupByName("Domain-0") +except: print 'Failed to find the main domain' sys.exit(1) @@ -392,6 +393,7 @@ from the C API, the only points to notice are:

openReadOnly function allows the code to execute as a normal user.
  • getting an object representing the Domain 0 using lookupByName
  • +
  • if the domain is not found a libvirtError exception will be raised
  • extracting and printing some informations about the domain using various methods diff --git a/docs/python.html b/docs/python.html index b0ff43e904..791c8637ef 100644 --- a/docs/python.html +++ b/docs/python.html @@ -1,16 +1,15 @@ Binding for Python

    Binding for Python

    Libvirt comes with direct support for the Python language (just make sure -you installed the libvirt-python package if not compiling from sources). -Also note that Daniel Berrange provides -bindings for Perl -too.

    The Python binding should be complete and are mostly automatically generated from -the formal description of the API in xml. The bindings are articulated around -2 classes virConnect and virDomain mapping to the C types. -Functions in the C API taking either type as argument then becomes methods -for the classes, their name is just stripped from the virConnect or -virDomain(Get) prefix and the first letter gets converted to lower case, for -example the C functions:

    int virConnectNumOfDomains +you installed the libvirt-python package if not compiling from sources). Also +note that Daniel Berrange provides bindings for Perl +too.

    The Python binding should be complete and are mostly automatically +generated from the formal description of the API in xml. The bindings are +articulated around 2 classes virConnect and virDomain mapping to +the C types. Functions in the C API taking either type as argument then +becomes methods for the classes, their name is just stripped from the +virConnect or virDomain(Get) prefix and the first letter gets converted to +lower case, for example the C functions:

    int virConnectNumOfDomains (virConnectPtr conn);

    int virDomainSetMaxMemory (virDomainPtr domain, unsigned long memory);

    become

    virConn::numOfDomains(self)

    virDomain::setMaxMemory(self, memory)

    This process is fully automated, you can get a summary of the conversion in the file libvirtclass.txt present in the python dir or in the docs.There @@ -35,8 +34,9 @@ if conn == None: print 'Failed to open connection to the hypervisor' sys.exit(1) -dom0 = conn.lookupByName("Domain-0") -if dom0 == None: +try: + dom0 = conn.lookupByName("Domain-0") +except: print 'Failed to find the main domain' sys.exit(1) @@ -46,6 +46,7 @@ from the C API, the only points to notice are:

    • the import of the modu
    • getting a connection to the hypervisor, in that case using the openReadOnly function allows the code to execute as a normal user.
    • getting an object representing the Domain 0 using lookupByName
    • +
    • if the domain is not found a libvirtError exception will be raised
    • extracting and printing some informations about the domain using various methods associated to the virDomain class.
    • -- 2.47.2