summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorRadek Novacek <rnovacek@redhat.com>2012-08-27 15:01:46 +0200
committerRadek Novacek <rnovacek@redhat.com>2012-08-28 14:37:33 +0200
commit4721a6cb186e7d6908ff1f361d0bc81e182473ad (patch)
treed63f8e7b8db9bdbfca8b6c85d21642ad237fc6eb /examples
parent3333004967971ad1720b74da4ce09949f023852e (diff)
downloadopenlmi-providers-4721a6cb186e7d6908ff1f361d0bc81e182473ad.tar.gz
openlmi-providers-4721a6cb186e7d6908ff1f361d0bc81e182473ad.tar.xz
openlmi-providers-4721a6cb186e7d6908ff1f361d0bc81e182473ad.zip
Rename prefix from Cura_ to LMI_
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/test_account.py28
-rwxr-xr-xexamples/test_power.py2
-rwxr-xr-xexamples/test_service.py60
3 files changed, 75 insertions, 15 deletions
diff --git a/examples/test_account.py b/examples/test_account.py
index 5b88ca3..835e3d3 100755
--- a/examples/test_account.py
+++ b/examples/test_account.py
@@ -33,37 +33,37 @@ if len(sys.argv) > 5:
cliconn = pywbem.WBEMConnection(url, (username, password))
if command == "list_user":
-# Listintg users is simple, just query all instances from Cura_Account
+# Listintg users is simple, just query all instances from LMI_Account
# or select only by given Name
if parameter == "*":
- instances = cliconn.ExecQuery('WQL', 'select * from Cura_Account')
+ instances = cliconn.ExecQuery('WQL', 'select * from LMI_Account')
else:
- instances = cliconn.ExecQuery('WQL', 'select * from Cura_Account where Name = "%s"' % parameter)
+ instances = cliconn.ExecQuery('WQL', 'select * from LMI_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
+# Listintg gruops is simple, just query all instances from LMI_Group
# or select only by given Name
if parameter == "*":
- instances = cliconn.ExecQuery('WQL', 'select * from Cura_Group')
+ instances = cliconn.ExecQuery('WQL', 'select * from LMI_Group')
else:
- instances = cliconn.ExecQuery('WQL', 'select * from Cura_Group where Name = "%s"' % parameter)
+ instances = cliconn.ExecQuery('WQL', 'select * from LMI_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
+# Group members is a bit tricky. You need to select group (LMI_Group)
+# by given Name, then you need to select identities (LMI_Identity), which
+# are connected through LMI_MemberOfGroup to LMI_Group.
+# And finally select all accounts (LMI_Account) which are connected through
+# LMI_AssignedAccountIdentity with selected identities (this should be
# 1 to 1)
- groups = cliconn.ExecQuery('WQL', 'select * from Cura_Group where Name = "%s"' % parameter)
+ groups = cliconn.ExecQuery('WQL', 'select * from LMI_Group where Name = "%s"' % parameter)
for group in groups:
- identities = cliconn.Associators(group.path, AssocClass='Cura_MemberOfGroup')
+ identities = cliconn.Associators(group.path, AssocClass='LMI_MemberOfGroup')
for identity in identities:
- accounts = cliconn.Associators(identity.path, AssocClass='Cura_AssignedAccountIdentity')
+ accounts = cliconn.Associators(identity.path, AssocClass='LMI_AssignedAccountIdentity')
for account in accounts:
print account.tomof()
diff --git a/examples/test_power.py b/examples/test_power.py
index e4d6abc..93a0bcd 100755
--- a/examples/test_power.py
+++ b/examples/test_power.py
@@ -44,7 +44,7 @@ if len(computerSystems) > 1:
print >>sys.stderr, "More than one Linux_ComputerSystem instance found, don't know which to use."
sys.exit(3)
-print cliconn.InvokeMethod("RequestPowerStateChange", "Cura_PowerManagementService",
+print cliconn.InvokeMethod("RequestPowerStateChange", "LMI_PowerManagementService",
ManagedElement=computerSystems[0].path,
TimeoutPeriod=pywbem.datetime.now(),
PowerState=pywbem.Uint16(state),
diff --git a/examples/test_service.py b/examples/test_service.py
new file mode 100755
index 0000000..1883a37
--- /dev/null
+++ b/examples/test_service.py
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+import sys
+import pywbem
+
+commands = {
+ 'start': 'StartService',
+ 'stop': 'StopService',
+ 'reload': 'ReloadService',
+ 'restart': 'RestartService',
+ 'try-restart': 'TryRestartService',
+ 'condrestart': 'CondRestartService',
+ 'reload-or-restart': 'ReloadOrRestartService',
+ 'reload-or-try-restart': 'ReloadOrTryRestartService',
+ 'enable': 'TurnServiceOn',
+ 'disable': 'TurnServiceOff'
+}
+
+def sanitize(text):
+ return text.replace('"', '').replace("'", "")
+
+if len(sys.argv) < 5:
+ print """Usage: %s <address> <service> <operation> [username] [password]
+ Connect to CIM server at address and execute an operation on the service.
+
+Available states:
+ %s
+
+Example: %s https://127.0.0.1:5989 bluetooth start root redhat""" % (sys.argv[0], "\n ".join(commands.keys()), sys.argv[0])
+ sys.exit(1)
+
+url = sys.argv[1]
+service = sanitize(sys.argv[2])
+operation = sanitize(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))
+cliconn.debug = True
+
+services = cliconn.ExecQuery("WQL", "select * from LMI_Service where Name='%s'" % service)
+
+if len(services) == 0:
+ print >>sys.stderr, "Service %s doesn't exist" % service
+ sys.exit(2)
+
+if len(services) > 1:
+ print >>sys.stderr, "There are more services with name '%s', don't know which one use" % service
+ sys.exit(3)
+
+if operation not in commands.keys():
+ print >>sys.stderr, "Invalid operation '%s'" % operation
+ sys.exit(4)
+
+print cliconn.InvokeMethod(commands[operation], services[0].path)