Resource
A managed resource with properties and class/static methods.
Usage
Resource()Parameters
name: str-
Resource name.
capacity: int = 100-
Maximum capacity.
Attributes
| Name | Description |
|---|---|
| available | Available capacity. |
| name | The resource name. |
available
Available capacity.
available: int
name
The resource name.
name: str
Methods
| Name | Description |
|---|---|
| allocate() | Allocate some capacity. |
| from_dict() | Create a Resource from a dictionary. |
| validate_name() | Check whether a resource name is valid. |
allocate()
Allocate some capacity.
Usage
allocate(amount)Parameters
amount: int-
Amount to allocate.
Returns
bool-
True if allocation succeeded.
from_dict()
Create a Resource from a dictionary.
Usage
from_dict(data)Parameters
data: dict-
Dictionary with ‘name’ and optional ‘capacity’ keys.
Returns
Resource-
A new resource instance.
validate_name()
Check whether a resource name is valid.
Usage
validate_name(name)Parameters
name: str-
The name to validate.
Returns
bool-
True if valid.