本文整理汇总了Python中nova.api.openstack.xmlutil.make_flat_dict函数的典型用法代码示例。如果您正苦于以下问题:Python make_flat_dict函数的具体用法?Python make_flat_dict怎么用?Python make_flat_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_flat_dict函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_hypervisor
def make_hypervisor(elem):
pci_stats = xmlutil.TemplateElement('%s:pci_stats' % Pci.alias,
colon_ns=True)
elem.append(pci_stats)
pci_stat = xmlutil.make_flat_dict('%s:pci_stat' % Pci.alias,
selector='%s:pci_stats' % Pci.alias,
colon_ns=True,
root=pci_stats,
ignore_sub_dicts=True)
extra = xmlutil.make_flat_dict('extra_info', selector='extra_info')
pci_stat.append(extra)
pci_stats.append(pci_stat)
示例2: test_make_flat_dict
def test_make_flat_dict(self):
expected_xml = ("<?xml version='1.0' encoding='UTF-8'?>\n"
'<wrapper><a>foo</a><b>bar</b></wrapper>')
root = xmlutil.make_flat_dict('wrapper')
tmpl = xmlutil.MasterTemplate(root, 1)
result = tmpl.serialize(dict(wrapper=dict(a='foo', b='bar')))
self.assertEqual(result, expected_xml)
expected_xml = ("<?xml version='1.0' encoding='UTF-8'?>\n"
'<ns0:wrapper xmlns:ns0="ns"><ns0:a>foo</ns0:a><ns0:b>bar</ns0:b>'
"</ns0:wrapper>")
root = xmlutil.make_flat_dict('wrapper', ns='ns')
tmpl = xmlutil.MasterTemplate(root, 1)
result = tmpl.serialize(dict(wrapper=dict(a='foo', b='bar')))
self.assertEqual(result, expected_xml)
示例3: construct
def construct(self):
root = xmlutil.TemplateElement('host')
elem = xmlutil.make_flat_dict('resource', selector='host',
subselector='resource')
root.append(elem)
return xmlutil.MasterTemplate(root, 1)
示例4: test_make_flat_dict_with_dicts
def test_make_flat_dict_with_dicts(self):
# Our test object to serialize
obj = {"device": {"id": 1,
"extra_info": {"key1": "value1",
"key2": "value2"}}}
expected_xml = (("<?xml version='1.0' encoding='UTF-8'?>\n"
'<device><id>1</id><extra_info><key2>value2</key2>'
'<key1>value1</key1></extra_info></device>'))
root = xmlutil.make_flat_dict('device', selector='device',
ignore_sub_dicts=True)
extra = xmlutil.make_flat_dict('extra_info', selector='extra_info')
root.append(extra)
master = xmlutil.MasterTemplate(root, 1)
result = master.serialize(obj)
self.assertEqual(expected_xml, result)
示例5: test_make_flat_dict_with_colon_tagname_support
def test_make_flat_dict_with_colon_tagname_support(self):
# Our test object to serialize
obj = {'extra_specs': {'foo:bar': '999'}}
expected_xml = (("<?xml version='1.0' encoding='UTF-8'?>\n"
'<extra_specs><foo:bar xmlns:foo="foo">999</foo:bar>'
'</extra_specs>'))
# Set up our master template
root = xmlutil.make_flat_dict('extra_specs', colon_ns=True)
master = xmlutil.MasterTemplate(root, 1)
result = master.serialize(obj)
self.assertEqual(expected_xml, result)
示例6: make_volume
def make_volume(elem):
elem.set("id")
elem.set("status")
elem.set("size")
elem.set("availabilityZone")
elem.set("createdAt")
elem.set("displayName")
elem.set("displayDescription")
elem.set("volumeType")
elem.set("snapshotId")
attachments = xmlutil.SubTemplateElement(elem, "attachments")
attachment = xmlutil.SubTemplateElement(attachments, "attachment", selector="attachments")
make_attachment(attachment)
metadata = xmlutil.make_flat_dict("metadata")
elem.append(metadata)
示例7: make_volume
def make_volume(elem):
elem.set('id')
elem.set('status')
elem.set('size')
elem.set('availabilityZone')
elem.set('createdAt')
elem.set('displayName')
elem.set('displayDescription')
elem.set('volumeType')
attachments = xmlutil.SubTemplateElement(elem, 'attachments')
attachment = xmlutil.SubTemplateElement(attachments, 'attachment',
selector='attachments')
make_attachment(attachment)
metadata = xmlutil.make_flat_dict('metadata')
elem.append(metadata)
示例8: construct
def construct(self):
return xmlutil.MasterTemplate(xmlutil.make_flat_dict('cloudpipe'), 1)
示例9: make_voltype
def make_voltype(elem):
elem.set("id")
elem.set("name")
extra_specs = xmlutil.make_flat_dict("extra_specs", selector="extra_specs")
elem.append(extra_specs)
示例10: construct
def construct(self):
root = xmlutil.TemplateElement("host")
elem = xmlutil.make_flat_dict("resource", selector="host", subselector="resource")
root.append(elem)
return xmlutil.MasterTemplate(root, 1)
示例11: construct
def construct(self):
extra_specs_dict = xmlutil.make_flat_dict('extra_specs', colon_ns=True)
return xmlutil.MasterTemplate(extra_specs_dict, 1)
示例12: test_make_flat_dict
def test_make_flat_dict(self):
expected_xml = "<?xml version='1.0' encoding='UTF-8'?>\n" "<wrapper><a>foo</a><b>bar</b></wrapper>"
root = xmlutil.make_flat_dict("wrapper")
tmpl = xmlutil.MasterTemplate(root, 1)
result = tmpl.serialize(dict(wrapper=dict(a="foo", b="bar")))
self.assertEqual(result, expected_xml)
示例13: construct
def construct(self):
root = xmlutil.make_flat_dict('extra_specs', selector='extra_specs')
return xmlutil.MasterTemplate(root, 1)