For the complete documentation index, see llms.txt. This page is also available as Markdown.

ncs.maapi Module

MAAPI high level module.

This module defines a high level interface to the low-level maapi functions.

The 'Maapi' class encapsulates a MAAPI connection which upon constructing, sets up a connection towards ConfD/NCS. An example of setting up a transaction and manipulating data:

import ncs

m = ncs.maapi.Maapi()
m.start_user_session('admin', 'test_context')
t = m.start_write_trans()
t.get_elem('/model/data{one}/str')
t.set_elem('testing', '/model/data{one}/str')
t.apply()

Another way is to use context managers, which will handle all cleanup related to transactions, user sessions and socket connections:

with ncs.maapi.Maapi() as m:
    with ncs.maapi.Session(m, 'admin', 'test_context'):
        with m.start_write_trans() as t:
            t.get_elem('/model/data{one}/str')
            t.set_elem('testing', '/model/data{one}/str')
            t.apply()

Finally, a really compact way of doing this:

with ncs.maapi.single_write_trans('admin', 'test_context') as t:
    t.get_elem('/model/data{one}/str')
    t.set_elem('testing', '/model/data{one}/str')
    t.apply()

Functions

connect

Convenience function for connecting to ConfD/NCS.

If 'port' is provided the connection uses TCP (with 'ip' defaulting to the value of NCS_IPC_ADDR / '127.0.0.1'). Otherwise, if 'path' is provided, Local IPC is used.

Arguments:

  • ip -- ConfD/NCS instance ip address (str)

  • port -- ConfD/NCS instance port (int)

  • path -- ConfD/NCS instance socket path (str)

Returns:

  • socket (Python socket)

retry_on_conflict

Function/method decorator to retry a transaction in case of conflicts.

When executing multiple concurrent transactions against the NCS RUNNING datastore, read-write conflicts are resolved by rejecting transactions having potentially stale data with ERR_TRANSACTION_CONFLICT.

This decorator restarts a function, should it run into a conflict, giving it multiple attempts to apply. The decorated function must start its own transaction because a conflicting transaction must be thrown away entirely and a new one started.

Example usage:

Arguments:

  • retries -- number of times to retry (int)

  • log -- optional log object for logging conflict details

single_read_trans

Context manager for a single READ transaction.

This function connects to ConfD/NCS, starts a user session and finally starts a new READ transaction.

Function signature:

For argument db, flags see Maapi.start_trans(). For arguments user, context, groups, src_ip, src_port, proto, vendor, product, version and client_id see Maapi.start_user_session(). For arguments ip, port and path see connect(). For argument load_schemas see init().

Arguments:

  • user - username (str)

  • context - context for the session (str)

  • groups - groups (list)

  • db -- database (int)

  • ip -- ConfD/NCS instance ip address (str)

  • port -- ConfD/NCS instance port (int)

  • path -- ConfD/NCS instance location path (str)

  • src_ip - source ip address (str)

  • src_port - source port (int)

  • proto - protocol used by for connecting (i.e. ncs.PROTO_TCP)

  • vendor -- lock error information (str, optional)

  • product -- lock error information (str, optional)

  • version -- lock error information (str, optional)

  • client_id -- lock error information (str, optional)

  • load_schemas - passed on to Maapi.init()

  • flags -- additional transaction flags (int)

Returns:

  • read transaction object (maapi.Transaction)

single_write_trans

Context manager for a single READ/WRITE transaction.

This function connects to ConfD/NCS, starts a user session and finally starts a new READ/WRITE transaction.

Function signature:

For argument db, flags see Maapi.start_trans(). For arguments user, context, groups, src_ip, src_port, proto, vendor, product, version and client_id see Maapi.start_user_session(). For arguments ip, port and path see connect(). For argument load_schemas see init().

