def construct(self): root = xmlutil.TemplateElement('volumes') elem = xmlutil.SubTemplateElement(root, 'volume', selector='volumes') make_volume(elem) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('users') elem = xmlutil.SubTemplateElement(root, 'user', selector='users') make_user(elem) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('diagnostics') elem = xmlutil.SubTemplateElement(root, xmlutil.Selector(0), selector=xmlutil.get_items) elem.text = 1 return xmlutil.MasterTemplate(root, 1, nsmap=sd_nsmap)
def construct(self): root = xmlutil.TemplateElement('floating_ip', selector='floating_ip') make_float_ip(root) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('server_group', selector='server_group') make_group(root) return xmlutil.MasterTemplate(root, 1, nsmap=server_group_nsmap)
def construct(self): sel = xmlutil.Selector('meta', xmlutil.get_items, 0) root = xmlutil.TemplateElement('meta', selector=sel) root.set('key', 0) root.text = 1 return xmlutil.MasterTemplate(root, 1, nsmap=metadata_nsmap)
def construct(self): root = xmlutil.TemplateElement('flavors') elem = xmlutil.SubTemplateElement(root, 'flavor', selector='flavors') make_flavor(elem, detailed=True) return xmlutil.MasterTemplate(root, 1, nsmap=flavor_nsmap)
def construct(self): root = xmlutil.TemplateElement('extension', selector='extension') make_ext(root) return xmlutil.MasterTemplate(root, 1, nsmap=ext_nsmap)
def construct(self): root = xmlutil.TemplateElement('security_group_rule', selector='security_group_rule') make_rule(root) return xmlutil.MasterTemplate(root, 1, nsmap=sg_nsmap)
def construct(self): root = xmlutil.TemplateElement('zones') elem = xmlutil.SubTemplateElement(root, 'zone', selector='zones') make_zone_entry(elem) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('cells') elem = xmlutil.SubTemplateElement(root, 'cell', selector='cells') make_cell(elem) return xmlutil.MasterTemplate(root, 1, nsmap=cell_nsmap)
def construct(self): root = xmlutil.TemplateElement('version', selector='version') make_version(root) return xmlutil.MasterTemplate(root, 1, nsmap=version_nsmap)
def construct(self): root = xmlutil.TemplateElement('choices') elem = xmlutil.SubTemplateElement(root, 'version', selector='choices') make_version(elem) return xmlutil.MasterTemplate(root, 1, nsmap=version_nsmap)
def construct(self): return xmlutil.MasterTemplate(xmlutil.make_flat_dict('attribute'), 1)
def test__serialize(self): # Our test object to serialize obj = { 'test': { 'name': 'foobar', 'values': [1, 2, 3, 4], 'attrs': { 'a': 1, 'b': 2, 'c': 3, 'd': 4, }, 'image': { 'name': 'image_foobar', 'id': 42, }, }, } # Set up our master template root = xmlutil.TemplateElement('test', selector='test', name='name') value = xmlutil.SubTemplateElement(root, 'value', selector='values') value.text = xmlutil.Selector() attrs = xmlutil.SubTemplateElement(root, 'attrs', selector='attrs') xmlutil.SubTemplateElement(attrs, 'attr', selector=xmlutil.get_items, key=0, value=1) master = xmlutil.MasterTemplate(root, 1, nsmap=dict(f='foo')) # Set up our slave template root_slave = xmlutil.TemplateElement('test', selector='test') image = xmlutil.SubTemplateElement(root_slave, 'image', selector='image', id='id') image.text = xmlutil.Selector('name') slave = xmlutil.SlaveTemplate(root_slave, 1, nsmap=dict(b='bar')) # Attach the slave to the master... master.attach(slave) # Try serializing our object siblings = master._siblings() nsmap = master._nsmap() result = master._serialize(None, obj, siblings, nsmap) # Now we get to manually walk the element tree... self.assertEqual(result.tag, 'test') self.assertEqual(len(result.nsmap), 2) self.assertEqual(result.nsmap['f'], 'foo') self.assertEqual(result.nsmap['b'], 'bar') self.assertEqual(result.get('name'), obj['test']['name']) for idx, val in enumerate(obj['test']['values']): self.assertEqual(result[idx].tag, 'value') self.assertEqual(result[idx].text, str(val)) idx += 1 self.assertEqual(result[idx].tag, 'attrs') for attr in result[idx]: self.assertEqual(attr.tag, 'attr') self.assertEqual(attr.get('value'), str(obj['test']['attrs'][attr.get('key')])) idx += 1 self.assertEqual(result[idx].tag, 'image') self.assertEqual(result[idx].get('id'), str(obj['test']['image']['id'])) self.assertEqual(result[idx].text, obj['test']['image']['name']) templ = xmlutil.Template(None) self.assertEqual(templ.serialize(None), '')
def construct(self): return xmlutil.MasterTemplate(xmlutil.make_flat_dict('keypair'), 1)
def construct(self): elem = xmlutil.TemplateElement('test') return xmlutil.MasterTemplate(elem, 1)
def construct(self): root = xmlutil.TemplateElement('certificate', selector='certificate') make_certificate(root) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('tenant_usages') elem = xmlutil.SubTemplateElement(root, 'tenant_usage', selector='tenant_usages') make_usage(elem) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('domain_entry', selector='domain_entry') make_domain_entry(root) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('servers') elem = xmlutil.SubTemplateElement(root, 'server', selector='servers') make_server(elem) xmlutil.make_links(root, 'servers_links') return xmlutil.MasterTemplate(root, 1, nsmap=server_nsmap)
def construct(self): root = xmlutil.TemplateElement('interface', selector='interface') _make_interface_elem(root) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('servers') elem = xmlutil.SubTemplateElement(root, 'server', selector='servers') make_server(elem, detailed=True) return xmlutil.MasterTemplate(root, 1, nsmap=server_nsmap)
def construct(self): root = xmlutil.TemplateElement('host') root.set('host') root.set('power_action') return xmlutil.MasterTemplate(root, 1)
def construct(self): extra_specs_dict = xmlutil.make_flat_dict('extra_specs', colon_ns=True) return xmlutil.MasterTemplate(extra_specs_dict, 1)
def construct(self): root = xmlutil.TemplateElement('snapshot', selector='snapshot') make_snapshot(root) return xmlutil.MasterTemplate(root, 1)
def construct(self): sel = xmlutil.Selector(xmlutil.get_items, 0) root = xmlutil.TemplateElement('extra_spec', selector=sel) root.set('key', 0) root.text = 1 return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('volumeAttachment', selector='volumeAttachment') make_attachment(root) return xmlutil.MasterTemplate(root, 1)
def construct(self): root = xmlutil.TemplateElement('instanceAction', selector='instanceAction') make_action(root) return xmlutil.MasterTemplate(root, 1)