Skip to content

Commit

Permalink
update sqlite plugin docs
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-dileo committed Jul 30, 2015
1 parent 14d3960 commit 90209cc
Showing 1 changed file with 60 additions and 7 deletions.
67 changes: 60 additions & 7 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ The values of the attributes can be either strings, numbers, lists, dictionaries
Plugins can be used to allocate resources on the server side and then pass the result of the allocation back to the client via the definition. The supported plugins are:

- **allocate(resource\_pool)** - allocates an available resource from a file-based resource pool
- **sqlite(resource\_pool)** - allocates an available resource from a sqlite database


.. note::

Expand Down Expand Up @@ -656,7 +658,7 @@ Actions
``[data_root]/actions/`` contains the set of all actions available for use in
definitions.

New custom actions to-be referenced from definitions can be added to
New custom actions to-be referenced from definitions can be added to
``[data_root]/actions/``. These will be loaded on-demand and do not require
a restart of the ZTPServer. See ``[data_root]/actions`` for examples.

Expand Down Expand Up @@ -765,22 +767,22 @@ just standard EOS configuration blocks.
Plugins for allocating resources
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Plugins for allocating resources from resource pools
are located in ``[data_root]/plugins/`` and are referenced
Plugins for allocating resources from resource pools
are located in ``[data_root]/plugins/`` and are referenced
by ``<filename>(<resource_pool>)``.

Each plugin contains a ``main`` function with the following signature:

def main(node_id, pool):
def main(node_id, pool):
...

where:
- ``node_id`` is the unique_id of the node being provisioned
- ``pool`` is the name of the resource pool from which an attribute is being allocated

New custom plugins to-be referenced from definitions can be added to
New custom plugins to-be referenced from definitions can be added to
``[data_root]/plugins/``. These will be loaded on-demand and do not require
a restart of the ZTPServer. See ``[data_root]/plugins/test`` for a very basic
a restart of the ZTPServer. See ``[data_root]/plugins/test`` for a very basic
example.

**allocate(resource_pool)**
Expand Down Expand Up @@ -839,6 +841,57 @@ associated to it back to ``null``, by editing the resource file.
Alternatively, ``$ztps --clear-resources`` can be used in order to free
all resources in all file-based resource files.

**sqlite(resource_pool)**

Allocates a resource from a pre-filled sqlite database. The database
is defined by the global variable, 'DB_URL' within the plugin. The database
can include multiple tables, but the value passed into the
'sqlite(resource_pool)' function will be used to look for an available resource.

Table structure should be as follows with the exact column names:

| node_id | key |
|:-------:|---------|
| NULL | 1.1.1.1 |
| NULL | 1.1.1.2 |
| NULL | 1.1.1.3 |

Which can be created with statements like:

``CREATE TABLE `mgmt_subnet`(key TEXT, node_id TEXT)``

and add entries with:

``INSERT INTO `mgmt_subnet` VALUES('1.1.1.1', NULL)``

When a resource is added, the node_id row will be updated
to include the System ID from the switch.

| node_id | key |
|--------------|---------|
| 001122334455 | 1.1.1.1 |
| NULL | 1.1.1.2 |
| NULL | 1.1.1.3 |
On subsequent attempts to allocate the resource to the same node,
ztpserver will first check to see whether the node has already been
allocated a resource from the pool. If it has, it will reuse the
resource instead of allocating a new one.

Definition example:

```
actions:
-
action: add_config
attributes:
url: files/templates/ma1.templates
variables:
ipaddress: sqlite('mgmt_subnet')
name: "configure ma1"
```

Config-handlers
~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 90209cc

Please sign in to comment.