ResourceManager
Manages the lifecycle of resources.
Usage
ResourceManager()Provides methods for creating, reading, updating, deleting, listing, and reporting on resources.
Parameters
namespace: str-
The namespace for this manager instance.
Examples
>>> mgr = ResourceManager("production")
>>> mgr.list_resources()
[]Methods
| Name | Description |
|---|---|
| __init__() | Initialize the ResourceManager. |
| add() | Add a new resource. |
| count() | Return the number of managed resources. |
| get() | Get a resource by ID. |
| list_resources() | List all managed resources. |
| remove() | Remove a resource by ID. |
| report() | Generate a status report. |
__init__()
Initialize the ResourceManager.
Usage
__init__(namespace)Parameters
namespace: str-
The namespace for this manager.
add()
Add a new resource.
Usage
add(name)Parameters
name: str-
The name of the resource to add.
Returns
dict-
The added resource.
Examples
>>> mgr = ResourceManager("test")
>>> mgr.add("item-1")
{'name': 'item-1', 'id': 1}count()
Return the number of managed resources.
Usage
count()Returns
int-
The total count of resources.
get()
Get a resource by ID.
Usage
get(id)Parameters
id: int-
The resource identifier.
Returns
dict-
The resource data.
list_resources()
List all managed resources.
Usage
list_resources()Returns
list-
A list of all resource dictionaries.
Examples
>>> mgr = ResourceManager("test")
>>> mgr.list_resources()
[]remove()
Remove a resource by ID.
Usage
remove(id)Parameters
id: int-
The resource identifier to remove.
Returns
bool-
True if the resource was removed.
report()
Generate a status report.
Usage
report()Returns
dict-
A report with namespace and resource count.
Examples
>>> mgr = ResourceManager("prod")
>>> mgr.report()
{'namespace': 'prod', 'count': 0}