forked from sgallagher/openlmi-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenlmi-services-demo.py
57 lines (44 loc) · 1.51 KB
/
openlmi-services-demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# !/usr/bin/env lmishell
'''
Created on Apr 8, 2013
@author: sgallagh
'''
import sys
import time
import demoutils.democolor as democolor
def display_service_status(service):
sys.stdout.write("{0} status: ".format(service.Name))
print democolor.hilite(service.Status, democolor.XTERM_CYAN \
if service.Started else democolor.XTERM_RED)
# Machine to contact
server = "openlmi-demo.example.com"
username = "root"
password = "redhat"
# Connect to the example VM
print democolor.hilite("\nConnecting to remote server \"{0}\"".format(server),
democolor.XTERM_WHITE)
c = connect(server, username, password)
# Shorthand the cimv2 namespace
ns = c.root.cimv2
# Display all services configured to start by default and their current status
print democolor.hilite("== Interrogating services configured to start at boot "
"Using OpenLMI ==",
democolor.XTERM_MAGENTA, True)
for service in ns.LMI_Service.instances():
if service.EnabledDefault == 2: # 2 means enabled, 3 means disabled
display_service_status(service)
time.sleep(1)
time.sleep(2)
print democolor.hilite("\n== Restarting auditd via OpenLMI ==",
democolor.XTERM_MAGENTA, True)
auditd = ns.LMI_Service.first_instance(key="Name", value="auditd")
display_service_status(auditd)
time.sleep(3)
print "Stopping auditd..."
auditd.StopService()
time.sleep(3)
display_service_status(auditd)
print "Starting auditd..."
auditd.StartService()
time.sleep(3)
display_service_status(auditd)