volttron.platform package

Core package.

volttron.platform.get_address()[source]

Return the VIP address of the platform If the VOLTTRON_VIP_ADDR environment variable is set, it used. Otherwise, it is derived from get_home().

volttron.platform.get_examples(agent_dir)[source]
volttron.platform.get_home()[source]

Return the home directory with user and variables expanded.

If the VOLTTRON_HOME environment variable is set, it used. Otherwise, the default value of ‘~/.volttron’ is used.

volttron.platform.get_ops(agent_dir=None)[source]
volttron.platform.get_services_core(agent_dir=None)[source]
volttron.platform.get_volttron_data()[source]
volttron.platform.get_volttron_root()[source]

Returns the root folder where the volttron code base resideds on disk.

Returns:absolute path to root folder
volttron.platform.is_instance_running(volttron_home=None)[source]
volttron.platform.is_rabbitmq_available()[source]
volttron.platform.set_home(home=None)[source]

Set the home directory with user and variables expanded.

If the home is sent in, it used. Otherwise, the default value of ‘~/.volttron’ is used.

Subpackages

Submodules

volttron.platform.aip module

volttron.platform.async module

Run gevent Greenlets in their own threads.

Supports killing threads and executing callbacks from other threads.

class volttron.platform.async.AsyncCall(hub=None)[source]

Bases: object

Send functions to another thread’s gevent hub for execution.

send(receiver, func, *args, **kwargs)[source]

Send a function to the hub to be called there.

All the arguments to this method are placed in a queue and the hub is signaled that a function is ready. When the hub switches to this handler, the functions are iterated over, each being called with its results sent to the receiver.

func is called with args and kwargs in the thread of the associated hub. If receiver is None, results are ignored and errors are printed when exceptions occur. Otherwise, receiver is called with the 2-tuple (exc_info, result). If an unhandled exception occurred, exc_info is the 3-tuple returned by sys.exc_info() and result is None. Otherwise exc_info is None and the result is func’s return value.

Note that receiver is called from the hub’s thread and may need to be injected into the thread of the receiver.

class volttron.platform.async.Threadlet(*args, **kwargs)[source]

Bases: threading.Thread

A subclass of threading.Thread supporting gevent Greenlets.

The run method is executed in the thread’s main greenlet and the thread will exit when that method returns. Other threads may run callbacks within this thread using the send() method. Unlike the base class, threading.Thread, daemon is set by default.

kill(exception=<class 'greenlet.GreenletExit'>)[source]

Raise GreenletExit or other exception in the main greenlet.

send(callback, *args, **kwargs)[source]

Execute callback in this thread’s hub.

exception volttron.platform.async.GreenletExit

Bases: exceptions.BaseException

volttron.platform.auth module

volttron.platform.certs module

volttron.platform.config module

volttron.platform.control module

volttron.platform.instance_setup module

volttron.platform.jsonrpc module

Implementation of JSON-RPC 2.0 with support for bi-directional calls.

See http://www.jsonrpc.org/specification for the complete specification.

exception volttron.platform.jsonrpc.Error(code, message, data=None)[source]

Bases: exceptions.Exception

Raised when a recoverable JSON-RPC protocol error occurs.

exception volttron.platform.jsonrpc.MethodNotFound(code, message, data=None)[source]

Bases: volttron.platform.jsonrpc.Error

Raised when remote method is not implemented.

exception volttron.platform.jsonrpc.RemoteError(message, **exc_info)[source]

Bases: exceptions.Exception

Report the details of an error which occurred remotely.

Instances of this exception are usually created by exception_from_json(), which uses the ‘detail’ element of the JSON-RPC error for message, if it is set, otherwise the JSON-RPC error message. The exc_info argument is set from the ‘exception.py’ element associated with an error code of -32000 (UNHANDLED_EXCEPTION). Typical keys in exc_info are exc_type, exc_args, and exc_tb (if tracebacks are allowed) which are stringified versions of the tuple returned from sys.exc_info().

print_tb(file=<open file '<stderr>', mode 'w'>)[source]

Pretty print the traceback in the standard format.

