本文整理汇总了Python中MilkCheck.Engine.BaseEntity.BaseEntity.fromdict方法的典型用法代码示例。如果您正苦于以下问题:Python BaseEntity.fromdict方法的具体用法?Python BaseEntity.fromdict怎么用?Python BaseEntity.fromdict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MilkCheck.Engine.BaseEntity.BaseEntity
的用法示例。
在下文中一共展示了BaseEntity.fromdict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resolve_all
# 需要导入模块: from MilkCheck.Engine.BaseEntity import BaseEntity [as 别名]
# 或者: from MilkCheck.Engine.BaseEntity.BaseEntity import fromdict [as 别名]
def test_resolve_all(self):
"""resolve_all() resolves all BaseEntity properties"""
entity = BaseEntity('entity')
entity.add_var('TGT', 'localhost')
entity.add_var('NBR1', 1)
entity.add_var('NBR2', 2)
entity.add_var('NBR3', 3)
entity.add_var('NBR4', 4)
entity.add_var('NBR5', 5)
entity.add_var('NBR6', 6)
entity.add_var('KEYWORD', 'delegate')
entity.add_var('TXT', 'I am the entity')
entity.fromdict({
'target': "%TGT",
'timeout': "%NBR1",
'retry': "%NBR2",
'fanout': "%NBR3",
'delay': "%NBR4",
'warnings': "%NBR5",
'errors': "%NBR6",
'desc': "%TXT",
'mode': "%KEYWORD"
})
entity.resolve_all()
self.assertEqual(entity.desc, "I am the entity")
self.assertEqual(entity.target, NodeSet('localhost'))
self.assertEqual(entity.timeout, 1)
self.assertEqual(entity.maxretry, 2)
self.assertEqual(entity.fanout, 3)
self.assertEqual(entity.delay, 4)
self.assertEqual(entity.errors, 6)
self.assertEqual(entity.warnings, 5)
self.assertEqual(entity.mode, 'delegate')
示例2: fromdict
# 需要导入模块: from MilkCheck.Engine.BaseEntity import BaseEntity [as 别名]
# 或者: from MilkCheck.Engine.BaseEntity.BaseEntity import fromdict [as 别名]
def fromdict(self, grpdict):
"""Populate group attributes from dict."""
BaseEntity.fromdict(self, grpdict)
if 'services' in grpdict:
dep_mapping = {}
# Wrap dependencies from YAML and build the service
for names, props in grpdict['services'].items():
for subservice in NodeSet(names):
# Parsing dependencies
wrap = DepWrapper()
for prop in ('require', 'require_weak',
'before', 'after', 'check'):
if prop in props:
if prop in ('before', 'after'):
props['require_weak'] = props[prop]
prop = 'require_weak'
wrap.deps[prop] = props[prop]
# Get subservices which might be Service or ServiceGroup
service = None
if 'services' in props:
service = ServiceGroup(subservice)
service.fromdict(props)
else:
service = Service(subservice)
service.fromdict(props)
# Link the group and its new subservice together
self._subservices[subservice] = service
service.parent = self
wrap.source = service
dep_mapping[subservice] = wrap
# Generate dependency links of the service
for wrap in dep_mapping.values():
# Not any dependencies so just attach
for dtype in wrap.deps:
for dep in wrap.deps[dtype]:
if dep not in self._subservices:
raise UnknownDependencyError(dep)
wrap.source.add_dep(self._subservices[dep],
sgth=dtype.upper())
# Bind subgraph to the service group
for service in self.iter_subservices():
if not service.children:
service.add_dep(self._source, parent=False)
if not service.parents:
service.add_dep(self._sink)
for subser in self.iter_subservices():
subser.inherits_from(self)
示例3: test_resolve_all_variables
# 需要导入模块: from MilkCheck.Engine.BaseEntity import BaseEntity [as 别名]
# 或者: from MilkCheck.Engine.BaseEntity.BaseEntity import fromdict [as 别名]
def test_resolve_all_variables(self):
"""resolve_all() resolves variables only once"""
entity = BaseEntity('entity')
entity.add_var('foo', 'cool')
entity.add_var('bar', '%foo')
entity.add_var('baz', '%foo')
entity.fromdict({'desc': 'New %bar'})
entity.resolve_all()
self.assertEqual(entity.variables['foo'], entity.variables['bar'])
self.assertEqual(entity.variables['foo'], entity.variables['baz'])
self.assertEqual(entity.desc, 'New cool')
示例4: fromdict
# 需要导入模块: from MilkCheck.Engine.BaseEntity import BaseEntity [as 别名]
# 或者: from MilkCheck.Engine.BaseEntity.BaseEntity import fromdict [as 别名]
def fromdict(self, svcdict):
"""Populate service attributes from dict."""
BaseEntity.fromdict(self, svcdict)
if "actions" in svcdict:
dependencies = {}
actions = {}
for names, props in svcdict["actions"].items():
for name in NodeSet(names):
action = Action(name)
action.fromdict(props)
actions[name] = action
dependencies[name] = props.get("check", [])
for action in actions.values():
for dep in dependencies[action.name]:
action.add_dep(actions[dep])
self.add_action(action)
# Inherits properies between service and actions
for action in self.iter_actions():
action.inherits_from(self)
示例5: fromdict
# 需要导入模块: from MilkCheck.Engine.BaseEntity import BaseEntity [as 别名]
# 或者: from MilkCheck.Engine.BaseEntity.BaseEntity import fromdict [as 别名]
def fromdict(self, actdict):
"""Populate action attributes from dict."""
BaseEntity.fromdict(self, actdict)
if 'cmd' in actdict:
self.command = actdict['cmd']