|
From: <jc...@us...> - 2007-12-18 18:14:56
|
Revision: 517
http://omc.svn.sourceforge.net/omc/?rev=517&view=rev
Author: jcarey
Date: 2007-12-18 10:15:00 -0800 (Tue, 18 Dec 2007)
Log Message:
-----------
implemented the time zone setting data and association to service
Modified Paths:
--------------
pybase/trunk/OMC_TimeService-peg.reg
pybase/trunk/OMC_TimeService.py
Modified: pybase/trunk/OMC_TimeService-peg.reg
===================================================================
--- pybase/trunk/OMC_TimeService-peg.reg 2007-12-18 03:34:49 UTC (rev 516)
+++ pybase/trunk/OMC_TimeService-peg.reg 2007-12-18 18:15:00 UTC (rev 517)
@@ -53,7 +53,6 @@
ProviderType = {2,3}; // Instance, Associator
};
-/*
instance of PG_ProviderCapabilities
{
CapabilityID = "OMC_TimeService_Capability3";
@@ -74,6 +73,7 @@
ProviderType = {2,3}; // Instance, Associator
};
+/*
instance of PG_ProviderCapabilities
{
CapabilityID = "OMC_TimeService_Capability7";
Modified: pybase/trunk/OMC_TimeService.py
===================================================================
--- pybase/trunk/OMC_TimeService.py 2007-12-18 03:34:49 UTC (rev 516)
+++ pybase/trunk/OMC_TimeService.py 2007-12-18 18:15:00 UTC (rev 517)
@@ -186,6 +186,7 @@
else:
os.unlink('/etc/ntp.conf')
os.rename(tfname, '/etc/ntp.conf')
+ os.chmod('/etc/ntp.conf', 0644)
return modified
except Exception,einst:
tfile.close()
@@ -232,6 +233,7 @@
else:
os.unlink('/etc/ntp.conf')
os.rename(tfname, '/etc/ntp.conf')
+ os.chmod('/etc/ntp.conf', 0644)
return modified
except Exception,einst:
tfile.close()
@@ -310,6 +312,7 @@
else:
os.unlink('/etc/sysconfig/clock')
os.rename(tfname, '/etc/sysconfig/clock')
+ os.chmod('/etc/sysconfig/clock', 0644)
except Exception,einst:
tfile.close()
cfile.close()
@@ -797,13 +800,194 @@
namespace=object_name.namespace);
model['Antecedent'] = _fill_service_instance(ref, True)
yield model
-
## end of class OMC_TimeServiceAccessBySAPProvider
-def get_providers(env):
- return {'OMC_TimeServiceAccessBySAP': omc_timeserviceaccessbysap_prov}
+class OMC_TimeZoneSettingDataProvider(pywbem.CIMProvider):
+ """Instrument the CIM class OMC_TimeZoneSettingData"""
+ def __init__ (self, env):
+ logger = env.get_logger()
+ logger.log_debug('Initializing provider %s from %s' \
+ % (self.__class__.__name__, __file__))
+
+ def get_instance(self, env, model, cim_class):
+ logger = env.get_logger()
+ logger.log_debug('Entering %s.get_instance()' \
+ % self.__class__.__name__)
+ try:
+ iid = model['InstanceID']
+ except KeyError:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
+ if iid.lower() != 'omc:timezone':
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
+ tzcc = _clock_conf_get_time_zone()
+ if not tzcc:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
+ model['ElementName'] = 'omc:timezone'
+ model['UTCHardwareClock'] = tzcc[0]
+ model['TimeZone'] = tzcc[1]
+ model['Caption'] = 'Time Zone Setting'
+ model['Description'] = 'Local time zone for the system'
+ return model
+
+ def enum_instances(self, env, model, cim_class, keys_only):
+ logger = env.get_logger()
+ logger.log_debug('Entering %s.enum_instances()' \
+ % self.__class__.__name__)
+ tzcc = _clock_conf_get_time_zone()
+ if not tzcc:
+ return
+ model['InstanceID'] = 'omc:timezone'
+ if not keys_only:
+ model['ElementName'] = 'omc:timezone'
+ model['UTCHardwareClock'] = tzcc[0]
+ model['TimeZone'] = tzcc[1]
+ model['Caption'] = 'Time Zone Setting'
+ model['Description'] = 'Local time zone for the system'
+ yield model
+
+ def set_instance(self, env, instance, previous_instance, cim_class):
+ logger = env.get_logger()
+ logger.log_debug('Entering %s.set_instance()' \
+ % self.__class__.__name__)
+ if os.geteuid() != 0:
+ raise pywbem.CIMError(pywbem.CIM_ERR_ACCESS_DENIED)
+ if previous_instance:
+ for k,v in instance.properties.items():
+ previous_instance[k] = v
+ instance = previous_instance
+ try:
+ iid = instance['InstanceID']
+ except KeyError:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
+ if iid.lower() != 'omc:timezone':
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
+
+ if 'timezone' not in instance or not instance['timezone']:
+ raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
+ "'TimeZone' is a required property")
+ if 'utchardwareclock' not in instance:
+ raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
+ "'UTCHardwareClass' is a required property")
+ time_zone = instance['timezone']
+ is_utc = instance['utchardwareclock']
+ tzcc = _clock_conf_get_time_zone()
+ if not tzcc:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
+ old_time_zone = tzcc[1]
+ # Verify zone info
+ zone_file = '/usr/share/zoneinfo/%s' % time_zone
+ if not os.path.exists(zone_file):
+ raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
+ '%s is not a valid time zone specification' % instance['timezone'])
+
+ cmd = '/usr/sbin/zic -l %s' % time_zone
+ cc = os.system(cmd)
+ if cc:
+ try:
+ # Try to revert back to old
+ os.system('/usr/sbin/zic -l %s' % old_time_zone)
+ except:
+ pass
+ raise pywbem.CIMError(pywbem.CIM_ERR_FAILED,
+ 'Failed to execute command %s' % cmd)
+
+ try:
+ _clock_conf_modify(is_utc, time_zone)
+ except Exception,einst:
+ # Try to recover old
+ try:
+ os.system('/usr/sbin/zic -l %s' % old_time_zone)
+ except:
+ pass
+ raise einst
+ return instance
+
+ def delete_instance(self, env, instance_name):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
+
+## end of class OMC_TimeZoneSettingDataProvider
+
+class OMC_TimeServiceTimeZoneSettingDataProvider(pywbem.CIMProvider):
+ """Instrument the CIM class OMC_TimeServiceTimeZoneSettingData"""
+ def __init__ (self, env):
+ logger = env.get_logger()
+ logger.log_debug('Initializing provider %s from %s' \
+ % (self.__class__.__name__, __file__))
+
+ def get_instance(self, env, model, cim_class):
+ logger = env.get_logger()
+ logger.log_debug('Entering %s.get_instance()' \
+ % self.__class__.__name__)
+ # TODO
+ return model
+
+ def enum_instances(self, env, model, cim_class, keys_only):
+ # TODO
+ if False:
+ yield None
+
+ def set_instance(self, env, instance, previous_instance, cim_class):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
+
+ def delete_instance(self, env, instance_name):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED)
+
+ def references(self, env, object_name, model, assoc_class,
+ result_class_name, role, result_role, keys_only):
+ print '#### my references called'
+ logger = env.get_logger()
+ logger.log_debug('Entering %s.references()' \
+ % self.__class__.__name__)
+ ch = env.get_cimom_handle()
+ if object_name.classname.lower() == 'omc_systemtimeservice':
+ print '#### my references the service!'
+ if role and role.lower() != 'managedelement':
+ return
+ if result_role and result_role.lower() != 'settingdata':
+ return
+ if result_class_name:
+ if not pywbem.is_subclass(ch, object_name.namespace,
+ sub='omc_timezonesettingdata',
+ super=result_class_name):
+ return
+ if not _is_service_ref(object_name):
+ return
+ model['managedelement'] = object_name
+ model['settingdata'] = pywbem.CIMInstanceName(
+ classname='OMC_TimeZoneSettingData',
+ namespace=object_name.namespace,
+ keybindings={'InstanceID':'omc:timezone'})
+ yield model
+ elif object_name.classname.lower() == 'omc_timezonesettingdata':
+ if role and role.lower() != 'settingdata':
+ return
+ if result_role and result_role.lower() != 'managedelement':
+ return
+ if result_class_name:
+ if not pywbem.is_subclass(ch, object_name.namespace,
+ sub='omc_systemtimeservice',
+ super=result_class_name):
+ return
+ try:
+ print '### object_name[instanceid] =',object_name['instanceid']
+ if object_name['InstanceID'].lower() != 'omc:timezone':
+ print '### No match on instance id'
+ return
+ except KeyError:
+ print '### KeyError on instance id'
+ return
+ model['settingdata'] = object_name
+ ref = pywbem.CIMInstanceName(classname='OMC_SystemTimeService',
+ namespace=object_name.namespace)
+ model['managedelement'] = _fill_service_instance(ref, True)
+ yield model
+
+## end of class OMC_TimeServiceTimeZoneSettingDataProvider
+
def get_providers(env):
+ omc_timeservicetimezonesettingdata_prov = OMC_TimeServiceTimeZoneSettingDataProvider(env)
+ omc_timezonesettingdata_prov = OMC_TimeZoneSettingDataProvider(env)
omc_timeserviceaccessbysap_prov = OMC_TimeServiceAccessBySAPProvider(env)
omc_remotetimeserviceport_prov = OMC_RemoteTimeServicePortProvider(env)
omc_systemtimeservice_prov = OMC_SystemTimeServiceProvider(env)
@@ -811,5 +995,7 @@
return {'OMC_SystemTimeService': omc_systemtimeservice_prov,
'OMC_HostedTimeService': omc_hostedtimeservice_prov,
'OMC_RemoteTimeServicePort': omc_remotetimeserviceport_prov,
- 'OMC_TimeServiceAccessBySAP': omc_timeserviceaccessbysap_prov}
+ 'OMC_TimeServiceAccessBySAP': omc_timeserviceaccessbysap_prov,
+ 'OMC_TimeZoneSettingData': omc_timezonesettingdata_prov,
+ 'OMC_TimeServiceTimeZoneSettingData': omc_timeservicetimezonesettingdata_prov}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|