paradrop.core.agent package

Submodules

paradrop.core.agent.http module

class CurlRequestDriver[source]

Bases: paradrop.core.agent.http.HTTPRequestDriver

code_pattern = <_sre.SRE_Pattern object>
curl = <MagicMock name='mock.Curl()' id='140589432849104'>
header_pattern = <_sre.SRE_Pattern object>
lock = <twisted.internet.defer.DeferredLock object>
receive(ignore)[source]

Receive response from curl and convert it to a response object.

receiveHeaders(header_line)[source]
request(method, url, body=None)[source]
class HTTPRequestDriver[source]

Bases: object

request(method, url, body)[source]
setHeader(key, value)[source]
class HTTPResponse(data=None)[source]

Bases: object

class JSONReceiver(response, finished)[source]

Bases: twisted.internet.protocol.Protocol

JSON Receiver

A JSONReceiver object can be used with the twisted HTTP client to receive data from a request and provide it to a callback function when complete.

Example (response came from an HTTP request): finished = Deferred() response.deliverBody(JSONReceiver(finished)) finished.addCallback(func_that_takes_result)

Some error conditions will result in the callback firing with a result of None. The receiver needs to check for this. This seems to occur on 403 errors where the server does not return any data, but twisted just passes us a ResponseDone object the same type as a normal result.

connectionLost(reason)[source]

internal: handles connection close events.

dataReceived(data)[source]

internal: handles incoming data.

class PDServerRequest(path, driver=<class 'paradrop.core.agent.http.CurlRequestDriver'>, setAuthHeader=True)[source]

Bases: object

Make an HTTP request to pdserver.

The API is assumed to use application/json for sending and receiving data. Authentication is automatically handled here if the router is provisioned.

We handle missing, invalid, or expired tokens by making the request and detecting a 401 (Unauthorized) response. We request a new token and retry the failed request. We do this at most once and return failure if the second attempt returns anything other than 200 (OK).

PDServerRequest objects are not reusable; create a new one for each request.

URL String Substitutions: router_id -> router id

Example: /routers/{router_id}/states -> /routers/halo06/states

get(**query)[source]
classmethod getServerInfo(c)[source]

Return the information needed to send API messages to the server.

This can be used by an external program (e.g. pdinstall).

patch(*ops)[source]

Expects a list of operations in jsonpatch format (http://jsonpatch.com/).

An example operation would be: {‘op’: ‘replace’, ‘path’: ‘/completed’, ‘value’: True}

post(**data)[source]
put(**data)[source]
receiveResponse(response)[source]

Intercept the response object, and if it’s a 401 authenticate and retry.

request()[source]
classmethod resetToken(c)[source]

Reset the auth token, to be called if the router’s identity has changed.

token = None
class PDServerResponse(response, data=None)[source]

Bases: object

A PDServerResponse object contains the results of a request to pdserver.

This wraps twisted.web.client.Response (cannot be subclassed) and exposes the same variables in addition to a ‘data’ variables. The ‘data’ variable, if not None, is the parsed object from the response body.

class TwistedRequestDriver[source]

Bases: paradrop.core.agent.http.HTTPRequestDriver

pool = <twisted.web.client.HTTPConnectionPool object>
receive(response)[source]

Receive response from twisted web client and convert it to a PDServerResponse object.

request(method, url, body=None)[source]
sem = <twisted.internet.defer.DeferredSemaphore object>
urlEncodeParams(data)[source]

Return data URL-encoded.

This function specifically handles None and boolean values to convert them to JSON-friendly strings (e.g. None -> ‘null’).

paradrop.core.agent.reporting module

class ReportSender(model='states', max_retries=None)[source]

Bases: object

increaseDelay()[source]
send(report)[source]
class StateReport[source]

Bases: object

toJSON()[source]
class StateReportBuilder[source]

Bases: object

prepare()[source]
class TelemetryReportBuilder[source]

Bases: object

prepare()[source]
sendStateReport()[source]
sendTelemetryReport()[source]

paradrop.core.agent.wamp_session module

The WAMP session of the paradrop daemon

class WampSession(*args, **kwargs)[source]

Bases: paradrop.base.cxbr.BaseSession

onChallenge(challenge)[source]
onConnect()[source]
onDisconnect()[source]
onJoin(*args, **kwargs)[source]
onLeave(details)[source]
classmethod set_update_fetcher(update_fetcher)[source]
update(pdid, data)[source]
update_fetcher = None
updatesPending(*args, **kwargs)[source]

Module contents