class volttron.platform.jsonrpc.Dispatcher[source]

Bases: object

Parses and directs JSON-RPC 2.0 requests/responses.

Parses a JSON-RPC message conatained in a dictionary (JavaScript object) or a batch of messages (list of dictionaries) and dispatches them appropriately.

Subclasses must implement the serialize and deserialize methods with the JSON library of choice. The exception, result, error, method and batch handling methods should also be implemented.

batch(**kwds)[source]

Context manager for batch requests.

Entered before processing a batch request and exited afterward.

batch_call(requests)[source]

Create and return a request for a batch of method calls.

requests is an iterator of lists or tuples with 4 items each: ident, method, args, kwargs. These are the same 4 arguments required by the call() method. The first (ident) element may be None to indicate a notification.

call(ident, method, args=None, kwargs=None)[source]

Create and return a request for a single method call.

deserialize(json_string)[source]

Unpack a JSON string and return Python object(s).

dispatch(json_string, context=None)[source]

Dispatch a JSON-RPC message and return a response or None.

error(response, ident, code, message, data=None, context=None)[source]

Called when an error resposne is received.

exception(response, ident, message, context=None)[source]

Called for response errors.

Typically called when a response, such as an error, does not contain all the necessary members and sending an error to the remote peer is not possible. Also called when serializing a response fails.

method(request, ident, name, args, kwargs, batch=None, context=None)[source]

Called to get make method call and return results.

request is the original JSON request (as dict). name is the name of the method requested. Only one of args or kwargs will contain parameters. If method is being executed as part of a batch request, batch will be the value returned from the batch() context manager.

This method should raise NotImplementedError() if the method is unimplemented. Otherwise, it should return the result of the method call or raise an exception. If the raised exception has a traceback attribute, which should be a string (if set), it will be sent back in the returned error. An exc_info attribute may also be set which must be a dictionary and will be used as the basis for the exception.py member of the returned error.

notify(method, args=None, kwargs=None)[source]

Create and return a request for a single notification.

result(response, ident, result, context=None)[source]

Called when a result response is received.

serialize(json_obj)[source]

Pack compatible Python objects into and return JSON string.

volttron.platform.keystore module

Module for storing local public and secret keys and remote public keys

class volttron.platform.keystore.BaseJSONStore(filename, permissions=384)[source]

Bases: object

JSON-file-backed store for dictionaries

load()[source]
remove(key)[source]
store(data)[source]
update(new_data)[source]
class volttron.platform.keystore.KeyStore(filename=None)[source]

Bases: volttron.platform.keystore.BaseJSONStore

Handle generation, storage, and retrival of CURVE key pairs

generate()[source]

Generate and store new key pair

static generate_keypair_dict()[source]

Generate and return new keypair as dictionary

static get_default_path()[source]
isvalid()[source]

Check if key pair is valid

public

Return encoded public key

secret

Return encoded secret key

class volttron.platform.keystore.KnownHostsStore(filename=None)[source]

Bases: volttron.platform.keystore.BaseJSONStore

Handle storage and retrival of known hosts

add(addr, server_key)[source]
serverkey(addr)[source]

volttron.platform.main module

volttron.platform.packages module

volttron.platform.packaging module

volttron.platform.resmon module

Resource Monitor

The resource monitor manages resources assigned to the platform, assigns resources to agent execution environments, and monitors those resources for abuse.

There will typically be only a single resource monitor that is instantiated and then set using set_resource_monitor(). Other modules may then just import the module and call the module-level functions without worrying about where to find the monitor instance.

exception volttron.platform.resmon.ResourceError[source]

Bases: exceptions.Exception

Exception raised for errors relating to this module.

class volttron.platform.resmon.ExecutionEnvironment[source]

Bases: object

Environment reserved for agent execution.

Deleting ExecutionEnvironment objects should cause the process to end and all resources to be returned to the system.

execute(*args, **kwargs)[source]
class volttron.platform.resmon.ResourceMonitor(env, **kwargs)[source]

Bases: object

check_hard_resources(contract)[source]

