|
From: <ba...@us...> - 2007-12-06 01:44:38
|
Revision: 504
http://omc.svn.sourceforge.net/omc/?rev=504&view=rev
Author: bartw
Date: 2007-12-05 17:44:43 -0800 (Wed, 05 Dec 2007)
Log Message:
-----------
added some more OS properties
Modified Paths:
--------------
pybase/trunk/OMC_OperatingSystem.py
Modified: pybase/trunk/OMC_OperatingSystem.py
===================================================================
--- pybase/trunk/OMC_OperatingSystem.py 2007-11-27 00:20:59 UTC (rev 503)
+++ pybase/trunk/OMC_OperatingSystem.py 2007-12-06 01:44:43 UTC (rev 504)
@@ -81,6 +81,26 @@
logger.log_debug('Entering %s.get_instance()' \
% self.__class__.__name__)
+ meminfo = {}
+ fo = open('/proc/meminfo', 'r')
+ for line in fo.readlines():
+ sline = line.split(':')
+ meminfo[sline[0].strip()] = int(sline[1].split()[0])
+
+ uex = model.update_existing
+
+ uex(TotalSwapSpaceSize = pywbem.Uint64(meminfo['SwapTotal']))
+ uex(FreePhysicalMemory = pywbem.Uint64(meminfo['MemFree']))
+ uex(FreeVirtualMemory = pywbem.Uint64(meminfo['MemFree'] +
+ meminfo['Buffers'] + meminfo['Cached']))
+ uex(TotalVirtualMemorySize = pywbem.Uint64(meminfo['MemTotal'] +
+ meminfo['SwapTotal']))
+
+ fnames = os.listdir('/proc')
+ numprocs = len([x for x in fnames if x.isdigit()])
+ uex(NumberOfProcesses = pywbem.Uint32(numprocs))
+
+
#model['Caption'] = # TODO (type = unicode)
#model['CurrentTimeZone'] = # TODO (type = pywbem.Sint16)
#model['Description'] = # TODO (type = unicode)
@@ -88,9 +108,7 @@
#model['ElementName'] = # TODO (type = unicode)
#model['EnabledDefault'] = # TODO (type = pywbem.Uint16 self.Values.EnabledDefault) (default=2L)
#model['EnabledState'] = # TODO (type = pywbem.Uint16 self.Values.EnabledState) (default=5L)
- #model['FreePhysicalMemory'] = # TODO (type = pywbem.Uint64)
#model['FreeSpaceInPagingFiles'] = # TODO (type = pywbem.Uint64)
- #model['FreeVirtualMemory'] = # TODO (type = pywbem.Uint64)
#model['HealthState'] = # TODO (type = pywbem.Uint16 self.Values.HealthState)
#model['InstallDate'] = # TODO (type = pywbem.CIMDateTime)
#model['LastBootUpTime'] = # TODO (type = pywbem.CIMDateTime)
@@ -99,10 +117,9 @@
#model['MaxProcessesPerUser'] = # TODO (type = pywbem.Uint32)
#model['MaxProcessMemorySize'] = # TODO (type = pywbem.Uint64)
#model['NumberOfLicensedUsers'] = # TODO (type = pywbem.Uint32)
- #model['NumberOfProcesses'] = # TODO (type = pywbem.Uint32)
#model['NumberOfUsers'] = # TODO (type = pywbem.Uint32)
#model['OperationalStatus'] = # TODO (type = [pywbem.Uint16,] self.Values.OperationalStatus)
- model['OSType'] = self.Values.OSType.LINUX
+ uex(OSType = self.Values.OSType.LINUX)
#model['OtherEnabledState'] = # TODO (type = unicode)
#model['OtherTypeDescription'] = # TODO (type = unicode)
#model['RequestedState'] = # TODO (type = pywbem.Uint16 self.Values.RequestedState) (default=12L)
@@ -110,8 +127,6 @@
#model['Status'] = # TODO (type = unicode self.Values.Status)
#model['StatusDescriptions'] = # TODO (type = [unicode,])
#model['TimeOfLastStateChange'] = # TODO (type = pywbem.CIMDateTime)
- #model['TotalSwapSpaceSize'] = # TODO (type = pywbem.Uint64)
- #model['TotalVirtualMemorySize'] = # TODO (type = pywbem.Uint64)
#model['TotalVisibleMemorySize'] = # TODO (type = pywbem.Uint64)
#model['Version'] = # TODO (type = unicode)
return model
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2007-12-07 06:02:51
|
Revision: 506
http://omc.svn.sourceforge.net/omc/?rev=506&view=rev
Author: bartw
Date: 2007-12-06 22:02:50 -0800 (Thu, 06 Dec 2007)
Log Message:
-----------
added some more properties
Modified Paths:
--------------
pybase/trunk/OMC_OperatingSystem.py
Modified: pybase/trunk/OMC_OperatingSystem.py
===================================================================
--- pybase/trunk/OMC_OperatingSystem.py 2007-12-07 00:08:48 UTC (rev 505)
+++ pybase/trunk/OMC_OperatingSystem.py 2007-12-07 06:02:50 UTC (rev 506)
@@ -37,6 +37,9 @@
import pywbem
from pywbem import CIMProvider
from socket import getfqdn
+import os
+import time
+from subprocess import Popen, PIPE
def get_os_path(ns):
return pywbem.CIMInstanceName(classname='OMC_OperatingSystem',
@@ -86,6 +89,7 @@
for line in fo.readlines():
sline = line.split(':')
meminfo[sline[0].strip()] = int(sline[1].split()[0])
+ fo.close()
uex = model.update_existing
@@ -93,32 +97,45 @@
uex(FreePhysicalMemory = pywbem.Uint64(meminfo['MemFree']))
uex(FreeVirtualMemory = pywbem.Uint64(meminfo['MemFree'] +
meminfo['Buffers'] + meminfo['Cached']))
+ uex(TotalVisibleMemorySize = pywbem.Uint64(meminfo['MemTotal']))
uex(TotalVirtualMemorySize = pywbem.Uint64(meminfo['MemTotal'] +
meminfo['SwapTotal']))
fnames = os.listdir('/proc')
numprocs = len([x for x in fnames if x.isdigit()])
uex(NumberOfProcesses = pywbem.Uint32(numprocs))
+ uex(CurrentTimeZone = pywbem.Sint16(time.timezone / 60))
+ uex(LocalDateTime = pywbem.CIMDateTime.now())
+ fo = open('/proc/uptime', 'r')
+ uex(LastBootUpTime = pywbem.CIMDateTime.fromtimestamp(
+ time.time() - float(fo.read().split()[0])))
+ fo.close()
+ if os.path.exists('/etc/SuSE-release'):
+ fo = open('/etc/SuSE-release', 'r')
+ version = fo.readline().strip()
+ uex(Version = version)
+ uex(ElementName = version)
+ uex(Description = version)
+ uex(Caption = version)
+ fo.close()
+ install_time = Popen(['rpm', '-qf','/etc/SuSE-release',
+ '--queryformat','%{INSTALLTIME}'],
+ stdout=PIPE).communicate()[0]
+ uex(InstallDate = pywbem.CIMDateTime.fromtimestamp(int(install_time)))
+ # TODO non-SUSE distros
- #model['Caption'] = # TODO (type = unicode)
- #model['CurrentTimeZone'] = # TODO (type = pywbem.Sint16)
- #model['Description'] = # TODO (type = unicode)
- #model['Distributed'] = # TODO (type = bool)
- #model['ElementName'] = # TODO (type = unicode)
+ uex(Distributed = True)
#model['EnabledDefault'] = # TODO (type = pywbem.Uint16 self.Values.EnabledDefault) (default=2L)
- #model['EnabledState'] = # TODO (type = pywbem.Uint16 self.Values.EnabledState) (default=5L)
+ uex(EnabledState = self.Values.EnabledState.Enabled)
#model['FreeSpaceInPagingFiles'] = # TODO (type = pywbem.Uint64)
- #model['HealthState'] = # TODO (type = pywbem.Uint16 self.Values.HealthState)
- #model['InstallDate'] = # TODO (type = pywbem.CIMDateTime)
- #model['LastBootUpTime'] = # TODO (type = pywbem.CIMDateTime)
- #model['LocalDateTime'] = # TODO (type = pywbem.CIMDateTime)
+ uex(HealthState = self.Values.HealthState.OK)
#model['MaxNumberOfProcesses'] = # TODO (type = pywbem.Uint32)
#model['MaxProcessesPerUser'] = # TODO (type = pywbem.Uint32)
#model['MaxProcessMemorySize'] = # TODO (type = pywbem.Uint64)
#model['NumberOfLicensedUsers'] = # TODO (type = pywbem.Uint32)
#model['NumberOfUsers'] = # TODO (type = pywbem.Uint32)
- #model['OperationalStatus'] = # TODO (type = [pywbem.Uint16,] self.Values.OperationalStatus)
+ uex(OperationalStatus = [self.Values.OperationalStatus.OK])
uex(OSType = self.Values.OSType.LINUX)
#model['OtherEnabledState'] = # TODO (type = unicode)
#model['OtherTypeDescription'] = # TODO (type = unicode)
@@ -127,8 +144,6 @@
#model['Status'] = # TODO (type = unicode self.Values.Status)
#model['StatusDescriptions'] = # TODO (type = [unicode,])
#model['TimeOfLastStateChange'] = # TODO (type = pywbem.CIMDateTime)
- #model['TotalVisibleMemorySize'] = # TODO (type = pywbem.Uint64)
- #model['Version'] = # TODO (type = unicode)
return model
def enum_instances(self, env, model, cim_class, keys_only):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jc...@us...> - 2007-12-18 23:37:44
|
Revision: 522
http://omc.svn.sourceforge.net/omc/?rev=522&view=rev
Author: jcarey
Date: 2007-12-18 15:37:41 -0800 (Tue, 18 Dec 2007)
Log Message:
-----------
Changed methods to only allow root...
Modified Paths:
--------------
pybase/trunk/OMC_OperatingSystem.py
Modified: pybase/trunk/OMC_OperatingSystem.py
===================================================================
--- pybase/trunk/OMC_OperatingSystem.py 2007-12-18 23:35:00 UTC (rev 521)
+++ pybase/trunk/OMC_OperatingSystem.py 2007-12-18 23:37:41 UTC (rev 522)
@@ -177,60 +177,11 @@
def cim_method_requeststatechange(self, env, object_name, method,
param_requestedstate,
param_timeoutperiod):
- """Implements OMC_OperatingSystem.RequestStateChange()
-
- Requests that the state of the element be changed to the value
- specified in the RequestedState parameter. When the requested
- state change takes place, the EnabledState and RequestedState of
- the element will be the same. Invoking the RequestStateChange
- method multiple times could result in earlier requests being
- overwritten or lost. If 0 is returned, then the task completed
- successfully and the use of ConcreteJob was not required. If 4096
- (0x1000) is returned, then the task will take some time to
- complete, ConcreteJob will be created, and its reference returned
- in the output parameter Job. Any other return code indicates an
- error condition.
-
- Keyword arguments:
- env -- Provider Environment (pycimmb.ProviderEnvironment)
- object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method RequestStateChange()
- should be invoked.
- method -- A pywbem.CIMMethod representing the method meta-data
- param_requestedstate -- The input parameter RequestedState (type pywbem.Uint16 self.Values.RequestStateChange.RequestedState)
- The state requested for the element. This information will be
- placed into the RequestedState property of the instance if the
- return code of the RequestStateChange method is 0 ('Completed
- with No Error'), 3 ('Timeout'), or 4096 (0x1000) ('Job
- Started'). Refer to the description of the EnabledState and
- RequestedState properties for the detailed explanations of the
- RequestedState values.
-
- param_timeoutperiod -- The input parameter TimeoutPeriod (type pywbem.CIMDateTime)
- A timeout period that specifies the maximum amount of time that
- the client expects the transition to the new state to take.
- The interval format must be used to specify the TimeoutPeriod.
- A value of 0 or a null parameter indicates that the client has
- no time requirements for the transition. If this property
- does not contain 0 or null and the implementation does not
- support this parameter, a return code of 'Use Of Timeout
- Parameter Not Supported' must be returned.
-
-
- Returns a two-tuple containing the return value (type pywbem.Uint32 self.Values.RequestStateChange)
- and a dictionary with the out-parameters
-
- Output parameters:
- Job -- (type REF (pywbem.CIMInstanceName(classname='CIM_ConcreteJob', ...))
- Reference to the job (can be null if the task is completed).
-
-
- """
-
logger = env.get_logger()
logger.log_debug('Entering %s.cim_method_requeststatechange()' \
% self.__class__.__name__)
-
+ if os.geteuid() != 0:
+ raise pywbem.CIMError(pywbem.CIM_ERR_ACCESS_DENIED)
rstate = int(param_requestedstate)
if rstate == 3: # Disable
logger.log_info('OS Disabled State Requested. Shutting Down now...')
@@ -261,32 +212,11 @@
return (pywbem.Uint32(1), {})
def cim_method_reboot(self, env, object_name, method):
- """Implements OMC_OperatingSystem.Reboot()
-
- Requests a reboot of the OperatingSystem. The return value should
- be 0 if the request was successfully executed, 1 if the request is
- not supported and some other value if an error occurred. In a
- subclass, the set of possible return codes could be specified,
- using a ValueMap qualifier on the method. The strings to which the
- ValueMap contents are 'translated' may also be specified in the
- subclass as a Values array qualifier.
-
- Keyword arguments:
- env -- Provider Environment (pycimmb.ProviderEnvironment)
- object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method Reboot()
- should be invoked.
- method -- A pywbem.CIMMethod representing the method meta-data
-
- Returns a two-tuple containing the return value (type pywbem.Uint32)
- and a dictionary with the out-parameters
-
- Output parameters: none
-
- """
logger = env.get_logger()
logger.log_debug('Entering %s.cim_method_reboot()' \
% self.__class__.__name__)
+ if os.geteuid() != 0:
+ raise pywbem.CIMError(pywbem.CIM_ERR_ACCESS_DENIED)
logger.log_info('OMC_OperatingSystem.reboot called. '
'Rebooting system now')
if os.system('/sbin/shutdown -r now'):
@@ -294,38 +224,11 @@
return ('Success', {})
def cim_method_shutdown(self, env, object_name, method):
- """Implements OMC_OperatingSystem.Shutdown()
-
- Requests a shutdown of the OperatingSystem. The return value should
- be 0 if the request was successfully executed, 1 if the request is
- not supported and some other value if an error occurred. It is up
- to the implementation or subclass of OperatingSystem to establish
- dependencies between the Shutdown and Reboot methods, and for
- example, to provide more sophisticated capabilities such as
- scheduled shutdown/ reboot, etc. In a subclass, the set of
- possible return codes could be specified, using a ValueMap
- qualifier on the method. The strings to which the ValueMap
- contents are 'translated' may also be specified in the subclass as
- a Values array qualifier.
-
- Keyword arguments:
- env -- Provider Environment (pycimmb.ProviderEnvironment)
- object_name -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method Shutdown()
- should be invoked.
- method -- A pywbem.CIMMethod representing the method meta-data
-
- Returns a two-tuple containing the return value (type pywbem.Uint32)
- and a dictionary with the out-parameters
-
- Output parameters: none
-
- """
-
logger = env.get_logger()
logger.log_debug('Entering %s.cim_method_shutdown()' \
% self.__class__.__name__)
-
+ if os.geteuid() != 0:
+ raise pywbem.CIMError(pywbem.CIM_ERR_ACCESS_DENIED)
logger.log_info('OMC_OperatingSystem.shutdown called. '
'shutdown system now')
if os.system('/sbin/shutdown -h now'):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2008-04-07 22:43:08
|
Revision: 553
http://omc.svn.sourceforge.net/omc/?rev=553&view=rev
Author: bartw
Date: 2008-04-07 15:43:11 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
implemented enum_instances on OMC_RunningOS and OMC_InstalledOS
Modified Paths:
--------------
pybase/trunk/OMC_OperatingSystem.py
Modified: pybase/trunk/OMC_OperatingSystem.py
===================================================================
--- pybase/trunk/OMC_OperatingSystem.py 2008-04-07 22:17:46 UTC (rev 552)
+++ pybase/trunk/OMC_OperatingSystem.py 2008-04-07 22:43:11 UTC (rev 553)
@@ -452,21 +452,33 @@
logger.log_debug('Entering %s.enum_instances()' \
% self.__class__.__name__)
- while False: # TODO more instances?
- # TODO fetch system resource
- # Key properties
- #model['GroupComponent'] = # TODO (type = REF (pywbem.CIMInstanceName(classname='CIM_ComputerSystem', ...))
- #model['PartComponent'] = # TODO (type = REF (pywbem.CIMInstanceName(classname='OMC_OperatingSystem', ...))
- if keys_only:
- yield model
- else:
- try:
- yield self.get_instance(env, model, cim_class)
- except pywbem.CIMError, (num, msg):
- if num not in (pywbem.CIM_ERR_NOT_FOUND,
- pywbem.CIM_ERR_ACCESS_DENIED):
- raise
+ os = pywbem.CIMInstanceName('OMC_OperatingSystem',
+ namespace=model.path.namespace,
+ keybindings={'CSCreationClassName':'OMC_UnitaryComputerSystem',
+ 'CreationClassName':'OMC_OperatingSystem',
+ 'Name':'Linux',
+ 'CSName':getfqdn()})
+ cs = pywbem.CIMInstanceName('OMC_UnitaryComputerSystem',
+ namespace=model.path.namespace,
+ keybindings={'CreationClassName':'OMC_UnitaryComputerSystem',
+ 'Name':getfqdn()})
+ if model.classname.lower() == 'omc_installedos':
+ model['GroupComponent'] = cs
+ model['PartComponent'] = os
+ else:
+ model['Dependent'] = cs
+ model['Antecedent'] = os
+ if keys_only:
+ yield model
+ else:
+ try:
+ yield self.get_instance(env, model, cim_class)
+ except pywbem.CIMError, (num, msg):
+ if num not in (pywbem.CIM_ERR_NOT_FOUND,
+ pywbem.CIM_ERR_ACCESS_DENIED):
+ raise
+
def set_instance(self, env, instance, previous_instance, cim_class):
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ba...@us...> - 2008-04-10 22:26:02
|
Revision: 562
http://omc.svn.sourceforge.net/omc/?rev=562&view=rev
Author: bartw
Date: 2008-04-10 15:26:05 -0700 (Thu, 10 Apr 2008)
Log Message:
-----------
fixed timezone and some memory related properties
Modified Paths:
--------------
pybase/trunk/OMC_OperatingSystem.py
Modified: pybase/trunk/OMC_OperatingSystem.py
===================================================================
--- pybase/trunk/OMC_OperatingSystem.py 2008-04-10 17:59:58 UTC (rev 561)
+++ pybase/trunk/OMC_OperatingSystem.py 2008-04-10 22:26:05 UTC (rev 562)
@@ -80,21 +80,23 @@
uex = model.update_existing
- uex(TotalSwapSpaceSize = pywbem.Uint64(meminfo['SwapTotal']))
- uex(FreePhysicalMemory = pywbem.Uint64(meminfo['MemFree']))
+ #uex(TotalSwapSpaceSize = pywbem.Uint64(meminfo['SwapTotal']))
+ uex(TotalSwapSpaceSize = None) # not distinguished from page files.
+ uex(FreePhysicalMemory = pywbem.Uint64(meminfo['MemFree'] +
+ meminfo['Buffers'] + meminfo['Cached']))
uex(FreeVirtualMemory = pywbem.Uint64(meminfo['MemFree'] +
- meminfo['Buffers'] + meminfo['Cached']))
+ meminfo['Buffers'] + meminfo['Cached'] +
+ meminfo['SwapFree']))
uex(TotalVisibleMemorySize = pywbem.Uint64(meminfo['MemTotal']))
uex(TotalVirtualMemorySize = pywbem.Uint64(meminfo['MemTotal'] +
meminfo['SwapTotal']))
- uex(FreeSpaceInPagingFiles = pywbem.Uint64(int(meminfo['SwapFree']) / 1024))
- uex(SizeStoredInPagingFiles = pywbem.Uint64(meminfo['SwapTotal']/1024))
+ uex(FreeSpaceInPagingFiles = pywbem.Uint64(meminfo['SwapFree']))
+ uex(SizeStoredInPagingFiles = pywbem.Uint64(meminfo['SwapTotal']))
fnames = os.listdir('/proc')
numprocs = len([x for x in fnames if x.isdigit()])
uex(NumberOfProcesses = pywbem.Uint32(numprocs))
- uex(CurrentTimeZone = pywbem.Sint16(
- (time.mktime(time.localtime()) - time.mktime(time.gmtime())) / 60))
+ uex(CurrentTimeZone = pywbem.Sint16(pywbem.CIMDateTime.get_local_utcoffset()))
uex(LocalDateTime = pywbem.CIMDateTime.now())
fo = open('/proc/uptime', 'r')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|