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


Python ModelFile.ModelFile类代码示例

本文整理汇总了Python中Shine.Configuration.ModelFile.ModelFile的典型用法代码示例。如果您正苦于以下问题:Python ModelFile类的具体用法?Python ModelFile怎么用?Python ModelFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: __init__

 def __init__(self, sep='=', linesep=' '):
     ModelFile.__init__(self, sep, linesep)
     self.add_element('dev', check='path')
     self.add_element('index', check='digit')
     self.add_element('jdev', check='path')
     self.add_element('mode', check='enum', default='managed',
                      values=['managed', 'external'])
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:7,代码来源:ModelFileTest.py

示例2: __init__

 def __init__(self, sep='=', linesep=' '):
     ModelFile.__init__(self, sep, linesep)
     self.add_element('tag',     check='string')
     self.add_element('node',    check='string')
     self.add_element('ha_node', check='string', multiple=True)
     self.add_element('dev',     check='path')
     self.add_element('size',    check='digit')
     self.add_element('jdev',    check='path')
     self.add_element('jsize',   check='digit')
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:9,代码来源:File.py

示例3: test_huge_folding_scales

 def test_huge_folding_scales(self):
     """folding a lot of elements is fast enough"""
     model = ModelFile()
     model.add_element("foo", check="string", multiple=True, fold=True)
     for i in range(0, 10000):
         model.parse('foo: first%s second%s' % (i, i + 10))
     before = time.time()
     self.assertEqual(str(model), 'foo:first[0-9999] second[10-10009]')
     elapsed = time.time() - before
     self.assertTrue(elapsed < 0.5, "%.2fs exceeds 0.5s threshold" % elapsed)
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:10,代码来源:ModelFileTest.py

示例4: __init__

 def __init__(self, sep='=', linesep=' '):
     ModelFile.__init__(self, sep, linesep)
     self.add_element('node',    check='string')
     self.add_element('ha_node', check='string', multiple=True)
     self.add_element('dev',     check='path')
     self.add_element('jdev',    check='path')
     self.add_element('index',   check='digit')
     self.add_element('group',   check='string')
     self.add_element('mode',    check='enum',
             default='managed', values=['managed', 'external'])
     self.add_element('network', check='string')
     self.add_element('tag',     check='string')
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:12,代码来源:Model.py

示例5: testMultipleElement

    def testMultipleElement(self):
        """ModelFile with MultipleElement"""
        model = ModelFile()
        model.add_element('foos', check='digit', multiple=True)

        # Default
        self.assertEqual(model.get('foos', []), [])

        # Multiple add()
        model.add('foos', 3)
        self.assertEqual(model.get('foos'), [3])
        self.assertEqual(str(model), "foos:3")
        model.add('foos', 5)
        self.assertEqual(model.get('foos'), [3, 5])
        self.assertEqual(str(model), "foos:3\nfoos:5")
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:15,代码来源:ModelFileTest.py

示例6: __init__

    def __init__(self, sep=":", linesep="\n"):
        ModelFile.__init__(self, sep, linesep)

        # General
        self.add_custom('fs_name', FSName())
        self.add_element('description',       check='string')

        # Stripping
        self.add_element('stripe_size',       check='digit', default=1048576)
        self.add_element('stripe_count',      check='digit', default=1)

        # Common target options
        for tgt in ['mgt', 'mdt', 'ost' ]:
            self.add_element(tgt + "_mkfs_options",  check='string')
            self.add_element(tgt + "_mount_options", check='string')
            self.add_element(tgt + "_format_params", check='string')
        self.add_element("mgt_mount_path",    check='string',
                default='/mnt/$fs_name/mgt')
        self.add_element("mdt_mount_path",    check='string',
                default='/mnt/$fs_name/mdt/$index')
        self.add_element("ost_mount_path",    check='string',
                default='/mnt/$fs_name/ost/$index')

        # Common client options
        self.add_element('mount_options',     check='string')
        self.add_element('mount_path',        check='path')

        # Quota
        self.add_element('quota',             check='boolean')
        self.add_element('quota_type',        check='string', default='ug')
        self.add_element('quota_bunit',       check='digit')
        self.add_element('quota_iunit',       check='digit')
        self.add_element('quota_btune',       check='digit')
        self.add_element('quota_itune',       check='digit')

        # NidMapping
        self.add_custom('nid_map', NidMaps())

        # Targets
        self.add_custom('mgt', Target(), multiple=True)
        self.add_custom('mdt', Target(), multiple=True)
        self.add_custom('ost', Target(), multiple=True)
        # Client
        self.add_custom('client', Client(), multiple=True)
        # Router
        self.add_custom('router', Router(), multiple=True)
