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


Python NodeSet.groups方法代码示例

本文整理汇总了Python中ClusterShell.NodeSet.groups方法的典型用法代码示例。如果您正苦于以下问题:Python NodeSet.groups方法的具体用法?Python NodeSet.groups怎么用?Python NodeSet.groups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClusterShell.NodeSet的用法示例。


在下文中一共展示了NodeSet.groups方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testGroupGroups

# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import groups [as 别名]
 def testGroupGroups(self):
     """test NodeSet.groups()"""
     nodeset = NodeSet("montana[32-37,42-55]")
     self.assertEqual(sorted(nodeset.groups().keys()), ['@all', '@chassis1', '@chassis10', '@chassis11', '@chassis12', '@chassis2', '@chassis3', '@chassis6', '@chassis7', '@chassis8', '@chassis9', '@compute'])
     testns = NodeSet()
     for gnodes, inodes in nodeset.groups().itervalues():
         testns.update(inodes)
     self.assertEqual(testns, nodeset)
开发者ID:ChristianKniep,项目名称:clustershell,代码行数:10,代码来源:NodeSetGroupTest.py

示例2: test_yaml_basic

# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import groups [as 别名]
    def test_yaml_basic(self):
        """test groups with a basic YAML config file"""
        dname = make_temp_dir()
        f = make_temp_file("""
# A comment

[Main]
default: yaml
autodir: %s
        """ % dname)
        yamlfile = make_temp_file("""
yaml:
    foo: example[1-4,91-100],example90
    bar: example[5-89]
        """, suffix=".yaml", dir=dname)

        res = GroupResolverConfig(f.name)

        # Group resolution
        nodeset = NodeSet("@foo", resolver=res)
        self.assertEqual(str(nodeset), "example[1-4,90-100]")
        nodeset = NodeSet("@bar", resolver=res)
        self.assertEqual(str(nodeset), "example[5-89]")
        nodeset = NodeSet("@foo,@bar", resolver=res)
        self.assertEqual(str(nodeset), "example[1-100]")
        nodeset = NodeSet("@unknown", resolver=res)
        self.assertEqual(len(nodeset), 0)

        # Regroup
        nodeset = NodeSet("example[1-4,90-100]", resolver=res)
        self.assertEqual(str(nodeset), "example[1-4,90-100]")
        self.assertEqual(nodeset.regroup(), "@foo")
        self.assertEqual(nodeset.groups().keys(), ["@foo"])
        self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-4,90-100]")

        # No 'all' defined: all_nodes() should raise an error
        self.assertRaises(GroupSourceError, res.all_nodes)
        # but then NodeSet falls back to the union of all groups
        nodeset = NodeSet.fromall(resolver=res)
        self.assertEqual(str(nodeset), "example[1-100]")
        # regroup doesn't use @all in that case
        self.assertEqual(nodeset.regroup(), "@bar,@foo")

        # No 'reverse' defined: node_groups() should raise an error
        self.assertRaises(GroupSourceError, res.node_groups, "example1")

        # regroup with rest
        nodeset = NodeSet("example[1-101]", resolver=res)
        self.assertEqual(nodeset.regroup(), "@bar,@foo,example101")

        # regroup incomplete
        nodeset = NodeSet("example[50-200]", resolver=res)
        self.assertEqual(nodeset.regroup(), "example[50-200]")

        # regroup no matching
        nodeset = NodeSet("example[102-200]", resolver=res)
        self.assertEqual(nodeset.regroup(), "example[102-200]")
开发者ID:LaHaine,项目名称:ohpc,代码行数:59,代码来源:NodeSetGroupTest.py

示例3: testGroupResolverND

# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import groups [as 别名]
    def testGroupResolverND(self):
        """test NodeSet with simple custom GroupResolver (nD)"""

        test_groups4 = makeTestG4()

        source = UpcallGroupSource("simple",
                                   "sed -n 's/^$GROUP:\(.*\)/\\1/p' %s" % test_groups4.name,
                                   "sed -n 's/^all:\(.*\)/\\1/p' %s" % test_groups4.name,
                                   "sed -n 's/^\([0-9A-Za-z_-]*\):.*/\\1/p' %s" % test_groups4.name,
                                   None)

        # create custom resolver with default source
        res = GroupResolver(source)
        self.assertFalse(res.has_node_groups())
        self.assertFalse(res.has_node_groups("dummy_namespace"))

        nodeset = NodeSet("@rack-x1y2", resolver=res)
        self.assertEqual(nodeset, NodeSet("idaho[2-3]z1"))
        self.assertEqual(str(nodeset), "idaho[2-3]z1")

        nodeset = NodeSet("@rack-y1", resolver=res)
        self.assertEqual(str(nodeset), "idaho[1-2,4-5]z1")

        nodeset = NodeSet("@rack-all", resolver=res)
        self.assertEqual(str(nodeset), "idaho[1-7]z1")

        # test NESTED nD groups()
        self.assertEqual(sorted(nodeset.groups().keys()),
                         ['@rack-all', '@rack-x1', '@rack-x1y1', '@rack-x1y2',
                          '@rack-x2', '@rack-x2y1', '@rack-x2y2', '@rack-y1',
                          '@rack-y2'])
        self.assertEqual(sorted(nodeset.groups(groupsource="simple").keys()),
                         ['@simple:rack-all', '@simple:rack-x1',
                          '@simple:rack-x1y1', '@simple:rack-x1y2',
                          '@simple:rack-x2', '@simple:rack-x2y1',
                          '@simple:rack-x2y2', '@simple:rack-y1',
                          '@simple:rack-y2'])
        self.assertEqual(sorted(nodeset.groups(groupsource="simple",
                                               noprefix=True).keys()),
                         ['@rack-all', '@rack-x1', '@rack-x1y1', '@rack-x1y2',
                          '@rack-x2', '@rack-x2y1', '@rack-x2y2', '@rack-y1',
                          '@rack-y2'])
        testns = NodeSet()
        for gnodes, inodes in nodeset.groups().itervalues():
            testns.update(inodes)
        self.assertEqual(testns, nodeset)

        # more tests with nested groups
        nodeset = NodeSet("idaho5z1", resolver=res)
        self.assertEqual(sorted(nodeset.groups().keys()),
                         ['@rack-all', '@rack-x2', '@rack-x2y1', '@rack-y1'])
        nodeset = NodeSet("idaho5z1,idaho4z1", resolver=res)
        self.assertEqual(sorted(nodeset.groups().keys()),
                         ['@rack-all', '@rack-x2', '@rack-x2y1', '@rack-y1'])
        nodeset = NodeSet("idaho5z1,idaho7z1", resolver=res)
        self.assertEqual(sorted(nodeset.groups().keys()),
                         ['@rack-all', '@rack-x2', '@rack-x2y1', '@rack-x2y2',
                          '@rack-y1', '@rack-y2'])
开发者ID:jasonshih,项目名称:clustershell,代码行数:60,代码来源:NodeSetGroupTest.py

示例4: testConfigCFGDIR

# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import groups [as 别名]
    def testConfigCFGDIR(self):
        """test groups with $CFGDIR use in upcalls"""
        f = make_temp_file("""
[Main]
default: local

[local]
map: echo example[1-100]
list: basename $CFGDIR
        """)
        res = GroupResolverConfig(f.name)
        nodeset = NodeSet("example[1-100]", resolver=res)
        # just a trick to check $CFGDIR resolution...
        tmpgroup = os.path.basename(os.path.dirname(f.name))
        self.assertEqual(nodeset.groups().keys(), ['@%s' % tmpgroup])
        self.assertEqual(str(nodeset), "example[1-100]")
        self.assertEqual(nodeset.regroup(), "@%s" % tmpgroup)
        self.assertEqual(str(NodeSet("@%s" % tmpgroup, resolver=res)),
                         "example[1-100]")
开发者ID:mdavranche,项目名称:clustershell,代码行数:21,代码来源:NodeSetGroupTest.py

示例5: testConfigBasicLocal

# 需要导入模块: from ClusterShell import NodeSet [as 别名]
# 或者: from ClusterShell.NodeSet import groups [as 别名]
    def testConfigBasicLocal(self):
        """test groups with a basic local config file"""
        f = make_temp_file("""
# A comment

[Main]
default: local

[local]
map: echo example[1-100]
#all:
list: echo foo
#reverse:
        """)
        res = GroupResolverConfig(f.name)
        nodeset = NodeSet("example[1-100]", resolver=res)
        self.assertEqual(str(nodeset), "example[1-100]")
        self.assertEqual(nodeset.regroup(), "@foo")
        self.assertEqual(nodeset.groups().keys(), ["@foo"])
        self.assertEqual(str(NodeSet("@foo", resolver=res)), "example[1-100]")

        # No 'all' defined: all_nodes() should raise an error
        self.assertRaises(GroupSourceNoUpcall, res.all_nodes)
        # No 'reverse' defined: node_groups() should raise an error
        self.assertRaises(GroupSourceNoUpcall, res.node_groups, "example1")

        # regroup with rest
        nodeset = NodeSet("example[1-101]", resolver=res)
        self.assertEqual(nodeset.regroup(), "@foo,example101")

        # regroup incomplete
        nodeset = NodeSet("example[50-200]", resolver=res)
        self.assertEqual(nodeset.regroup(), "example[50-200]")

        # regroup no matching
        nodeset = NodeSet("example[102-200]", resolver=res)
        self.assertEqual(nodeset.regroup(), "example[102-200]")
开发者ID:ChristianKniep,项目名称:clustershell,代码行数:39,代码来源:NodeSetGroupTest.py


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