ref: refs/heads/master
commit 762fec511e263a873251d784d41139dd4b083c69
Author: Michael Andres
Date: Tue Feb 3 20:11:06 2009 +0100
Start adding example applications tying out powerCIM.
---
examples/README | 17 +++++++++++++++++
examples/TODO | 24 ++++++++++++++++++++++++
examples/list_packages.py | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/examples/README b/examples/README
new file mode 100644
index 0000000..71e5141
--- /dev/null
+++ b/examples/README
@@ -0,0 +1,17 @@
+
+Some example applications using powerCIM (http://en.opensuse.org/PowerCIM)
+
+#> zypper ar http://download.opensuse.org/repositories/home:/mmrazik/openSUSE_Factory powerCIM
+#> zypper in powerCIM
+
+
+In each example you must define 4 variables to access the WEBMserver.
+Instead of editing each file you can write your values to ~/.cmpi-zypp.
+(one value per line, in the sequence above)
+(*** do 'chmod 600 ~/.cmpi-zypp' to protect the password! )
+
+# WBEMServer = 'https://localhost:5989'
+# login = 'root'
+# password = '*******'
+# namespace = 'root/cimv2'
+
diff --git a/examples/TODO b/examples/TODO
new file mode 100644
index 0000000..502bb65
--- /dev/null
+++ b/examples/TODO
@@ -0,0 +1,24 @@
+
+- list_packages.py works with a test repom but not with real life data from my system.
+ Have to check why.
+
+ Traceback (most recent call last):
+ File "./list_packages.py", line 32, in <module>
+ for package in system._GetAssociators( namespace, 'SUSE_InstalledSoftwareIdentity' ):
+ File "/usr/lib/python2.6/site-packages/powerCIM/cim.py", line 348, in _GetAssociators
+ resultRole=resultRole)
+ File "/usr/lib/python2.6/site-packages/powerCIM/meta.py", line 50, in myFunc
+ ret = func(self, *args,**kws)
+ File "/usr/lib/python2.6/site-packages/powerCIM/wbemconnection.py", line 231, in Associators
+ return self.connection.Associators(name,**params)
+ File "/usr/lib/python2.6/site-packages/pywbem/cim_operations.py", line 696, in Associators
+ **params)
+ File "/usr/lib/python2.6/site-packages/pywbem/cim_operations.py", line 178, in imethodcall
+ reply_dom = minidom.parseString(resp_xml)
+ File "/usr/lib/python2.6/site-packages/_xmlplus/dom/minidom.py", line 1925, in parseString
+ return expatbuilder.parseString(string)
+ File "/usr/lib/python2.6/site-packages/_xmlplus/dom/expatbuilder.py", line 942, in parseString
+ return builder.parseString(string)
+ File "/usr/lib/python2.6/site-packages/_xmlplus/dom/expatbuilder.py", line 223, in parseString
+ parser.Parse(string, True)
+ xml.parsers.expat.ExpatError: not well-formed (invalid token): line 31864, column 4
diff --git a/examples/list_packages.py b/examples/list_packages.py
new file mode 100755
index 0000000..37fcbf6
--- /dev/null
+++ b/examples/list_packages.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+#
+# Example application using powerCIM (http://en.opensuse.org/PowerCIM)
+#
+# It connects to given host and lists all inatalled and available
+# packages.
+#
+import os
+import powerCIM
+
+# Define those 4 variables or write their values to ~/.cmpi-zypp
+#
+# WBEMServer = 'https://localhost:5989'
+# login = 'root'
+# password = '*******'
+# namespace = 'root/cimv2'
+if os.path.exists('%s/.cmpi-zypp'%os.environ['HOME']):
+ with open( '%s/.cmpi-zypp'%os.environ['HOME'], 'r' ) as f:
+ WBEMServer = f.readline().rstrip()
+ login = f.readline().rstrip()
+ password = f.readline().rstrip()
+ namespace = f.readline().rstrip()
+
+# create factory/connection
+factory = powerCIM.WBEMFactory( WBEMServer, login, password, namespace )
+
+# get all installed packages
+print '===[installed packages]============================================================'
+systems = factory.EnumerateInstances( 'Linux_ComputerSystem' )
+for system in systems:
+ for package in system._GetAssociators( namespace, 'SUSE_InstalledSoftwareIdentity' ):
+ print package.InstanceID
+
+# get all packages
+print '===[all packages]============================================================'
+instances = factory.EnumerateInstances( 'SUSE_SoftwareIdentity' )
+for package in instances:
+ print package.InstanceID
+
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org