Resource Pool

A managed pool of abstract resources that can be allocated and released. A resource pool offers a simple way to store JSON entities (i.e. “resources”), which can be allocated/de-allocated. Resources are grouped by “type” so you can use one pool for different resources.

When allocating resources, the client will receive a random resource (there is no way to determine which resource will be allocated). Several resources can be allocated at once by providing a count parameter. The response will contain a list of resource JSON entities. If there are not enough free resources available, the command will fail with an error. Allocated resources can be released by body and type.

Service Descriptor

To use a resource pool, add an interface with the following pins to your manifest:

allocate-resources:  send-command(string type, int count => list<object> resources)
release-resources:   send-command(string type, list<object> resources)

An extended list of pool commands is available through the REST API:

allocate-resources:  receive-command(string type, int count => list<object> resources)
release-resources:   receive-command(string type, list<object> resources)
list-resources:      receive-command(string type => list<object> free, list<object> busy, list<object> disabled)
list-all-resources:  receive-command( => map<string, record<list<object> free, list<object> busy, list<object> disabled>> resources)
disable-resources:   receive-command(string type, list<object> resources)
enable-resources:    receive-command(string type, list<object> resources)

Configuration

A resource pool is configured through a mapping of available resources in YAML format. The mapping key is a resource type and the value is a resource list. For example:

vm:
 - "192.168.0.1"
 - "192.168.0.2"
db:
 - { master: "127.0.0.1", slave: "127.0.0.2" }
 - { master: "127.0.0.3", slave: "127.0.0.4" }

Commands

Name Definition
list-resources List resources of a given type, grouped by status.
list-all-resources List resources of all types, grouped by status.
allocate-resources Allocate one or more resources of a given type.
release-resources Release previously allocated resources.
disable-resources Temporarily disable some resources (e.g. disable for maintenance purposes).
enable-resource Enable previously disabled resources.

Example

We would like to create a pool of virtual machines with IP addresses and user identity information. This can be achieved by creating a resource pool with the following configuration:

vm:
 - { ip: "192.168.0.1", identity: "ubuntu" }
 - { ip: "192.168.0.2", identity: "root" }
 - { ip: "192.168.0.3", identity: "ubuntu" }

We can then allocate virtual machines using a serviceCall action.

steps:
 - allocate:
     action: serviceCall
     parameters:
       service: resource-pool
       command: allocate-resources
       arguments:
         type: vm
         count: 2
     output:
       vms: result

The result variable will contain an array of two allocated VMs (e.g. the first and the second VMs) under the resources key.

{ resources: [ { ip: "192.168.0.1", identity: "ubuntu" }, { ip: "192.168.0.2", identity: "root" } ] }

When you no longer need these VMs, you can release them.

steps:
 - release:
     action: serviceCall
     parameters:
       service: resource-pool
       command: release-resource
       arguments:
         type: vm
         resources: {$.vms.resources}