Arguments:

  • user - username (str)

  • context - context for the session (str)

  • groups - groups (list)

  • db -- database (int)

  • ip -- ConfD/NCS instance ip address (str)

  • port -- ConfD/NCS instance port (int)

  • path -- ConfD/NCS instance location path (str)

  • src_ip - source ip address (str)

  • src_port - source port (int)

  • proto - protocol used by the client for connecting (int)

  • vendor -- lock error information (str, optional)

  • product -- lock error information (str, optional)

  • version -- lock error information (str, optional)

  • client_id -- lock error information (str, optional)

  • load_schemas - passed on to Maapi.init()

  • flags -- additional transaction flags (int)

Returns:

  • write transaction object (maapi.Transaction)

Classes

class CommitParams

Class representing NSO commit parameters.

Start with creating an empty instance of this class and set commit parameters using helper methods.

Members:

comment(...)

Method:

Set comment.

commit_queue_async(...)

Method:

Set commit queue asynchronous mode of operation.

commit_queue_atomic(...)

Method:

Make the commit queue item atomic.

commit_queue_block_others(...)

Method:

Make the commit queue item block other commit queue items for this device.

commit_queue_bypass(...)

Method:

Make the commit transactional even if commit queue is configured by default.

commit_queue_error_option(...)

Method:

Set commit queue item behaviour on error.

commit_queue_lock(...)

Method:

Make the commit queue item locked.

commit_queue_non_atomic(...)

Method:

Make the commit queue item non-atomic.

commit_queue_sync(...)

Method:

Set commit queue synchronous mode of operation.

confirm_network_state(...)

Method:

Check that the parts of the device configuration read and/or modified are up-to-date in CDB before pushing the configuration change to the device.

confirm_network_state_mode(...)

Method:

Set the mode for confirm-network-state.

confirm_network_state_re_deploy_all(...)

Method:

Re-deploy all services affected by discovered out-of-band data

confirm_network_state_re_evaluate_policies(...)

Method:

Check that the parts of the device configuration read and/or modified are up-to-date in CDB before pushing the configuration change to the device and re-evaluate policies of effected services.

This function is deprecated and will be removed in a future release. Use confirm_network_state_mode() instead.

confirm_network_state_scope(...)

Method:

Set the scope for confirm-network-state.

dry_run_cli(...)

Method:

Dry-run commit outformat CLI.

dry_run_cli_c(...)

Method:

Dry-run commit outformat cli-c.

dry_run_cli_c_reverse(...)

Method:

Dry-run commit outformat cli-c reverse.

dry_run_native(...)

Method:

Dry-run commit outformat native.

dry_run_native_reverse(...)

Method:

Dry-run commit outformat native reverse.

dry_run_xml(...)

Method:

Dry-run commit outformat XML.

get_comment(...)

Method:

Get comment.

get_commit_queue_error_option(...)

Method:

Get commit queue item behaviour on error.

get_commit_queue_sync_timeout(...)

Method:

Get commit queue synchronous mode of operation timeout.

get_confirm_network_state_mode(...)

Method:

Get the mode for confirm-network-state.

get_confirm_network_state_scope(...)

Method:

Get the scope for confirm-network-state.

get_dry_run_outformat(...)

Method:

Get dry-run outformat

get_label(...)

Method:

Get label.

get_no_overwrite_scope(...)

Method:

Get no-overwrite scope

get_tagvalues(...)

Method:

Get commit parameters as a list of TagValue's.

get_trace_id(...)

Method:

Get trace id.

is_commit_queue_async(...)

Method:

Get commit queue asynchronous mode of operation.

is_commit_queue_atomic(...)

Method:

Check if the commit queue item should be atomic.

is_commit_queue_block_others(...)

Method:

Check if the the commit queue item should block other commit queue items for this device.

is_commit_queue_bypass(...)

Method:

Check if the commit is transactional even if commit queue is configured by default.

is_commit_queue_lock(...)

Method:

Check if the commit queue item should be locked.

is_commit_queue_non_atomic(...)

Method:

