From 4721a6cb186e7d6908ff1f361d0bc81e182473ad Mon Sep 17 00:00:00 2001 From: Radek Novacek Date: Mon, 27 Aug 2012 15:01:46 +0200 Subject: Rename prefix from Cura_ to LMI_ --- examples/test_service.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 examples/test_service.py (limited to 'examples/test_service.py') 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
[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) -- cgit