开发者ID:pombredanne,项目名称:shine,代码行数:46,代码来源:Model.py

示例7: testModelBaseMethods

    def testModelBaseMethods(self):
        """test ModelFile base methods"""

        model = ModelFile()

        # content() with a default value
        self.assertEqual(model.content('default'), 'default')

        model.add_element('foo', check='string', multiple=True)

        # get() with a default value
        self.assertEqual(model.get('foo', 'default'), 'default')

        # Only key with non-empty value are taken in account
        self.assertEqual(len(model), 0)

        # parse() 
        self.assertRaises(ModelFileValueError, model.parse, "foo one two")

        # __contains__() False
        self.assertFalse('foo' in model)

        # iter()
        model.add('foo', "5 6")
        model.add('foo', "6 7")
        self.assertEqual(list(iter(model)), ['foo'])

        # __contains__() True
        self.assertTrue('foo' in model)
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:29,代码来源:ModelFileTest.py

示例8: __init__

        def __init__(self, sep="=", linesep="\n"):
            ModelFile.__init__(self, sep, linesep)

            # Backend stuff
            self.add_element('backend',             check='enum',
                    default='None', values=['ClusterDB', 'File', 'None'])
            self.add_element('storage_file',        check='path',
                    default='/etc/shine/storage.conf')
            self.add_element('status_dir',          check='path',
                    default='/var/cache/shine/status')

            # Config dirs
            self.add_element('conf_dir',            check='path',
                    default='/var/cache/shine/conf')
            self.add_element('lmf_dir',             check='path',
                    default='/etc/shine/models')
            self.add_element('tuning_file',         check='path')

            # Timeouts
            self.add_element('ssh_connect_timeout', check='digit',
                    default=30)
            self.add_element('ssh_fanout',          check='digit',
                    default=0)
            self.add_element('default_timeout',     check='digit',
                    default=30)

            # Commands
            self.add_element('command_path',        check='path',
                    default='/usr/lib/lustre')

            # Lustre version
            self.add_element('lustre_version',      check='string')

            # CLI
            self.add_element('color',               check='enum',
                    default='auto', values=['never', 'always', 'auto'])

            # TO BE IMPLEMENTED
            self.add_element('start_timeout',       check='digit')
            self.add_element('mount_timeout',       check='digit')
            self.add_element('stop_timeout',        check='digit')
            self.add_element('status_timeout',      check='digit')
            self.add_element('log_file',            check='path')
            self.add_element('log_level',           check='string')
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:44,代码来源:Globals.py

示例9: testExpandRange

    def testExpandRange(self):
        """parse ranged line expand correctly"""
        model = ModelFile()
        model.add_element("foo", check="string", multiple=True)

        model.parse("foo: mine[10-15]")
        self.assertEqual(len(model.get('foo')), 6)
        del model['foo']

        model.parse("foo: mine[10-15] second[1-6]")
        self.assertEqual(len(model.get('foo')), 6)
        del model['foo']

        # Ranges mismatch
        self.assertRaises(ModelFileValueError, model.parse, "foo: five[1-5] two[1-2]")
开发者ID:kcgthb,项目名称:lustre-shine,代码行数:15,代码来源:ModelFileTest.py

示例10: testDiffSimpleElement

    def testDiffSimpleElement(self):
        """diff between 2 modelfiles with a SimpleElement"""
        model = ModelFile()
        model.add_element('name', check='string')

        model2 = model.emptycopy()

        # Empty models have no difference
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # Same model have no difference
        model.add('name', 'foo')
        model2.add('name', 'foo')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # A value changed
        del model2['name']
        model2.add('name', 'bar')
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {'name': 'bar'})

        # A value added
        del model['name']
        added, changed, removed = model.diff(model2)
        self.assertEqual(added.as_dict(), {'name': 'bar'})
        self.assertEqual(removed.as_dict(), {})
        self.assertEqual(changed.as_dict(), {})

        # A value removed
        added, changed, removed = model2.diff(model)
        self.assertEqual(added.as_dict(), {})
        self.assertEqual(removed.as_dict(), {'name': 'bar'})
        self.assertEqual(changed.as_dict(), {})
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:41,代码来源:ModelFileTest.py