Test contract against hard resources and return failed terms.

contract should be a dictionary of terms and conditions that are being requested. If all terms can be met, None is returned. Otherwise, a dictionary is returned with the terms that failed along with hints on values that would cause the terms to succeed, if any. The contract is tested against the platform’s hard capabilities and static resources.

get_static_resources(query_items=None)[source]

Return a dictionary of hard capabilities and static resources.

query_items is a list of resources the requester is interested in; only items in the list will appear in the returned dictionary. If query_items is not passed or is None, all items should be returned.

The returned dictionary contains the requested items that are available and their associated values and/or limits.

Examples of static resources:
architecture kernel version distribution (lsb_release) installed software
reserve_soft_resources(contract)[source]

Test contract against soft resources and reserve resources.

contract should be a dictionary of terms and conditions to test against the platform’s soft capabilities and dynamic resources.

A 2-tuple is returned: (reservation, failed_terms). If reservation is None, no resources were reserved and failed_terms is a dictionary that can be consulted for the terms that must be modified for a reservation to succeed. Otherwise, reservation will be a ExecutionEnvironment object that can later be used to execute an agent and failed_terms will be None.

volttron.platform.scheduling module

Schedule generators.

volttron.platform.scheduling.cron(cron_string, start=None, stop=None, second=0)[source]

Return a schedule generator from a cron-style string.

cron_string is a cron-style time expression consisting of five whitespace-separated fields explained in further detail below. start and stop are used to bound the schedule and can be None, datetime.datetime or datetime.timedelta objects or numeric values, such as is returned by time.time(). If start is None, the current time is used. If it is a timedelta, it will be added to the current time. If stop is None, cron will generate values infinitely. If it is a timedelta, the end time is the start time plus stop. Each iteration yields a datetime.datetime object. Since the smallest cron unit is a minute, second may be passed in to offset the time within the minute.

The following description of the cron fields is taken from the crontab(5) man page (with slight modifications).

The time and date fields are:

field allowed values —– ————– minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sunday, or use names)

A field may contain an asterisk (*), which always stands for “first-last”.

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The specified range is inclusive. For example, 8-11 for an ‘hours’ entry specifies execution at hours 8, 9, 10, and 11. If the range start or end value is left off, the first or last value will be used. For example, -8 for an ‘hours’ entry is equivalent to 0-8, 20- for a ‘days of month’ entry is equivalent to 20-31, and - for a ‘months’ entry is equivalent to 1-12.

Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples: “1,2,5,9”, “0-4,8-12”.

Step values can be used in conjunction with ranges. Following a range with “/<number>” specifies skips of the number’s value through the range. For example, “0-23/2” can be used in the ‘hours’ field to specify every other hour. Step values are also permitted after an asterisk, “*/2” in the ‘hours’ field is equivalent to “0-23/2”.

Names can also be used for the ‘month’ and ‘day of week’ fields. Use at least the first three letters of the particular day or month (case does not matter).

Note: The day can be specified in the following two fields: ‘day of month’, and ‘day of week’. If both fields are restricted (i.e., do not contain the “*” character), then both are used to compute date/time values. For example, “30 4 1,15 * 5” is interpreted as “4:30 am on the 1st and 15th of each month, plus every Friday.”

volttron.platform.scheduling.periodic(period, start=None, stop=None)[source]

Generate periodic datetime objects.

Yields datetime objects increasing by the given period, which can be of type int, long, float, or datetime.timedelta. start and stop are used to bound the schedule and can be None, datetime.datetime or datetime.timedelta objects or numeric values, such as is returned by time.time(). If start is None, the current time is used. If it is a timedelta, it will be added to the current time. If stop is None, cron will generate values infinitely. If it is a timedelta, the end time is the start time plus stop. Each iteration yields a datetime.datetime object.

volttron.platform.store module

volttron.platform.storeutils module

volttron.platform.storeutils.check_for_recursion(new_config_name, new_config, existing_configs)[source]

Returns a set of config files referenced in this configuration

volttron.platform.storeutils.strip_config_name(config_name)[source]

volttron.platform.vpm module