Check if the commit queue item should be non-atomic.

is_commit_queue_sync(...)

Method:

Get commit queue synchronous mode of operation.

is_confirm_network_state(...)

Method:

Should a check be done that the parts of the device configuration read and/or modified are up-to-date in CDB before pushing the configuration change to the device.

is_confirm_network_state_re_deploy_all(...)

Method:

Is confirm-network-state with re-deploy-all enabled.

is_confirm_network_state_re_evaluate_policies(...)

Method:

Is confirm-network-state with re-evaluate-policies enabled.

This function is deprecated and will be removed in a future release. Use get_confirm_network_state_mode() instead.

is_dry_run(...)

Method:

Is dry-run enabled

is_dry_run_reverse(...)

Method:

Is dry-run reverse enabled.

is_no_deploy(...)

Method:

Should service create method be invoked or not.

is_no_lsa(...)

Method:

Get no-lsa commit parameter.

is_no_networking(...)

Method:

Check if the the configuration should only be written to CDB and not actually pushed to the device.

is_no_out_of_sync_check(...)

Method:

Do not check device sync state before pushing the configuration change.

is_no_overwrite(...)

Method:

Should a check be done that the parts of the device configuration to be modified are up-to-date in CDB before pushing the configuration change to the device.

is_no_revision_drop(...)

Method:

Get no-revision-drop commit parameter.

is_reconcile_attach_non_service_config(...)

Method:

Get reconcile commit parameter with attach-non-service-config behaviour.

is_reconcile_detach_non_service_config(...)

Method:

Get reconcile commit parameter with detach-non-service-config behaviour.

is_reconcile_discard_non_service_config(...)

Method:

Get reconcile commit parameter with discard-non-service-config behaviour.

is_reconcile_keep_non_service_config(...)

Method:

Get reconcile commit parameter with keep-non-service-config behaviour.

is_use_lsa(...)

Method:

Get use-lsa commit parameter.

is_with_service_meta_data(...)

Method:

Get with-service-meta-data commit parameter.

label(...)

Method:

Set label.

no_deploy(...)

Method:

Do not invoke service's create method.

no_lsa(...)

Method:

Set no-lsa commit parameter.

no_networking(...)

Method:

Only write the configuration to CDB, do not actually push it to the device.

no_out_of_sync_check(...)

Method:

Do not check device sync state before pushing the configuration change.

no_overwrite(...)

Method:

Check that the parts of the device configuration to be modified are up-to-date in CDB before pushing the configuration change to the device.

no_revision_drop(...)

Method:

Set no-revision-drop commit parameter.

reconcile_attach_non_service_config(...)

Method:

Set reconcile commit parameter with attach-non-service-config behaviour.

reconcile_detach_non_service_config(...)

Method:

Set reconcile commit parameter with detach-non-service-config behaviour.

reconcile_discard_non_service_config(...)

Method:

Set reconcile commit parameter with discard-non-service-config behaviour.

reconcile_keep_non_service_config(...)

Method:

Set reconcile commit parameter with keep-non-service-config behaviour.

set_dry_run_outformat(...)

Method:

Set dry-run outformat

set_reconcile_exclude_paths(...)

Method:

Set paths to be excluded during reconciliation.

set_reconcile_include_paths(...)

Method:

Set paths to be included during reconciliation.

trace_id(...)

Method:

Set trace id.

use_lsa(...)

Method:

Set use-lsa commit parameter.

with_service_meta_data(...)

Method:

Set with-service-meta-data commit parameter.

class ConfirmNetworkStateMode

Enumeration for confirm network state modes: NORMAL = 1 RE_EVALUATE_POLICIES = 2

Members:

NORMAL
RE_EVALUATE_POLICIES
name

The name of the Enum member.

value

The value of the Enum member.

class ConfirmNetworkStateScope

Enumeration for confirm network state scopes: WRITE_AND_FULL_READ_SET = 1 WRITE_AND_SERVICE_READ_SET = 2

