nso_jsonrpc_requester package
Submodules
nso_jsonrpc_requester.common module
Holds the common needs for the NSO-JSON RPC
- class nso_jsonrpc_requester.common.NsoJsonRpcCommon(protocol: str = 'http', ip: str = '127.0.0.1', port: str = '8080', username: str = 'admin', password: str = 'admin', ssl_verify: bool = True)[source]
Bases:
object
This class is used as a parent for other NSO JsonRPC API classes for common needs
- Parameters:
protocol (String) – (‘http’, ‘https’) Default: http
ip (String) – IPv4 Address or hostname Default: 127.0.0.1
port (String) – A protocol port Default: 8080
username (String) – The username to use Default: admin
password (String) – The password to use Default: admin
ssl_verify (Boolean) – Choice to verify SSL Cer Default: True
- Return type:
None
- Returns:
NA init
- Rasies TypeError:
If protocol is not (‘http’, ‘https’)
- abort(request_id)[source]
Method to send abort post
- Parameters:
request_id (Integer) – Request ID to abort
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if request_id is not an integer
- eval_xpath(xpath_expr)[source]
Method to send eval_xpath post
- Parameters:
xpath_expr (String) – The xpath to evaluate
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if xpath_expr is not an string
- get_system_setting(operation='version')[source]
Method to get get_system_setting information
- Parameters:
operation (String) – (‘capabilities’, ‘customizations’ ,’models’, ‘user’, ‘version’, ‘all’) Default: version
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
ValueError – if operation not (‘capabilities’, ‘customizations’ ,’models’, ‘user’, ‘version’, ‘all’)
- get_trans()[source]
Method to get the all current transaction information
- Return type:
Dict
- Returns:
A dictionary of data
- login(ack_warning=False)[source]
Method to send a login request, if the user is able to log in, the users cookie is set
- Parameters:
ack_warning (Boolean) – Default: False
- Return type:
Dict
- Returns:
A dictionary, also set’s self.cookies with a Cookies object
- Raises:
TypeError – if ack_warning is not boolean
- new_trans(mode='read', conf_mode='private', tag=None, on_pending_changes='reuse')[source]
Method to request a new transaction
- Parameters:
mode (String) – (‘read’, ‘read_write’) Default: read
conf_mode (String) – (‘private’, ‘shared’, ‘exclusive’) Default: private
tag (String) – Default: None it is optional
on_pending_changes (String) – (‘reuse’, ‘reject’, ‘discard’) Default: reuse
- Return type:
Dict
- Returns:
A dictionary, also set’s self.transaction_handle with a transaction handle self.transaction_mode with either (‘read’, ‘read_write’)
- Raises:
TypeError – if mode is not a string
ValueError – if mode is not (‘read’, ‘read_write’)
ValueError – if conf_mode not (‘private’, ‘shared’, ‘exclusive’)
ValueError – if on_pending_changes not (‘reuse’, ‘reject’, ‘discard’)
TypeError – if tag is supplied and is not a string
- post_with_cookies(json_data)[source]
Method to request a post with yummy cookies
- Parameters:
json_data (Dict) – Json Data in a dictionary
- Return type:
requests response object
- Returns:
A requests response
- static print_pretty_json(json_data)[source]
Method to print response JSON real pretty like
- Parameters:
json_data (Dict) – JSON Data in a dictionary
- Return type:
None
- Returns:
prints pretty JSON
nso_jsonrpc_requester.comet module
Holds the comet methods for the NSO-JSON RPC
- class nso_jsonrpc_requester.comet.NsoJsonRpcComet(protocol: str = 'http', ip: str = '127.0.0.1', port: str = '8080', username: str = 'admin', password: str = 'admin', ssl_verify: bool = True)[source]
Bases:
NsoJsonRpcCommon
This class is used for the NSO JsonRPC API for remote logging
- Parameters:
protocol (String) – (‘http’, ‘https’) Default: http
ip (String) – IPv4 Address or hostname Default: 127.0.0.1
port (String) – A protocol port Default: 8080
username (String) – The username to use Default: admin
password (String) – The password to use Default: admin
ssl_verify (Boolean) – Choice to verify SSL Cer Default: True
- Return type:
None
- Returns:
NA init
- Rasies TypeError:
If protocol is not (‘http’, ‘https’)
- get_subscriptions()[source]
Method to send a get_subscriptions post This get’s the sessions subscriptions
- Return type:
Dict
- Returns:
A dictionary of subscriptions
- subscribe_cdboper(path)[source]
Method to send a subscribe_cdboper post
- Parameters:
path (String) – The NSO KEYPATH to the data to watch for changes
- Return type:
Dict
- Returns:
A dictionary of data, also appends variables to self.comet_handles to the handle given by NSO
- Raises:
TypeError – if path is not a string
- subscribe_changes(path)[source]
Method to send a subscribe_changes post
- Parameters:
path (String) – The NSO KEYPATH to the data to watch for changes
- Return type:
Dict
- Returns:
A dictionary of data, also appends variables to self.comet_handles to the handle given by NSO
- Raises:
TypeError – if path is not a string
- subscribe_jsonrpc_batch()[source]
Method to send a subscribe_jsonrpc_batch post
- Return type:
Dict
- Returns:
A dictionary of data, also appends variables to self.comet_handles to the handle given by NSO
- subscribe_poll_leaf(path, interval)[source]
Method to send a subscribe_poll_leaf post
- Parameters:
path (String) – The NSO KEYPATH to the data to watch for changes
interval (Integer) – The interval of time for polling
- Return type:
Dict
- Returns:
A dictionary of data, also appends variables to self.comet_handles to the handle given by NSO
- Raises:
TypeError – if path is not a string
TypeError – if interval is not a integer
nso_jsonrpc_requester.config module
Holds the config methods for the NSO-JSON RPC
- class nso_jsonrpc_requester.config.NsoJsonRpcConfig(protocol: str = 'http', ip: str = '127.0.0.1', port: str = '8080', username: str = 'admin', password: str = 'admin', ssl_verify: bool = True)[source]
Bases:
NsoJsonRpcCommon
This class is used for the NSO JsonRPC API for configuration
- Parameters:
protocol (String) – (‘http’, ‘https’) Default: http
ip (String) – IPv4 Address or hostname Default: 127.0.0.1
port (String) – A protocol port Default: 8080
username (String) – The username to use Default: admin
password (String) – The password to use Default: admin
ssl_verify (Boolean) – Choice to verify SSL Cer Default: True
- Return type:
None
- Returns:
NA init
- Rasies TypeError:
If protocol is not (‘http’, ‘https’)
- commit(dry_run=True, output='cli', reverse=False)[source]
Method to send a commit post, in the CLI commits are validated automatically, in JsonRPC they are not, but only validated commits can be commited
- Parameters:
dry_run (Boolean) – To output a dry run, Default: is True
output (String) – (‘cli’, ‘native’, ‘xml’) Default: cli
reverse (Boolean) – Output the revers of the config going in, default is False, only valid when output equals native
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if dry_run is not boolean
KeyError – if output is not (‘cli’, ‘native’, ‘xml’)
TypeError – if reverse is not boolean
ValueError – if transaction_mode is not read_write
- create(path)[source]
Method to send a create post
- Parameters:
path (String) – The NSO KEYPATH to the data
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
ValueError – if transaction_mode is not read_write
- delete(path)[source]
Method to send a delete post
- Parameters:
path (String) – The NSO KEYPATH to the data
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
ValueError – if transaction_mode is not read_write
- deref(path, result_as='paths')[source]
Method to send a deref post
- Parameters:
path (String) – The NSO KEYPATH to the data
result_as (String) – (‘paths’, ‘target’, ‘list-target’) Default: paths
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
KeyError – if result_as is not (‘paths’, ‘target’, ‘list-target’)
- exists(path)[source]
Method to send a exists post
- Parameters:
path (String) – The NSO KEYPATH to the data
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
- get_case(path, choice)[source]
Method to send a get_case post
- Parameters:
path (String) – The NSO KEYPATH to the data
choice (String) – A choice from a case
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
TypeError – if choice is not a string
- get_leafref_values(path, skip_grouping=False, keys=None)[source]
Method to send a get_leafref_values post
- Parameters:
path (String) – The NSO KEYPATH to the data
skip_grouping (Boolean) – Default: False
keys (List) – A list of keys
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
TypeError – if skip_grouping is not boolean
TypeError – if keys is not a list
- get_list_keys(path)[source]
Method to send a get_list_keys post
- Parameters:
path (String) – The NSO KEYPATH to the data
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
- get_schema(path)[source]
Method to send a get_schema post
- Parameters:
path (String) – The NSO KEYPATH to the data
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
- get_service_points()[source]
Method to send a get_service_points post
- Return type:
Dict
- Returns:
A dictionary of data
- get_template_variables(name)[source]
Method to send a get_template_variables post, this retrieves device templates only
- Parameters:
name (String) – The name of the template
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if name is not a string
- get_value(path, check_default=False)[source]
Method to send a get_value post retrieves a single value
- Parameters:
path (String) – The NSO KEYPATH to the data
check_default (Boolean) – Default: False
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
TypeError – if check_default is not boolean
- get_values(path, leafs, check_default=False)[source]
Method to send a get_values post retrieves multiple leafs at once
- Parameters:
path (String) – The NSO KEYPATH to the data
leafs (List) – A list of leafs you want the data for, of type string
check_default (Boolean) – Default: False
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
TypeError – if leafs is not a list
TypeError – if check_default is not boolean
- load(data, path='/', data_format='xml', mode='merge')[source]
Method to send a load post
- Parameters:
data (String) – The data to be loaded in the transaction
path (String) – The NSO KEYPATH to the data Default: /
data_format (String) – (‘json’, ‘xml’) Default: xml
mode (String) – (‘create’, ‘merge’, ‘replace’) Default: merge
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if data is not a string
TypeError – if path is not a string
KeyError – if data_format is not (‘json’, ‘xml’)
KeyError – if mode is not (‘create’, ‘merge’, ‘replace’)
ValueError – if transaction_mode is not read_write
- query(xpath_expr, result_as='string')[source]
Method for a basic Query in NSO, This is a convenience method for calling start_query, run_query and stop_query This method should not be used for paginated results, as it results in performance degradation - use start_query, multiple run_query and stop_query instead.
- Parameters:
xpath_expr (String) – The XPATH expression to query
result_as (String) – One of these options {‘string’, ‘keypath-value’, ‘leaf_value_as_string’}, Default string
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if xpath_expr is not a string
ValueError – if result_as is not one of the following {‘string’, ‘keypath-value’, ‘leaf_value_as_string’}
- reset_query(qh)[source]
Method to reset the query
- Parameters:
qh (Integer) – The query handle to run
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if qh is not a integer
- run_action(path, input_data=None)[source]
Method to send a run_action post
- Parameters:
path (String) – The NSO KEYPATH to the data
input_data (Dict) – A Dictionary of inputs
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
TypeError – if input_data is not a dict
- run_query(qh)[source]
Method to run the query
- Parameters:
qh (Integer) – The query handle to run
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if qh is not a integer
- set_value(path, value, dry_run=False)[source]
Method to send a set_value post
- Parameters:
path (String) – The NSO KEYPATH to the data
value (User specified) – The value to set the item to
dry_run (Boolean) – Default: False, when set True tests if value is valid or not
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
TypeError – if dry_run is not boolean
ValueError – if transaction_mode is not read_write
- show_config(path, result_as='string', with_oper=False, max_size=0)[source]
Method to send a show_config post
- Parameters:
path (String) – The NSO KEYPATH to the data
result_as (String) – (‘string’, ‘json’) Defualt: string
with_oper (Boolean) – Default: False
max_size (Integer) – Default: 0, 0 = disable limit
- Return type:
Dict
- Returns:
A dictionary of data
- Raises:
TypeError – if path is not a string
KeyError – if result_as is not (‘string’, ‘json’)
TypeError – if with_oper is not boolean
TypeError – if max_size is not integer
- start_query(xpath_expr=None, path=None, selection=None, chunk_size=None, initial_offset=None, sort=None, sort_order=None, include_total=True, context_node=None, result_as='string')[source]
Method to start a complex query
- Parameters:
xpath_expr (String) – The XPATH expression to query is chosen above path if both are given
path (String) – The KEYPATH expression to query
selection (List) – The fields to select, Optional
chunk_size (Integer) – Must be greater than 0, Optional
initial_offset (Integer) – Not sure on this yet, Optional
sort (List) – A list of XPATH expressions, Optional
sort_order (String) – One of the following {“ascending”, “descending”}, Optional
include_total (Boolean) – Include the total of records, Default: True
context_node (String) – A KEYPATH, Optional
result_as (String) – One of these options {‘string’, ‘keypath-value’, ‘leaf_value_as_string’}, Default string
- Return type:
Dict
- Returns:
A dictionary of data with one key ‘qh’ which is the Query Handle to be used with run_query etc.
- Raises:
ValueError – if both xpath_expr, and path are not given
TypeError – if xpath_expr is not a string
TypeError – if path is not a string
TypeError – if selection is not a list
TypeError – if chunk_size is not a integer greater than 0
TypeError – if initial_offset is not a integer
TypeError – if sort is not a list
ValueError – if sort_order, is not one of the following {“ascending”, “descending”}
TypeError – if include_total is not a boolean
TypeError – if context_node is not a string
ValueError – if result_as is not one of the following {‘string’, ‘keypath-value’, ‘leaf_value_as_string’}
Module contents
This exports the main Classes to use NSO JSON-RPC