summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2012-08-14 15:10:03 +0200
committerRoman Rakus <rrakus@redhat.com>2012-08-14 15:11:43 +0200
commite84ef5b99ff28063dcda246aa2746177bcc22e9b (patch)
treef9b8308d041857e3ab09ba49c23dc39909c5fdd7 /examples
parent8e14ce31d9c6ad81a337e51647ab9fa16e62cbe7 (diff)
downloadopenlmi-providers-e84ef5b99ff28063dcda246aa2746177bcc22e9b.tar.gz
openlmi-providers-e84ef5b99ff28063dcda246aa2746177bcc22e9b.tar.xz
openlmi-providers-e84ef5b99ff28063dcda246aa2746177bcc22e9b.zip
Account provider0.0.2
Listing of the users and groups Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/test_account.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/examples/test_account.py b/examples/test_account.py
new file mode 100755
index 0000000..5b88ca3
--- /dev/null
+++ b/examples/test_account.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+
+import sys
+import pywbem
+
+def usage():
+ print """Usage: %s <address> <command> <command parameter> [username] [password]
+ Connect to CIM server at address and issue a command on the machine.
+
+Available commands and their parameters:
+ list_user - list users, parameter is user name or * for all
+ list_group - list groups, parameter is group name or * for all
+ group_members - list members of group, parameter is group name
+
+Example: %s https://127.0.0.1:5989 list_user * root redhat""" % (sys.argv[0], sys.argv[0])
+
+
+if len(sys.argv) < 6:
+ usage()
+ sys.exit(1)
+
+url = sys.argv[1]
+command = sys.argv[2]
+parameter = sys.argv[3]
+
+username = None
+password = None
+if len(sys.argv) > 4:
+ username = sys.argv[4]
+if len(sys.argv) > 5:
+ password = sys.argv[5]
+
+cliconn = pywbem.WBEMConnection(url, (username, password))
+
+if command == "list_user":
+# Listintg users is simple, just query all instances from Cura_Account
+# or select only by given Name
+ if parameter == "*":
+ instances = cliconn.ExecQuery('WQL', 'select * from Cura_Account')
+ else:
+ instances = cliconn.ExecQuery('WQL', 'select * from Cura_Account where Name = "%s"' % parameter)
+ for instance in instances:
+ print instance.tomof()
+
+elif command == "list_group":
+# Listintg gruops is simple, just query all instances from Cura_Group
+# or select only by given Name
+ if parameter == "*":
+ instances = cliconn.ExecQuery('WQL', 'select * from Cura_Group')
+ else:
+ instances = cliconn.ExecQuery('WQL', 'select * from Cura_Group where Name = "%s"' % parameter)
+ for instance in instances:
+ print instance.tomof()
+
+elif command == "group_members":
+# Group members is a bit tricky. You need to select group (Cura_Group)
+# by given Name, then you need to select identities (Cura_Identity), which
+# are connected through Cura_MemberOfGroup to Cura_Group.
+# And finally select all accounts (Cura_Account) which are connected through
+# Cura_AssignedAccountIdentity with selected identities (this should be
+# 1 to 1)
+ groups = cliconn.ExecQuery('WQL', 'select * from Cura_Group where Name = "%s"' % parameter)
+ for group in groups:
+ identities = cliconn.Associators(group.path, AssocClass='Cura_MemberOfGroup')
+ for identity in identities:
+ accounts = cliconn.Associators(identity.path, AssocClass='Cura_AssignedAccountIdentity')
+ for account in accounts:
+ print account.tomof()
+
+
+else:
+# unknown command
+ print "Unknown command", command
+ usage()
+ sys.exit(1)