Members:

WRITE_AND_FULL_READ_SET
WRITE_AND_SERVICE_READ_SET
name

The name of the Enum member.

value

The value of the Enum member.

class DryRunOutformat

Enumeration for dry run formats: XML = 1 CLI = 2 NATIVE = 3 CLI_C = 4

Members:

CLI
CLI_C
NATIVE
XML
name

The name of the Enum member.

value

The value of the Enum member.

class Key

Key string encapsulation and helper.

Initialize a key.

'key' may be a string or a list of strings.

Members:

None

class Maapi

Class encapsulating a MAAPI connection.

Create a Maapi instance.

Arguments:

  • ip -- ConfD/NCS instance ip address (str, optional)

  • port -- ConfD/NCS instance port (int, optional)

  • path -- ConfD/NCS instance location path (str, optional)

  • msock -- already connected MAAPI socket (socket.socket, optional) (ip, port and path ignored)

  • load_schemas -- whether schemas should be loaded/reloaded or not LOAD_SCHEMAS_LOAD = load schemas unless already loaded LOAD_SCHEMAS_SKIP = do not load schemas LOAD_SCHEMAS_RELOAD = force reload of schemas

The option LOAD_SCHEMAS_RELOAD can be used to force a reload of schemas, for example when connecting to a different ConfD/NSO node. Note that previously constructed maagic objects will be invalid and using them will lead to undefined behavior. Use this option with care, for example in a small script querying a list of running nodes.

Members:

apply_template(...)

Method:

Apply a template.

attach(...)

Method:

Attach to an existing transaction.

'ctx_or_th' may be either a TransCtxRef or a transaction handle. The 'hashed_ns' argument is basically just there to save a call to set_namespace(). 'usid' is only used if 'ctx_or_th' is a transaction handle and if set to 0 the user session id that is the owner of the transaction will be used.

Arguments:

  • ctx_or_th (TransCtxRef or transaction handle)

  • hashed_ns (int)

  • usid (int)

Returns:

  • transaction object (maapi.Transaction)

attach_init(...)

Method:

Attach to phase0 for CDB initialization and upgrade.

authenticate(...)

Method:

Authenticate a user using the AAA configuration.

Use src_addr, src_port, context and prot to use an external authentication executable. Use the 'n' to get a list of n-1 groups that the user is a member of. Use n=1 if the function is used in a context where the group names are not needed.

Returns 1 if accepted without groups. If the authentication failed or was accepted a tuple with first element status code, 0 for rejection and 1 for accepted is returned. The second element either contains the reason for the rejection as a string OR a list groupnames.

Arguments:

  • user - username (str)

  • password - passwor d (str)

  • n - number of groups to return (int)

  • src_addr - source ip address (str)

  • src_port - source port (int)

  • context - context for the session (str)

  • prot - protocol used by the client for connecting (int)

Returns:

  • status (int or tuple)

clear_read_intent(...)

Method:

Clear the read intent for the transaction.

This function clears the read intent for the given XPath in the transaction, which can be used for optimization purposes by the ConfD/NCS system.

Arguments:

  • th -- transaction handle

close(...)

Method:

Ends session and closes socket.

cursor(...)

Method:

Get an iterable list cursor.

destroy_cursor(...)

Method:

Destroy cursor.

Arguments:

  • cursor (maapi.Cursor)

detach(...)

Method:

Detach the underlying MAAPI socket.

Arguments:

  • ctx_or_th (TransCtxRef or transaction handle)

do_display(...)

Method:

Do display.

If the data model uses the YANG when or tailf:display-when statement, this function can be used to determine if the item given by the path should be displayed or not.

Arguments:

  • th -- transaction handle

  • path -- path to the 'display-when' statement (str)

Returns

  • boolean

end_progress_span(...)

Method:

Don't call this function.

Call instance.end() on the progress.Span instance created from start_progress_span() instead.

exists(...)

