当前位置: 首页>>代码示例>>Python>>正文


Python BaseEntity.fromdict方法代码示例

本文整理汇总了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')
开发者ID:cea-hpc,项目名称:milkcheck,代码行数:35,代码来源:BaseEntityTest.py

示例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)
开发者ID:pombredanne,项目名称:milkcheck,代码行数:58,代码来源:ServiceGroup.py

示例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')
开发者ID:cea-hpc,项目名称:milkcheck,代码行数:13,代码来源:BaseEntityTest.py

示例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)
开发者ID:pombredanne,项目名称:milkcheck,代码行数:25,代码来源:Service.py

示例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']
开发者ID:mdlx,项目名称:milkcheck,代码行数:8,代码来源:Action.py


注:本文中的MilkCheck.Engine.BaseEntity.BaseEntity.fromdict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。