示例11: testLoadModelFromFile

    def testLoadModelFromFile(self):
        """load a ModelFile from file"""
        model = ModelFile()
        model.add_element("foo", check="string", multiple=True)
        model.add_element("bar", check="digit", multiple=True)

        testfile = makeTempFile("""foo: my test
bar: 3
foo: another
bar: 1
bar: 2""")
        model.load(testfile.name)
        self.assertEqual(model.get('foo'), ['my test', 'another'])
        self.assertEqual(model.get('bar'), [3, 1, 2])

        # Bad file syntax
        testfile = makeTempFile("""foo bad file""")
        self.assertRaises(ModelFileValueError, model.load, testfile.name)
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:18,代码来源:ModelFileTest.py

示例12: testModelElementManagement

    def testModelElementManagement(self):
        """add/del elements to a model file"""
        model = ModelFile()

        # Add an element
        model.add_element('foo', check='path')

        # Add another element with the same key raises an error
        self.assertRaises(KeyError, model.add_element, 'foo', check='string')

        # is_element() accessors
        self.assertTrue(model.is_element('foo'))

        # Undeclared an element
        model.del_element('foo')
        self.assertRaises(KeyError, model.del_element, 'foo')

        # Re-add an element
        model.add_element('foo', check='digit')
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:19,代码来源:ModelFileTest.py

示例13: testAddCustomElement

    def testAddCustomElement(self):
        """model file uses a user-defined Element"""
        class ElemNodeSet(SimpleElement):
            def __init__(self, check='string', default=None, values=None):
                SimpleElement.__init__(self, 'string', default, values)

            def _validate(self, value):
                try:
                    return NodeSet(value)
                except:
                    raise ModelFileValueError

        model = ModelFile()
        model.add_custom('nodes', ElemNodeSet(), multiple=True)
        model.add_custom('nids', ElemNodeSet(), multiple=True)

        model.add('nodes', 'foo[1-5]')
        self.assertEqual(str(model), "nodes:foo[1-5]")
        self.assertEqual([str(item) for item in model.get('nodes')],
                [str(NodeSet('foo[1-5]'))])
        self.assertRaises(ModelFileValueError, model.add, 'nodes', 'bad[15')
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:21,代码来源:ModelFileTest.py

示例14: test_hash_model_element

    def test_hash_model_element(self):
        """check 2 different model element have different hashes."""
        model = ModelFile()
        model.add_element('foo', check='string')
        model.add_element('bar', check='string')

        model2 = model.emptycopy()

        model.parse('foo: foo1')
        model.parse('bar: bar1')
        model2.parse('foo: foofoo')
        model2.parse('bar: barbar')

        self.assertEqual(hash(model), hash(model))
        self.assertEqual(hash(model2), hash(model2))
        self.assertNotEqual(hash(model), hash(model2))
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:16,代码来源:ModelFileTest.py

示例15: test_expand_fold_range

    def test_expand_fold_range(self):
        """parse line with range expand and fold correctly"""
        model = ModelFile()
        model.add_element("foo", check="string", multiple=True, fold=True)

        model.parse("foo: mine[10-15]")
        self.assertEqual(len(model.get('foo')), 6)
        self.assertEqual(str(model.elements('foo')), 'mine[10-15]')
        del model['foo']

        model.parse("foo: mine[10-15] second[1-6]")
        self.assertEqual(len(model.get('foo')), 6)
        self.assertEqual(str(model.elements('foo')), 'mine[10-15] second[1-6]')
        del model['foo']

        # Range supports padding
        model.parse('foo: bar[01-02]')
        self.assertEqual(model.get('foo'), ['bar01', 'bar02'])
        self.assertEqual(str(model.elements('foo')), 'bar[01-02]')
        del model['foo']

        # Ranges mismatch
        self.assertRaises(ModelFileValueError, model.parse, "foo: five[1-5] two[1-2]")
开发者ID:bullxpfs,项目名称:lustre-shine,代码行数:23,代码来源:ModelFileTest.py


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