Method:

Check if path exists.

Arguments:

  • th -- transaction handle

  • path -- path to the node in the data tree (str)

Returns:

  • boolean

find_next(...)

Method:

Find next.

Update the cursor 'mc' with the key(s) for the list entry designated by the 'type' and 'inkeys' arguments. This function may be used to start a traversal from an arbitrary entry in a list. Keys for subsequent entries may be retrieved with the get_next() function. When no more keys are found, False is returned.

The strategy to use is defined by 'type':

get_next(...)

Method:

Iterate and get the keys for the next entry in a list.

When no more keys are found, False is returned

Arguments:

  • cursor (maapi.Cursor)

Returns:

  • keys (list or boolean)

get_objects(...)

Method:

Get objects.

Read at most n values from each nobj lists starting at cursor mc. Returns a list of Value's.

Arguments:

  • mc (maapi.Cursor)

  • n -- at most n values will be read (int)

  • nobj -- number of nobj lists which n elements will be taken from (int)

Returns:

  • list of values (list)

get_read_intent(...)

Method:

Get the read intent for the transaction.

This function gets the read intents for the transaction, which can be used for optimization purposes by the ConfD/NCS system.

Arguments:

  • th -- transaction handle

Returns:

  • list of path read intent (list)

get_running_db_status(...)

Method:

Get running db status.

Gets the status of the running db. Returns True if consistent and False otherwise.

Returns:

  • boolean

get_template_variables(...)

Method:

Get template variables for specific types.

get_trans_mode(...)

Method:

Get transaction mode for a transaction handle.

Arguments:

  • th -- a transaction handle.

Returns:

  • Either READ or READ_WRITE flag (ncs) or -1 (no transaction).

ip

Readonly property

Return address to connect to the IPC port

load_schemas(...)

Method:

Load the schemas to Python (using shared memory if enabled).

If 'use_maapi_socket' is set to True, the schmeas are loaded through the NSO daemon via a MAAPI socket.

netconf_ssh_call_home(...)

Method:

Initiate NETCONF SSH Call Home.

netconf_ssh_call_home_opaque(...)

Method:

Initiate NETCONF SSH Call Home w. opaque data.

path

Readonly property

Return path to connect to the IPC port

port

Readonly property

Return port to connect to the IPC port

progress_info(...)

Method:

While spans represents a pair of data points: start and stop; info events are instead singular events, one point in time. Call progress_info() to write a progress span info event to the progress trace. The info event will have the same span-id as the start and stop events of the currently ongoing progress span in the active user session or transaction. See help for start_progress_span() for more information.

Arguments:

  • msg - message to report (str)

  • verbosity - ncs.VERBOSITY_*, VERBOSITY_NORMAL is default (optional)

  • attrs - user defined attributes (optional)

  • links - list of ncs.progress.Span or dict (optional)

  • path - keypath to an action/leaf/service/etc (str, optional)

query_free_result(...)

Method:

Deallocate QueryResult memory.

Deallocated memory inside the QueryResult object 'qrs' returned from query_result(). It is not necessary to call this method as deallocation will be done when the Python library garbage collects the QueryResult object.

Arguments:

  • qrs -- the query result structure to free

report_progress(...)

Method:

Report transaction/action progress.

The 'package' argument is only available to NCS.

This function is deprecated and will be removed in a future release. Use progress_info() instead.

report_progress_start(...)

Method:

Report transaction/action progress.

Used for calculation of the duration between two events. The method returns a _Progress object to be passed to report_progress_stop() once the event has finished.

The 'package' argument is only available to NCS.

This function is deprecated and will be removed in a future release. Use start_progress_span() instead.

report_progress_stop(...)

Method:

Report transaction/action progress.

Used for calculation of the duration between two events. The method takes a _Progress object returned from report_progress_start().

This function is deprecated and will be removed in a future release. Use end_progress_span() instead.

report_service_progress(...)

Method:

