The cinder.api.xmlutil Module

class ConstantSelector(value)

Bases: object

Returns a constant.

class EmptyStringSelector(*chain)

Bases: cinder.api.xmlutil.Selector

Returns the empty string if Selector would return None.

class MasterTemplate(root, version, nsmap=None)

Bases: cinder.api.xmlutil.Template

Represent a master template.

Master templates are versioned derivatives of templates that additionally allow slave templates to be attached. Slave templates allow modification of the serialized result without directly changing the master.

attach(*slaves)

Attach one or more slave templates.

Attaches one or more slave templates to the master template. Slave templates must have a root element with the same tag as the master template. The slave template’s apply() method will be called to determine if the slave should be applied to this master; if it returns False, that slave will be skipped. (This allows filtering of slaves based on the version of the master template.)

copy()

Return a copy of this master template.

class Selector(*chain)

Bases: object

Selects datum to operate on from an object.

class SlaveTemplate(root, min_vers, max_vers=None, nsmap=None)

Bases: cinder.api.xmlutil.Template

Represent a slave template.

Slave templates are versioned derivatives of templates. Each slave has a minimum version and optional maximum version of the master template to which they can be attached.

apply(master)

Hook method for determining slave applicability.

An overridable hook method used to determine if this template is applicable as a slave to a given master template. This version requires the master template to have a version number between min_vers and max_vers.

Parameters:master – The master template to test.
SubTemplateElement(parent, tag, attrib=None, selector=None, subselector=None, **extra)

Create a template element as a child of another.

Corresponds to the etree.SubElement interface. Parameters are as for TemplateElement, with the addition of the parent.

class Template(root, nsmap=None)

Bases: object

Represent a template.

apply(master)

Hook method for determining slave applicability.

An overridable hook method used to determine if this template is applicable as a slave to a given master template.

Parameters:master – The master template to test.
make_tree(obj)

Create a tree.

Serializes an object against the template. Returns an Element node with appropriate children.

Parameters:obj – The object to serialize.
serialize(obj, *args, **kwargs)

Serialize an object.

Serializes an object against the template. Returns a string with the serialized XML. Positional and keyword arguments are passed to etree.tostring().

Parameters:obj – The object to serialize.
tree()

Return string representation of the template tree.

Returns a representation of the template as a string, suitable for inclusion in debug logs.

unwrap()

Unwraps a template to return a template element.

wrap()

Wraps a template element to return a template.

class TemplateBuilder

Bases: object

Template builder.

This class exists to allow templates to be lazily built without having to build them each time they are needed. It must be subclassed, and the subclass must implement the construct() method, which must return a Template (or subclass) instance. The constructor will always return the template returned by construct(), or, if it has a copy() method, a copy of that template.

construct()

Construct a template.

Called to construct a template instance, which it must return. Only called once.

class TemplateElement(tag, attrib=None, selector=None, subselector=None, **extra)

Bases: object

Represent an element in the template.

append(elem)

Append a child to the element.

apply(elem, obj)

Apply text and attributes to an etree.Element.

Applies the text and attribute instructions in the template element to an etree.Element instance.

Parameters:
  • elem – An etree.Element instance.
  • obj – The base object associated with this template element.
extend(elems)

Append children to the element.

get(key)

Get an attribute.

Returns a callable which performs datum selection.

Parameters:key – The name of the attribute to get.
getAttrib(obj)

Get attribute.

insert(idx, elem)

Insert a child element at the given index.

items()

Return the attribute names and values.

keys()

Return the attribute names.

remove(elem)

Remove a child element.

render(parent, obj, patches=None, nsmap=None)

Render an object.

Renders an object against this template node. Returns a list of two-item tuples, where the first item is an etree.Element instance and the second item is the datum associated with that instance.

Parameters:
  • parent – The parent for the etree.Element instances.
  • obj – The object to render this template element against.
  • patches – A list of other template elements to apply when rendering this template element.
  • nsmap – An optional namespace dictionary to attach to the etree.Element instances.
set(key, value=None)

Set an attribute.

Parameters:
  • key – The name of the attribute to set.
  • value – A callable taking an object and optional boolean do_raise indicator and returning the datum bound to the attribute. If None, a Selector() will be constructed from the key. If a string, a Selector() will be constructed from the string.
text

Template element text.

Either None or a callable taking an object and optional boolean do_raise indicator and returning the datum bound to the text of the template element.

tree()

Return string representation of the template tree.

Returns a representation of the template rooted at this element as a string, suitable for inclusion in debug logs.

unwrap()

Unwraps a template to return a template element.

will_render(datum)

Hook method.

An overridable hook method to determine whether this template element will be rendered at all. By default, returns False (inhibiting rendering) if the datum is None.

Parameters:datum – The datum associated with this template element.
wrap()

Wraps a template element to return a template.

get_items(obj)

Get items in obj.

make_flat_dict(name, selector=None, subselector=None, ns=None)

Utility for simple XML templates.

Simple templates are templates that traditionally used XMLDictSerializer with no metadata.

Returns a template element where the top-level element has the given tag name, and where sub-elements have tag names derived from the object’s keys and text derived from the object’s values.

This only works for flat dictionary objects, not dictionaries containing nested lists or dictionaries.

Attach an Atom <links> element to the parent.

validate_schema(xml, schema_name)

Previous topic

The cinder.api.views.versions Module

Next topic

The cinder.backup.api Module

Project Source

This Page