PyNSO API - Client

class pynso.client.NSOClient(host: str, username: str, password: str, port: int = 8080, ssl: bool = False, verify_ssl: bool = True, root: str = 'restconf')

The main client class for the NSO APIs.

apply_rollback(id: int, selective: bool = False, path: Optional[str] = None) → None

Apply a system rollback.

After applying a rollback this latest change gets id 0 which means that all other ids also change.

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

apply_rollback_by_fixed_number(fixed_number: int, selective: bool = False, path: Optional[str] = None) → None

Apply a system rollback by fixed number.

After applying a rollback the fixed number is still the same.

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

call_operation(data_path: Iterable[str], data: Any, *, params: Optional[Dict[str, Union[str, int, bool]]] = None) → Optional[Any]

Call (POST) an operation to a datastore.

Parameters

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

create_data_value(data_path: Iterable[str], data: Any, *, datastore: Optional[pynso.datastores.DatastoreType] = None, params: Optional[Dict[str, Union[str, int, bool]]] = None) → None

Create (POST) a data entry in a datastore.

Parameters

Raises requests.HTTPError on failures.

delete_path(data_path: Iterable[str], *, datastore: Optional[pynso.datastores.DatastoreType] = None, params: Optional[Dict[str, Union[str, int, bool]]] = None) → None

Delete a data entry in a datastore.

Parameters

Raises requests.HTTPError on failures.

exists(data_path: Iterable[str], *, datastore: Optional[pynso.datastores.DatastoreType] = None, params: Optional[Dict[str, Union[str, int, bool]]] = None) → bool

Check if a data entry in a datastore exists.

Parameters

Raises requests.HTTPError on failures.

get_data(data_path: Iterable[str], *, datastore: Optional[pynso.datastores.DatastoreType] = None, params: Optional[Dict[str, Union[str, int, bool]]] = None) → Any

Get a data entry in a datastore.

Parameters

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

get_datastore(datastore_name: str, *, params: Optional[Dict[str, Union[str, int, bool]]] = None) → Any

Get the details of a datastore.

Parameters
  • datastore_name – The target datastore name

  • params – Extra query parameters, see Params

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

get_rollback(id: int) → str

Get the contents of stored rollbacks.

This returns the configuration diff as it was applied in the change by id.

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

get_rollback_by_fixed_number(fixed_number: int) → str

Get the contents of stored rollbacks by fixed number.

This returns the configuration diff as it was applied in the change by fixed-number.

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

get_rollbacks() → Any

Get a list of stored rollbacks.

Rollbacks have an id which start at the most recent change and a fixed number which starts at the oldest change.

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

info() → Any

Return API information.

This call returns the loaded yang modules.

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

query(data: Any) → Any

Call the nso query api.

The API consists of the following Requests:

  • start-query: Start a query and return a query handle.

  • fetch-query-result: Use a query handle to repeatedly fetch chunks of the result.

  • immediate-query: Start a query and return the entire result immediately.

  • reset-query: (Re)set where the next fetched result will begin from.

  • stop-query: Stop (and close) the query.

The API consists of the following Replies:

  • start-query-result: Reply to the start-query request

  • query-result: Reply to the fetch-query-result and immediate-query requests

Example:

Example payload:

{
    "start-query": {
        "foreach": "/x/host[enabled = 'true']",
        "select": [
            {
                "label": "Host name",
                "expression": "name",
                "result-type": ["string"]
            },
            {
                "expression": "address",
                "result-type": ["string"]
            }
        ],
        "sort-by": ["name"],
        "limit": 100,
        "offset": 1
    }
}

Raises requests.HTTPError on request failures or json.JSONDecodeError on invalid json.

set_data_value(data_path: Iterable[str], data: Any, *, datastore: Optional[pynso.datastores.DatastoreType] = None, params: Optional[Dict[str, Union[str, int, bool]]] = None) → None

Update (PUT) a complete data entry in a datastore.

Parameters

Raises requests.HTTPError on failures.

update_data_value(data_path: Iterable[str], data: Any, *, datastore: Optional[pynso.datastores.DatastoreType] = None, params: Optional[Dict[str, Union[str, int, bool]]] = None) → None

Partial update (PATCH) elements of a data entry in a datastore by only providing the changed items.

Parameters

Raises requests.HTTPError on failures.

Enumerations

class pynso.datastores.DatastoreType

An enum of the resource types in the API.

By default all calls to NSO operate on the unified data store. If you want only operational or config data one can use NONCONFIG or CONFIG respectively.

CONFIG = 'config'

Only work on the config datastore.

This corrensponds with using the content=config query parameter

NONCONFIG = 'nonconfig'

Only work on the operational datastore.

This corrensponds with using the content=config query parameter

UNIFIED = 'all'

Work on both datastores

This corrensponds with using the default content=all query parameter or no content query parameter

Types

pynso.types.Params = typing.Dict[str, typing.Union[str, int, bool]]

Dictionary of query string parametes.

See NSO documentation for meaning of possible parameters:

  • commit-queue

  • commit-queue-atomic

  • commit-queue-block-others

  • commit-queue-lock

  • commit-queue-tag

  • commit-queue-timeout

  • commit-queue-error-option

  • depth

  • dry-run

  • dry-run-reverse

  • insert

  • no-networking

  • no-out-of-sync-check

  • no-overwrite

  • no-revision-drop

  • no-deploy

  • no-lsa

  • point

  • rollback-comment

  • rollback-label

  • fields

  • unhide

  • use-lsa

  • with-defaults