Report transaction progress for a FASTMAP service.

This function is deprecated and will be removed in a future release. Use progress_info() instead.

report_service_progress_start(...)

Method:

Report transaction progress for a FASTMAP service.

Used for calculation of the duration between two events. The method returns a _Progress object to be passed to report_service_progress_stop() once the event has finished.

This function is deprecated and will be removed in a future release. Use start_progress_span() instead.

report_service_progress_stop(...)

Method:

Report transaction progress for a FASTMAP service.

Used for calculation of the duration between two events. The method takes a _Progress object returned from report_service_progress_start().

This function is deprecated and will be removed in a future release. Use end_progress_span() instead.

run_with_retry(...)

Method:

Run fun with a new read-write transaction against RUNNING.

The transaction is applied if fun returns True. The fun is only retried in case of transaction conflicts. Each retry is run using a new transaction.

The last conflict error.Error is thrown in case of max number of retries is reached.

Arguments:

  • fun - work fun (fun(maapi.Transaction) -> bool)

  • usid - user id (int)

  • max_num_retries - maximum number of retries (int)

Returns:

  • bool True if transation was applied, else False.

safe_create(...)

Method:

Safe version of create.

Create a new list entry, a presence container, or a leaf of type empty in the data tree - if it doesn't already exist.

Arguments:

  • th -- transaction handle

  • path -- path to the new element (str)

safe_delete(...)

Method:

Safe version of delete.

Delete an existing list entry, a presence container, or an optional leaf and all its children (if any) from the data tree. If it exists.

Arguments:

  • th -- transaction handle

  • path -- path to the element (str)

safe_get_elem(...)

Method:

Safe version of get_elem.

Read the element at 'path', returns 'None' if it doesn't exist.

Arguments:

  • th -- transaction handle

  • path -- path to the element (str)

Returns:

  • configuration element

safe_get_object(...)

Method:

Safe version of get_object.

This function reads at most 'n' values from the list entry or container specified by the 'path'. Returns 'None' the path is empty.

Arguments:

  • th -- transaction handle

  • n -- at most n values (int)

  • path -- path to the object (str)

Returns:

  • configuration object

set_elem(...)

Method:

Set the node at 'path' to 'value'.

If 'value' is not of type Value it will be converted to a string before calling set_elem2() under the hood.

Arguments:

  • th -- transaction handle

  • value -- element value (Value or str)

  • path -- path to the element (str)

set_read_intent(...)

Method:

Set a read intent for the transaction.

This function sets a read intent for the given XPath in the transaction, which can be used for optimization purposes by the ConfD/NCS system.

Arguments:

  • th -- transaction handle

  • xpath_or_xpaths -- A single XPath or a list of xpaths (str or list)

shared_apply_template(...)

Method:

FASTMAP version of apply_template().

shared_copy_tree(...)

Method:

FASTMAP version of copy_tree().

shared_create(...)

Method:

FASTMAP version of create().

shared_insert(...)

Method:

FASTMAP version of insert().

shared_set_elem(...)

Method:

FASTMAP version of set_elem().

If 'value' is not of type Value it will be converted to a string before calling shared_set_elem2() under the hood.

shared_set_values(...)

Method:

FASTMAP version of set_values().

start_progress_span(...)

Method:

Starts a progress span. Progress spans are trace messages written to the progress trace and the developer log. A progress span consists of a start and a stop event which can be used to calculate the duration between the two. Those events can be identified with unique span-ids. Inside the span it is possible to start new spans, which will then become child spans, the parent-span-id is set to the previous spans' span-id. A child span can be used to calculate the duration of a sub task, and is started from consecutive maapi_start_progress_span() calls, and is ended with maapi_end_progress_span().

The concepts of traces, trace-id and spans are highly influenced by https://opentelemetry.io/docs/concepts/signals/traces/#spans

Call help(ncs.progress) or help(confd.progress) for examples.

