|
From: <bni...@us...> - 2008-09-29 22:56:49
|
Revision: 1053
http://omc.svn.sourceforge.net/omc/?rev=1053&view=rev
Author: bnicholes
Date: 2008-09-29 22:56:32 +0000 (Mon, 29 Sep 2008)
Log Message:
-----------
Add StartMode, Started and InstallDate properties
Modified Paths:
--------------
pybase/trunk/OMC_InitdService.py
Modified: pybase/trunk/OMC_InitdService.py
===================================================================
--- pybase/trunk/OMC_InitdService.py 2008-09-29 20:57:08 UTC (rev 1052)
+++ pybase/trunk/OMC_InitdService.py 2008-09-29 22:56:32 UTC (rev 1053)
@@ -38,7 +38,7 @@
import pywbem
from pywbem.cim_provider2 import CIMProvider2
import os
-from subprocess import call
+from subprocess import call, Popen, PIPE
from socket import getfqdn
def _blacklist(file):
@@ -79,6 +79,31 @@
return False
+#------------------------------------------------------------------------------
+def _get_rpm_install_date(fullpath):
+ try:
+ l=subprocess.Popen([r'/bin/rpm', '-qf', '--queryformat', \
+ '%{INSTALLTIME}', fullpath], \
+ stdout=subprocess.PIPE).communicate()[0]
+ if len(l):
+ return pywbem.CIMDateTime.fromtimestamp(long(l))
+ except:
+ pass
+ return None
+
+#------------------------------------------------------------------------------
+def _is_auto_start(name):
+ try:
+ l=subprocess.Popen([r'/usr/bin/find', '/etc/init.d', '-name', \
+ 'S[0-9][0-9]%s'%name], \
+ stdout=subprocess.PIPE).communicate()[0]
+ if l.endswith('\n'):
+ l = l[0:-1]
+ return len(l.split()) > 0
+ except:
+ pass
+ return False
+
class OMC_InitdServiceProvider(CIMProvider2):
"""Instrument the CIM class OMC_InitdService
@@ -103,7 +128,6 @@
#model['EnabledDefault'] = # TODO (type = pywbem.Uint16 self.Values.EnabledDefault) (default=2L)
#model['EnabledState'] = # TODO (type = pywbem.Uint16 self.Values.EnabledState) (default=5L)
#model['HealthState'] = # TODO (type = pywbem.Uint16 self.Values.HealthState)
- #model['InstallDate'] = # TODO (type = pywbem.CIMDateTime)
fullpath = '/etc/init.d/' + model['name']
if not filtered and (_blacklist(model['name']) or
not os.path.isfile(fullpath)):
@@ -119,6 +143,10 @@
model['Caption'] = caption
model['Description'] = caption
+ idt = _get_rpm_install_date(fullpath)
+ if idt:
+ model['InstallDate'] = idt
+
osts = []
cmd = fullpath + ' status'
st = call(cmd, shell=True)
@@ -136,6 +164,9 @@
if osts:
model['OperationalStatus'] = osts
+ model['StartMode'] = _is_auto_start(model['name']) and 'Automatic' or 'Manual'
+ svcStarted = (st == self.Values.ServiceStatus.Service_Running)
+ model['Started'] = svcStarted
#model['OperationalStatus'] = # TODO (type = [pywbem.Uint16,] self.Values.OperationalStatus)
#model['OtherEnabledState'] = # TODO (type = unicode)
#model['RequestedState'] = # TODO (type = pywbem.Uint16 self.Values.RequestedState) (default=12L)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|