The diskimage_builder.block_device.plugin Module

The diskimage_builder.block_device.plugin Module

class diskimage_builder.block_device.plugin.NodeBase(name, state)

Bases: object

A configuration node entry

This is the main driver class for dib-block-device operation.

The final operations graph is composed of instantiations of this class. The graph undergoes a topological sort (i.e. is linearised in dependency order) and each node has create() called in order to perform its operations.

Every node has a unique string name. This is its key in the graph and used for edge relationships. Implementations must ensure they initalize it; e.g.

class FooNode(NodeBase):
    def __init__(name, arg1, ...):
        super(FooNode, self).__init__(name)
add_rollback(func, *args, **kwargs)

Add a call for rollback

Functions registered with this method will be called in reverse-order in the case of failures during Nodebase.create().

Parameters:
  • func – function to call
  • args – arguments
  • kwargs – keyword arguments
Returns:

None

cleanup()

Cleanup actions

Actions to taken when dib-block-device cleanup is called. This is the cleanup path in the success case. The nodes are called in the reverse order to create()

Returns:None
create()

Main creation driver

This is the main driver function. After the graph is linearised, each node has it’s create() function called.

Raises:Exception – A failure should raise an exception. This will initiate a rollback. See Nodebase.add_rollback().
Returns:None
delete()

Cleanup actions

Actions to taken when dib-block-device delete is called. This is the cleanup path in case of a reported external failure. The nodes are called in the reverse order to create()

Returns:None
get_edges()

Return the dependencies/edges for this node

This function will be called after all nodes are created (this is because some plugins need to know the global state of all nodes to decide their dependencies).

This function returns a tuple with two lists

  • edges_from : a list of node names that point to us
  • edges_to : a list of node names we point to

In most cases, node creation will have saved a single parent that was given in the base parameter of the configuration. A usual return might look like:

def get_edges(self):
    return ( [self.base], [] )

Some nodes (level0) don’t have a base, however

get_name()
rollback()

Initiate rollback

Call registered rollback in reverse order. This method is called by the driver in the case of failures during Nodebase.create().

Return None:
umount()

Umount actions

Actions to taken when dib-block-device umount is called. The nodes are called in the reverse order to create()

Returns:None
class diskimage_builder.block_device.plugin.PluginBase

Bases: object

The base plugin object

This is the base plugin object. Plugins are an instantiation of this class. There should be an entry-point (see setup.cfg) defined under diskimage_builder.block_device.plugin for each plugin, e.g.

foo = diskimage_builder.block_device.levelX.foo:Foo

A configuration entry in the graph config that matches this entry point will create an instance of this class, e.g.

foo:
  name: foo_node
  base: parent_node
  argument_a: bar
  argument_b: baz

The __init__ function will be passed three arguments:

config
The full configuration dictionary for the entry. A unique name entry can be assumed. In most cases a base entry will be present giving the parent node (see NodeBase.get_edges()).
state
A reference to the gobal state dictionary. This should be passed to NodeBase.__init__() on node creation
defaults
The global defaults dictionary (see --params)

get_nodes() should return the node object(s) created by the config for insertion into the final configuration graph. In the simplest case, this is probably a single node created during instantiation. e.g.

class Foo(PluginBase):

  def __init__(self, config, defaults, state):
      super(Foo, self).__init__()
      self.node = FooNode(config.name, state, ...)

  def get_nodes(self):
      return [self.node]

Some plugins require more, however.

get_nodes()

Return nodes created by the plugin

Returns:a list of NodeBase objects for insertion into the graph
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.