Arguments:

  • msg - message to report (str)

  • verbosity - ncs.VERBOSITY_*, VERBOSITY_NORMAL is default (optional)

  • attrs - user defined attributes (optional)

  • links - list of ncs.progress.Span or dict (optional)

  • path - keypath to an action/leaf/service/etc (str, optional)

Returns:

  • trace span (ncs.progress.Span)

start_read_trans(...)

Method:

Start a read transaction.

For details see start_trans().

start_trans(...)

Method:

Start a transaction towards the 'db'.

This function starts a new a new transaction towards the given data store.

Arguments:

  • rw -- Either READ or READ_WRITE flag (ncs)

  • db -- Either CANDIDATE, RUNNING or STARTUP flag (cdb)

  • usid -- user id (int)

  • flags -- additional transaction flags (int)

  • vendor -- lock error information (str, optional)

  • product -- lock error information (str, optional)

  • version -- lock error information (str, optional)

  • client_id -- lock error information (str, optional)

Returns:

  • transaction (maapi.Transaction)

Flags (maapi):

  • FLAG_HINT_BULK

  • FLAG_NO_DEFAULTS

  • FLAG_CONFIG_ONLY

  • FLAG_HIDE_INACTIVE

  • FLAG_DELAYED_WHEN

  • FLAG_NO_CONFIG_CACHE

  • FLAG_CONFIG_CACHE_ONLY

  • FLAG_HIDE_ALL_HIDEGROUPS

  • FLAG_SKIP_SUBSCRIBERS

start_trans_in_trans(...)

Method:

Start a new transaction within a transaction.

This function makes it possible to start a transaction with another transaction as backend, instead of an actual data store. This can be useful if we want to make a set of related changes, and then either apply or discard them all based on some criterion, while other changes remain unaffected. The thandle identifies the backend transaction to use. If 'usid' is 0, the transaction will be started within the user session associated with the MAAPI socket, otherwise it will be started within the user session given by usid. If we call apply() on this "transaction in a transaction" object, the changes (if any) will be applied to the backend transaction. To discard the changes, call finish() without calling apply() first.

Arguments:

  • th -- transaction handle

  • readwrite -- Either READ or READ_WRITE flag (ncs)

  • usid -- user id (int)

Returns:

  • transaction (maapi.Transaction)

start_user_session(...)

Method:

Start a new user session.

This method gives some resonable defaults.

Arguments:

  • user - username (str)

  • context - context for the session (str)

  • groups - groups (list)

  • src_ip - source ip address (str)

  • src_port - source port (int)

  • proto - protocol used by for connecting (i.e. ncs.PROTO_TCP)

  • vendor -- lock error information (str, optional)

  • product -- lock error information (str, optional)

  • version -- lock error information (str, optional)

  • client_id -- lock error information (str, optional)

  • path -- path to Unix-domain socket (only for NSO)

Protocol flags (ncs):

  • PROTO_CONSOLE

  • PROTO_HTTP

  • PROTO_HTTPS

  • PROTO_SSH

  • PROTO_SSL

  • PROTO_SYSTEM

  • PROTO_TCP

  • PROTO_TLS

  • PROTO_TRACE

  • PROTO_UDP

Example use:

start_write_trans(...)

Method:

Start a write transaction.

For details see start_trans().

write_service_log_entry(...)

Method:

Write service log entries.

This function makes it possible to write service log entries from FASTMAP code.

class NoOverwriteScope

Enumeration for no-overwrite scopes: WRITE_SET_ONLY = 1 WRITE_AND_FULL_READ_SET = 2 WRITE_AND_SERVICE_READ_SET = 3

Members:

WRITE_AND_FULL_READ_SET
WRITE_AND_SERVICE_READ_SET
WRITE_SET_ONLY
name

The name of the Enum member.

value

The value of the Enum member.

class Session

Encapsulate a MAAPI user session.

Context manager for user sessions. This class makes it easy to use a single Maapi connection and switch user session along the way. For example:

