Resource

class activelogic.Resource

This is the parent class for all resources.

Connection instantiates all resources:

c = await conn.config()
rs = await conn.ruleset()

Each resource defines a subset of the system’s configuration and has its own set of privileges in the user database:

  • None - User can’t access the resource at all.

  • Read - User can run read-only commands on the resource.

  • Write - User can run all commands on the resource.

A session attached to the resource will always be in a transaction. There is also implicit locks on each resource that are taken when the first manipulative command is sent, and released when changes are committed or rolled back.

Changes to database-bound resources, such like Config and Ruleset must be committed to take effect. This either can be done using a context manager or by just calling commit():

# Alt 1.
async with await conn.config() as c:
    await c.update_value('DRDL_ENABLED', True)

# Alt 2.
await c.update_value('DRDL_ENABLED', True)
await c.commit()

Issuing commands on an outdated resource will result in that PLDBNewDataCommitted is raised.

Resource.machineid

The machine id of the system that owns the resource.

>>> res.machineid
'001122334455'
Resource.distversion

The firmware version running on the system that owns the resource.

>>> res.distversion
'22.20.06.1'

Transactions

Resource.set_commit_message(commit_message)

Sets the commit message of the next commit.

Parameters

commit_message (str) –

This function is typically used for setting proper commit message in context manager-based commits:

>>> with conn.config() as c:
...     c.update("GEOLOGIC_ENABLED", True)
...     c.set_commit_message("Enable GeoLogic function")
async Resource.commit(commit_message=None)

Stores the current transaction to the database.

Parameters

commit_message (str) – Message recorded in the commit log.

This command makes your changes visible to others.

It is usually a good practice to commit changes in batches. In particular if changes are committed to Ruleset. This will reload the ruleset and take a lot of CPU resources from the system.

async Resource.rollback()

Aborts the current transaction and discards the changes.

This also automatically happens if your connection drops or you exit the program without committing your changes.

Resource Cache

Resource.enable_cache(enable)

Enables or disables the caching mechanism for the resource.

Parameters

enable (bool) – True or False.

For optimal performance, caching should always be enabled. All resources have their caching enabled by default.

Resource.invalidate_cache(cache_id='')

Invalidates a specific cache, or all caches tied to the current resource.

The cache is always invalidated if the current transaction is rolled back or committed.

Parameters

cache_id (str) – Id of the cache to invalidate, or empty if all caches should be invalidated.

Miscellaneous

async Resource.ping(data)

Sends a message to session to test if it is up.

Parameters

data (bytes) – Data to send.

Returns

The echo reply from remote session.

>>> res.ping(b"hello")
b'hello'