JSON RPC service

The JSONRPC implementation consists of a clacks agent plugin (JSONRPCService) and a WSGI application (JsonRpcApp). The first is implemented as a handler plugin, so it is going to be invoked on agent startup. It takes care of registering the WSGI application to the clacks.agent.httpd.HTTPService.


class clacks.agent.jsonrpc_service.JSONRPCService

This is the JSONRPC clacks agent plugin which is registering an instance of clacks.agent.jsonrpc_service.JsonRpcApp into the clacks.agent.httpd.HTTPService.

It is configured thru the [jsonrpc] section of your clacks configuration:

Key Description
path Path to register the service in HTTP
cookie-lifetime Seconds of authentication cookie lifetime

Example:

[jsonrpc]
path = /rpc
cookie-lifetime = 3600
serve()

Start JSONRPC service for this clacks service provider.

stop()

Stop serving the JSONRPC service for this clacks service provider.

class clacks.agent.jsonrpc_service.JsonRpcApp(dispatcher)

This is the WSGI application wich is responsible for serving the clacks.agent.command.CommandRegistry via HTTP/JSONRPC.

authenticate(user=None, password=None)

Use the AMQP connection to authenticate the incoming HTTP request.

Parameter Description
user User name to authenticate with
password Password

Return: True on success

process(req, environ)

Process an incoming JSONRPC request and dispatch it thru the CommandRegistry.

Parameter Description
req Incoming Request
environ WSGI environment

Return: varries

JSON RPC objects

class clacks.agent.jsonrpc_objects.JSONRPCObjectMapper

The JSONRPCObjectMapper is a clacks agent plugin that implements a stack which can handle object instances. These can be passed via JSONRPC using the __jsonclass__ helper attribute and allows remote proxies to emulate the object on the stack. The stack can hold objects that have been retrieved by their OID using the clacks.common.components.objects.ObjectRegistry.

Example:

>>> from clacks.common.components import AMQPServiceProxy
>>> # Create connection to service
>>> proxy = >>> AMQPServiceProxy('amqps://admin:secret@amqp.example.net/org.clacks')
>>> pm = proxy.openObject('libinst.diskdefinition')
>>> pm.getDisks()
[]
>>> proxy.closeObject(str(pm))
>>>

This will indirectly use the object mapper on the agent side.

closeObject(ref)

Note

This method will be exported by the CommandRegistry.

Close an object by its reference. This will free the object on the agent side.

Parameter Description
ref UUID / object reference
dispatchObjectMethod(ref, method, *args)

Note

This method will be exported by the CommandRegistry.

Call a member method of the referenced object.

Parameter Description
ref UUID / object reference
method Method name
args Arguments to pass to the method

Return: mixed

getObjectProperty(ref, name)

Note

This method will be exported by the CommandRegistry.

Get a property of an existing stack object.

Parameter Description
ref UUID / object reference
name Property name

Return: mixed

listObjectOIDs()

Note

This method will be exported by the CommandRegistry.

Provide a list of domain wide available object OIDs.

Return: list

openObject(user, oid, *args, **kwargs)

Note

This method will be exported by the CommandRegistry.

Open object on the agent side. This creates an instance on the stack and returns an a JSON description of the object and it’s values.

Parameter Description
oid OID of the object to create
args/kwargs Arguments to be used when getting an object instance

Return: JSON encoded object description

reloadObject(user, instance_uuid)

Note

This method will be exported by the CommandRegistry.

Opens a copy of the object given as instance_uuid and closes the original instance.

removeObject(user, oid, *args, **kwargs)

Note

This method will be exported by the CommandRegistry.

Open object on the agent side and calls its remove method

Parameter Description
oid OID of the object to create
args/kwargs Arguments to be used when getting an object instance

Return: True

setObjectProperty(ref, name, value)

Note

This method will be exported by the CommandRegistry.

Set a property on an existing stack object.

Parameter Description
ref UUID / object reference
name Property name
value Property value