Initialize a Session object via start_user_session().

Arguments:

  • maapi -- maapi object (maapi.Maapi)

  • for all other arguments see start_user_session()

Members:

close(...)

Method:

Close the user session.

class TemplateTypes

Enumeration for template types: DEVICE_TEMPLATE = 0 SERVICE_TEMPLATE = 1 COMPLIANCE_TEMPLATE = 2

Members:

COMPLIANCE_TEMPLATE
DEVICE_TEMPLATE
SERVICE_TEMPLATE
name

The name of the Enum member.

value

The value of the Enum member.

class Transaction

Class that corresponds to a single MAAPI transaction.

Initialize a Transaction object.

When created one may access the maapi and th arguments like this:

An instance of this class is also a context manager:

When exiting the with statement, finish() will be called.

If 'th' is left out (or None) a new transaction is started using the 'db' and 'rw' arguments, otherwise 'db' and 'rw' are ignored.

Arguments:

  • maapi -- a Maapi object (maapi.Maapi)

  • th -- a transaction handle or None

  • rw -- Either READ or READ_WRITE flag (ncs)

  • db -- Either CANDIDATE, RUNNING or STARTUP flag (cdb)

  • vendor -- lock error information (optional)

  • product -- lock error information (optional)

  • version -- lock error information (optional)

  • client_id -- lock error information (optional)

Members:

abort(...)

Method:

Abort the transaction.

apply(...)

Method:

Apply the transaction.

Validates, prepares and eventually commits or aborts the transaction. If the validation fails and the 'keep_open' argument is set to True (default), the transaction is left open and the developer can react upon the validation errors.

Arguments:

  • keep_open -- keep transaction open (boolean)

  • flags - additional transaction flags (int)

Flags (maapi):

  • COMMIT_NCS_NO_REVISION_DROP

  • COMMIT_NCS_NO_DEPLOY

  • COMMIT_NCS_NO_NETWORKING

  • COMMIT_NCS_NO_OUT_OF_SYNC_CHECK

  • COMMIT_NCS_NO_OVERWRITE_WRITE_SET_ONLY

  • COMMIT_NCS_NO_OVERWRITE_WRITE_AND_FULL_READ_SET

  • COMMIT_NCS_NO_OVERWRITE_WRITE_AND_FULL_SERVICE_SET

  • COMMIT_NCS_USE_LSA

  • COMMIT_NCS_NO_LSA

  • COMMIT_NCS_RECONCILE_KEEP_NON_SERVICE_CONFIG

  • COMMIT_NCS_RECONCILE_DISCARD_NON_SERVICE_CONFIG

  • COMMIT_NCS_RECONCILE_ATTACH_NON_SERVICE_CONFIG

  • COMMIT_NCS_RECONCILE_DETACH_NON_SERVICE_CONFIG

  • COMMIT_NCS_CONFIRM_NETWORK_STATE

  • COMMIT_NCS_CONFIRM_NETWORK_STATE_RE_EVALUATE_POLICIES

  • COMMIT_NCS_CONFIRM_NETWORK_STATE_RE_DEPLOY_ALL

apply_params(...)

Method:

Apply the transaction and return the result in form of dict().

Validates, prepares and eventually commits or aborts the transaction. If the validation fails and the 'keep_open' argument is set to True (default), the transaction is left open and the developer can react upon the validation errors.

The 'params' argument represent commit parameters. See CommitParams class for available commit parameters.

The result is a dictionary representing the result of applying transaction. If dry-run was requested, then the resulting dictionary will have 'dry-run' key set along with the actual results. If commit through commit queue was requested, then the resulting dictionary will have 'commit-queue' key set. Otherwise the dictionary will be empty.

Arguments:

  • keep_open -- keep transaction open (boolean)

  • params -- list of commit parameters (maapi.CommitParams)

Returns:

  • dict (see above)

Example use:

commit(...)

Method: