libsolace.SolaceAPI module

class libsolace.SolaceAPI.SolaceAPI(environment, version=None, detect_status=True, testmode=False, **kwargs)[source]

Connects to a Solace cluster’s primary and backup appliance(s)

a SolaceAPI instance contains a SolaceXMLBuilder and a SolaceCommandQueue in order to facilitate the generation of SEMP XML requests, enqueuing the XML requests, and sending them to the appliance(s) through the rpc(str) method.

SolaceAPI connects to both appliances in a redundant pair setup and gets the the primary and backup node states. Typically you issue the same SEMP command to both appliances. Commands can also be issued to either the primary or the backup appliance utilizing the primaryOnly and backupOnly kwargs. see: rpc()

The version of the SolOS-TR OS is detected on automatically, and this behaviour can be overridden with the version kwarg. If using the VMR you will want to pass in both detect_status=False and version=”soltr/7_1_1”.

Parameters:
  • environment (str) – the environemnt
  • detect_status (bool) – detection of node primary/backup status, pass True here for the VMR or single appliances.
  • version (str) – override appliance version detection. Some versions of SolOS-TR require you to set the language level a bit higher like the VMR for example.
  • testmode (bool) – Tells the api to connect using the READ_ONLY_USER as defined in the libsolace.yaml file.
Return type:

SolaceAPI.SolaceAPI

Returns:

instance

Examples:
>>> from libsolace.SolaceXMLBuilder import SolaceXMLBuilder
>>> api = SolaceAPI("dev")
>>> api.x = SolaceXMLBuilder("LOG: Showing the Message Spool in %s" % api.environment, version=api.version)
>>> api.x.show.message_spool.detail
OrderedDict()
>>> response = api.rpc(api.x)

Setting the API version if detection fails

>>> from libsolace.SolaceXMLBuilder import SolaceXMLBuilder
>>> api = SolaceAPI("dev", version="soltr/7_1_1")
>>> api.x = SolaceXMLBuilder("My description of what im doing", version=api.version)
>>> api.x.show.message_spool
OrderedDict()
>>> response = api.rpc(api.x, primaryOnly=True)
>>> response[0]['rpc-reply']['rpc']['show']['message-spool']['message-spool-info']['config-status']
u'Enabled (Primary)'

Query the backup appliance only

>>> from libsolace.SolaceXMLBuilder import SolaceXMLBuilder
>>> api = SolaceAPI("dev", detect_status=False)
>>> api.x = SolaceXMLBuilder("My Something something", version=api.version)
>>> api.x.show.version
OrderedDict()
>>> r = api.rpc(api.x, backupOnly=True)
>>> # check the response was the "configured" backup
>>> r[0]['HOST'] == settings.SOLACE_CONF["dev"]['MGMT'][1]
True

Get a instance of some plugin from the plugin manager

>>> api = SolaceAPI("dev")
>>> type(api.manage("NullPlugin"))
<class 'libsolace.items.NullPlugin.NullPlugin'>
get_memory()[source]

Returns the Memory Usage

Example of request XML <rpc semp-version=”soltr/6_0”>

<show>
<memory></memory>

</show>

</rpc>

get_message_spool(**kwargs)[source]

show message spool :param version:

get_redundancy()[source]

Return redundancy status

Example:
>>> api = SolaceAPI("dev")
>>> api.get_redundancy()[0]['rpc-reply']['rpc']['show']['redundancy']['config-status']
u'Enabled'
manage(plugin_name, **kwargs)[source]

Gets a plugin, configures it, then allows direct communication with it.

Plugins are passed the kwargs directly if any are specified.

Example:
>>> api = SolaceAPI("dev")
>>> p1 = api.manage("NullPlugin")
>>> p1.some_method("foo", bar="baz")
(('foo',), {'bar': 'baz'})
>>> p2 = api.manage("NullPlugin", a="a")
>>> p2.kwargs['a']
'a'
rpc(xml, allowfail=False, primaryOnly=False, backupOnly=False, xml_response=False, **kwargs)[source]

Execute a SEMP command on the appliance(s), call with a string representation of a SolaceXMLBuilder instance.

Args:

xml(str): string representation of a SolaceXMLBuilder instance. allowFail(Optional(bool)): tollerate some types of errors from the

appliance.

primaryOnly(Optional(bool)): only execute on primary appliance. backupOnly(Optional(bool)): only execute on backup appliance.

Returns:
data response list as from appliances. Json-like data
Example:
>>> from libsolace.SolaceXMLBuilder import SolaceXMLBuilder
>>> conn = SolaceAPI("dev")
>>> conn.x = SolaceXMLBuilder(version = conn.version)
>>> conn.x.show.version
OrderedDict()
>>> type(conn.rpc(str(conn.x)))
<type 'list'>