本文整理汇总了Python中mpx.lib.persistent.PersistentDataObject.filename方法的典型用法代码示例。如果您正苦于以下问题:Python PersistentDataObject.filename方法的具体用法?Python PersistentDataObject.filename怎么用?Python PersistentDataObject.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpx.lib.persistent.PersistentDataObject
的用法示例。
在下文中一共展示了PersistentDataObject.filename方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
def start(self):
self.managernode = self.as_node(self.manager)
self.synclock.acquire()
try:
alarmsname = '%s (%s)' % (self.name, 'alarms')
eventsname = '%s (%s)' % (self.name, 'events')
self.alarms = PersistentDictionary(alarmsname,
encode=self.encode,
decode=self.decode)
self.events = PersistentDictionary(eventsname,
encode=self.encode,
decode=self.decode)
# Migrate PDO data from old style persistence.
pdodata = PersistentDataObject(self, dmtype=GC_NEVER)
if os.path.exists(pdodata.filename()):
msglog.log('broadway', msglog.types.INFO,
"Migrating previous alarm and event data")
pdodata.events = {}
pdodata.alarms = {}
pdodata.load()
migrate(pdodata, self.decode)
self.rebuildstorage()
pdodata.destroy()
del(pdodata)
finally:
self.synclock.release()
self.securitymanager = self.as_node('/services/Security Manager')
register = self.managernode.register_for_type
self.sub = register(self.handle_event, StateEvent)
self.running.set()
super(AlarmConfigurator, self).start()
示例2: start
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
def start(self):
filename = '%s (%s)' % (self.name, 'triggers')
self.manager = self.nodespace.as_node(self.manager)
self._pdo_lock.acquire()
try:
if self._triggers is None:
self._triggers = PersistentDictionary(
filename, encode=None, decode=None)
if not self._triggers:
pdodata = PersistentDataObject(self, dmtype=GC_NEVER)
if os.path.exists(pdodata.filename()):
msglog.log('broadway', msglog.types.INFO,
"Migrating previous trigger data.")
pdodata.triggers = {}
pdodata.load()
self._triggers.update(pdodata.triggers)
pdodata.destroy()
del(pdodata)
self._loadtriggers()
if self.secured:
self.security_manager = self.as_node("/services/Security Manager")
else:
self.security_manager = None
finally:
self._pdo_lock.release()
return super(TriggersConfigurator, self).start()
示例3: start
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
def start(self):
try:
self._pdo_lock.acquire()
try:
if self.__running:
return
self.__running = True
self._trendconfig = PersistentDictionary(filename(self), encode=None, decode=None)
if not self._trendconfig:
pdodata = PersistentDataObject(self, dmtype=GC_NEVER)
if os.path.exists(pdodata.filename()):
msglog.log("broadway", msglog.types.INFO, "Migrating previous trend data")
pdodata.trends = {}
pdodata.load()
self._trendconfig.update(pdodata.trends)
del (pdodata)
finally:
self._pdo_lock.release()
super(TrendManager, self).start()
self.logger = node.as_internal_node(self.logger_url)
if self.has_child("trends"):
self.trends = self.get_child("trends")
else:
self.trends = CompositeNode()
self.trends.configure({"parent": self, "name": "trends"})
self.trends.start()
corrupt_trends = []
for trendname, trenddump in self._trendconfig.items():
msg = "Loading trend: %s" % trendname
msglog.log("trendmanager", msglog.types.INFO, msg)
try:
trend = unmarshal(trenddump)
except:
corrupt_trends.append(trendname)
msg = "Failed to load trend: %s" % trendname
msglog.log("trendmanager", msglog.types.ERR, msg)
msglog.exception(prefix="Handled")
for trendname in corrupt_trends:
try:
msg = "Deleting trend information: %s" % trendname
msglog.log("trendmanager", msglog.types.INFO, msg)
self._delete_trend_configuration(trendname)
if self.trends.has_child(trendname):
trend = self.trends.get_child(trendname)
trend.prune(force=True)
except:
msglog.exception(prefix="Handled")
except:
self.__running = False
raise
return
示例4: CloudConfigurator
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
class CloudConfigurator(CompositeNode):
def __init__(self, *args, **kw):
self.secured = True
self.path = "/cloudconfig"
self.manager = '/services/Cloud Manager'
self.security_manager = '/services/Security Manager'
super(CloudConfigurator, self).__init__(*args, **kw)
def configure(self, config):
self.secured = as_boolean(as_internal_node("/services").secured)
self.setattr('path', config.get('path',self.path))
self.setattr('manager', config.get('manager','/services/Cloud Manager'))
super(CloudConfigurator, self).configure(config)
def configuration(self):
config = super(CloudConfigurator, self).configuration()
config['path'] = self.getattr('path')
config['manager'] = self.getattr('manager')
config['secured'] = str(int(self.secured))
return config
def stop(self):
if not isinstance(self.manager, str):
self.manager.dispatcher.unregister(self.sub)
self.manager = as_node_url(self.manager)
if not isinstance(self.security_manager, str):
self.security_manager = as_node_url(self.security_manager)
return super(CloudConfigurator, self).stop()
def get_manager(self):
manager = self.manager
if self.secured:
manager = self.security_manager.as_secured_node(manager)
return manager
def match(self, path):
return path.startswith(self.path)
def start(self):
self.manager = self.nodespace.as_node(self.manager)
self.security_manager = as_node(self.security_manager)
self._pdo = PersistentDataObject(self)
msg='The CloudConfigurator Persistent Object is in the file :%s' %str(self._pdo.filename())
msglog.log('CloudConfigurator', msglog.types.INFO,msg)
if os.path.exists(self._pdo.filename()):
# Migration
msglog.log('CloudConfigurator', msglog.types.INFO, 'PDO Migration in Progress')
self._pdo.formation = cPickle.dumps(IPickles(self.manager.formation))
self._pdo.load()
formation = IPickles(cPickle.loads(self._pdo.formation))()
msglog.log('CloudConfigurator', msglog.types.INFO, 'PDO Migration for the Formation:%s' %str(formation))
self.manager.update_formation(formation,None)
self._pdo.destroy()
del(self._pdo)
msglog.log('CloudConfigurator', msglog.types.INFO, 'PDO Migration is Complete')
return super(CloudConfigurator, self).start()
def get_node_names(self):
formation = self.manager.get_formation()
norm_formation=self.manager.nformation.normalize_formation(formation)
ind=norm_formation.index(self.manager.peer)
# move the peer to be at the head of the list
p=formation.pop(ind)
formation.insert(0,p)
#insert manager at the very first place
portal=self.manager.get_portal()
if(portal == None):
formation.insert(0,"")
else:
formation.insert(0,portal)
return (formation)
def validate(self,name):
name=name.strip()
if ( not (valid_ip_address(name) or valid_hostname(name))):
return(1)
if(name == 'localhost' ):
return(1)
if(name == '127.0.0.1' ):
return(1)
return(0)
def handle_request(self, request):
pass
#create_node: name - name of the peer/portal
#config - type = config["type"] string will tell if this is a "Peer" or a "Portal"
def create_node(self, name, config=()):
config = dict(config)
type = config['type'].lower()
manager = self.get_manager()
# Next statements verify access to modifier permitted.
if type == "peer":
manager.add_peer
else:
manager.set_portal
config.setdefault("parent", self.manager)
peer_or_portal = config.setdefault("name", name).strip()
ret = self.validate(peer_or_portal)
if(ret != 0 ):
msg='Add Peer/Portal failed. %s is a invalid hostname/IP Address' %(peer_or_portal)
raise ValueError(msg)
#.........这里部分代码省略.........
示例5: CloudManager
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
#.........这里部分代码省略.........
portal=self.nformation.get_portal()
self.update_formation(formation,portal)
return
def get_formation(self):
formation=self.nformation.get_formation()
return(formation)
def get_portal(self):
portal=self.nformation.get_portal()
return(portal)
security.protect('set_portal', 'Configure')
def set_portal(self,portal):
formation=self.nformation.get_formation()
self.update_formation(formation,portal)
security.protect('remove_peer', 'Configure')
def remove_peer(self,peer):
formation = self.nformation.get_formation()
formation.remove(peer)
portal=self.nformation.get_portal()
self.update_formation(formation,portal)
def start(self):
# Bad self IP Address
if(self.peer == '127.0.0.1' ):
msg='Cloud facility will not function properly because of local IP address being 127.0.0.1'
self.message(msg,msglog.types.WARN)
return
if not self.channel_monitor.is_running():
self.channel_monitor.start_monitor()
self._pdo=PersistentDataObject(self)
self.message('The Cloud Manager Persistent Object is in the file :%s' %str(self._pdo.filename()),msglog.types.INFO)
migration=False
if(os.path.exists(self._pdo.filename())):
# Already Migrated
self._pdo.formation=[self.peer]
self._pdo.portal=None
self._pdo.peer=self.peer
self._pdo.load()
else:
# We save a 'default' formation and expect the Cloud Configurator to
# update the _pdo.formation via update_information API.
# The _setup_formation gets called internally from update_information
self._pdo.portal=None
self._pdo.formation=[self.peer]
self._pdo.peer=self.peer
self._pdo.save()
self._pdo.load()
migration=True
#Bad formation/peer in the PDO
if( not self._pdo.peer in self._pdo.formation ):
#Bad formation/peer
self.message('The Cloud Manager PDO in the file :%s is corrupted. Defaulting to safe configuration' %str(self._pdo.filename()),msglog.types.WARN)
self._pdo.portal=None
self._pdo.formation=[self.peer]
self._pdo.peer=self.peer
self._pdo.save()
self._pdo.load()
self.message('Hosts are :%s portal=%s self=%s' %(str(self._pdo.formation),self._pdo.portal,self._pdo.peer),msglog.types.INFO)
self.nformation=NFormation(self._pdo.formation,self.peer)
self.nformation.set_portal(self._pdo.portal)
示例6: start
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
def start(self):
if self.is_running():
raise TypeError("Equipment Monitor already running.")
if TESTING and not self.test_machines:
self.test_machines = setup_machines()
machinecount = len(self.test_machines)
self.debugout("Setup %d test machines" % machinecount)
self.synclock.acquire()
try:
self.running.set()
if self.subscriptions and not self.subscriptions.closed():
self.subscriptions.close()
self.formatter = None
self.transporter = None
children = self.children_nodes()
for childnode in children:
if IFormatter.providedBy(childnode):
if self.formatter is not None:
raise TypeError("Already has formatter child.")
self.formatter = childnode
if ITransporter.providedBy(childnode):
if self.transporter is not None:
raise TypeError("Already has transporter child.")
self.transporter = childnode
if not self.formatter:
raise TypeError("Must have one formatter child node.")
if not self.transporter:
raise TypeError("Must have one transporter child node.")
self.smservice = as_node(self.smnodeurl)
self.subscriptions = PersistentDictionary(
self.name, encode=self.serialize_subscription,
decode=self.unserialize_subscription)
pdodata = PersistentDataObject(self)
if os.path.exists(pdodata.filename()):
msglog.log('broadway', msglog.types.WARN,
"Equipment Monitor upgrading persistence.")
migrate = frompdo(pdodata)
self.subscriptions.update(migrate)
message = "Equipment Monitor merged %d subscriptions."
message = message % len(migrate)
msglog.log('broadway', msglog.types.INFO, message)
pdodata.destroy()
msglog.log('broadway', msglog.types.WARN,
"Equipment Monitor destroyed old persistence.")
msglog.log('broadway', msglog.types.INFO,
"Equipment Monitor persistence upgrade complete.")
del(pdodata)
message = 'Equipment Monitor startup: %s %s'
for subscription in self.subscriptions.values():
try:
subscription.setup_subscription()
except:
msglog.exception(prefix="handled")
else:
self.debugout(message % ('setup', subscription))
skipcounts = []
for i in range(0, 1 + len(self.subscriptions) / 30):
skipcounts.extend([i + 1] * 30)
self.setup_work_threads()
for subscription in self.subscriptions.values():
try:
subscription.start(skipcounts.pop())
except:
msglog.exception(prefix = "Handled")
else:
self.debugout(message % ('started', subscription))
except:
self.cleanup_resources()
self.running.clear()
raise
finally:
self.synclock.release()
super(EquipmentMonitor, self).start()
示例7: Control
# 需要导入模块: from mpx.lib.persistent import PersistentDataObject [as 别名]
# 或者: from mpx.lib.persistent.PersistentDataObject import filename [as 别名]
class Control(CompositeNode):
##
# This attribute is used in the introspective generation
# of configuration data.
__module__ = mpx.service.control.__name__
def __init__(self):
CompositeNode.__init__(self)
self._status = 'initialized'
self._stale_apps = []
def configure(self, config):
self._pdo = PersistentDataObject(self)
self._pdo.stats_dict = {} #used to detect changes to xml files based on timestamp. Tuple (modify time, pickle string)
self._pdo.load()
# write_priority can be set for the entire control service, though
# it may be specialized at the individual application node level.
set_attribute(self, 'write_priority', 9, config, int)
CompositeNode.configure(self, config)
def configuration(self):
config = CompositeNode.configuration(self)
self.pdo_file = self._pdo.filename()
get_attribute(self, 'write_priority', config)
get_attribute(self, 'pdo_file', config, str)
return config
def _save_pdo(self): #no locking needed since the load and save cannot overlap
start_time = time.time()
self._pdo.save()
msglog.log(self.as_node_url(),msglog.types.INFO,
'Control service configuration data saved in: %s seconds' % (str(time.time() - start_time),))
def start(self):
self._status = 'starting'
self.stats_dict = {} #clear out stats dict to force reload of app
self.application_change_detector(1) #starting
def _start(self):
CompositeNode.start(self) #get the children ready for a trip...
#now that the children are started, go back through the list and finish up the "graphical compile"
for n in self.children_nodes():
if n.hasattr('map_output_connections'):
n.map_output_connections()
for n in self.children_nodes():
if n.hasattr('map_reference_output_connections'):
n.map_reference_output_connections()
for n in self.children_nodes():
if n.hasattr('resolve_inputs'):
n.resolve_inputs()
for n in self.children_nodes():
if n.hasattr('prepare_run_list'):
n.prepare_run_list()
for n in self.children_nodes():
if n.hasattr('trigger_run_list'):
n.trigger_run_list()
def prune_orphaned_schedules(self):
# remove schedules under /services/time/local/TIM that have no app
manager = as_node('/services/time/local')
if manager.has_child('TIM'):
try:
sh = as_node('/services/time/local/TIM')
name_header = 'RZSched_'
# create list of RZSched_'s under the TIM node
schedules = filter(lambda k:k[:len(name_header)] == name_header, sh.children_names())
# compare appname after RZSched_, upto : with our children names
orphans = filter(lambda k:k.split('_')[1].split(':')[0] not in self.children_names(), schedules)
for o in orphans:
try:
sh.get_child(o).prune()
msglog.log('Graphical Control:', 'pruned orphaned schedule: ', o)
except:
msglog.exception()
if len(orphans):
sh.save_schedule()
except:
msglog.exception()
def check_and_load_application_files(self, starting=0):
app_reloaded = starting #return value to signal that the children need to be started
save_pdo = 0 #flag to control saving config data to pdo
files = os.listdir(config_path) #/var/mpx/config/services/control (usually)
xml_filenames = []
for f in files:
if f.find('.xml') > 0 and len(f) == (f.find('.xml') + 4): #any xml file in this folder is assumed to be a control app
xml_filenames.append(f)
modify_time = os.stat(config_path + f)[8]
stale_pdo = True
no_stats_pdo = True
if f in self._pdo.stats_dict: #check for change since last time
no_stats_pdo = False
if self._pdo.stats_dict[f][0] == modify_time:
stale_pdo = False #old news, no change detected
#self.stats_dict[f]=modify_time
if starting or no_stats_pdo or (stale_pdo and ALLOW_APP_RELOAD): #need to (re)load application
if app_reloaded == 0: #only stop all application nodes for the first detected change
try:
self._status = 'Stopping %s' % (f,)
msglog.log(self.as_node_url(),msglog.types.INFO,
'Stage 0: Stop Application templates.')
for c in self.children_nodes():
if hasattr(c, '_stop_running_app'):
c._stop_running_app()
except:
msglog.exception()
#.........这里部分代码省略.........