當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。