ydk.services module¶
services.py
The Services module. Supported services include
CRUDService: Provides Create/Read/Update/Delete API’s¶
-
class
ydk.services.
CRUDService
¶ Bases:
ydk.services.Service
CRUD Service class for supporting CRUD operations on entities.
-
create
(provider, entity)¶ Create the entity
Parameters: - provider – An instance of ydk.providers.ServiceProvider
- entity – An instance of an entity class defined under the ydk.models package or subpackages.
Returns: None
Raises: - ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError – if other error has occurred
Possible Errors:
- a server side error
- there isn’t enough information in the entity to prepare the message (eg. missing keys)
-
read
(provider, read_filter, only_config=False)¶ Read the entity or entities.
Parameters: - provider – An instance of ydk.providers.ServiceProvider
- read_filter – A read_filter is an instance of an entity class. An entity class is a class defined under the ydk.models package that is not an Enum, Identity or a subclass of FixedBitsDict). Attributes of this entity class may contain values that act as match expressions or can be explicitly marked as to be read by assigning an instance of type ydk.types.READ to them.
- only_config – Flag that indicates that only the data that represents configuration data is to be fetched. Default is set to False i.e both oper and config data will be fetched.
Returns: The entity or list of entities as identified by the read_filter
Raises: - ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError – if other error has occurred
Possible errors could be
- a server side error
- if there isn’t enough information in the entity to prepare the message (missing keys for example)
-
update
(provider, entity)¶ Update the entity.
Note:
- An attribute of an entity class can be deleted by setting to an instance of ydk.types.DELETE.
- An entity can only be updated if it exists on the server. Otherwise a ydk.errors.YPYError will be raised.
Parameters: - provider – An instance of ydk.providers.ServiceProvider
- entity – An instance of an entity class defined under the ydk.models package or subpackages.
Returns: None
Raises: - ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError – if other error has occurred
Possible errors could be
- a server side error
- if there isn’t enough information in the entity to the message (missing keys for example)
-
delete
(provider, entity)¶ Delete the entity
Parameters: - provider – An instance of ydk.providers.ServiceProvider
- entity – An instance of an entity class defined under the ydk.models package or subpackages.
Returns: None
Raises: - ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError – if other error has occurred
Possible errors could be
- a server side error
- if there isn’t enough information in the entity to the message (missing keys for example)
-
NetconfService: Provides API’s to execute netconf operations¶
-
class
ydk.services.
Datastore
¶ Bases:
enum.Enum
Netconf datastore type
-
candidate = 1
Candidate
-
running = 2
Running
-
startup = 3
Startup
-
-
class
ydk.services.
NetconfService
¶
Bases: ydk.services.Service
.
Netconf Service class for executing netconf operations.
cancel_commit
(provider, persist_id=None)¶Execute an cancel-commit operation to cancel an ongoing confirmed commit.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- persist_id (str) – This parameter is given in order to cancel a persistent confirmed commit. The value must be equal to the value given in the ‘persist’ parameter to the commit operation. If it does not match, the operation fails with an ‘invalid-value’ error.
Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – If validation error has occurred.
- ydk.errors.YPYError –
If other error has occurred. Possible errors could be:
- A server side error
- If there isn’t enough information in the entity to the message (missing keys for example).
close_session
(provider)¶Execute a close-session operation to cancel an ongoing confirmed commit.
Parameters: provider (ydk.providers.ServiceProvider) – A provider instance.
Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
commit
(provider, confirmed=False, confirm_timeout=None, persist=False, persist_id=None)¶Execute a commit operation to commit the candidate configuration as the device’s new current configuration.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- confirmed (bool) – Perform a confirmed commit operation.
- confirm_timeout (int) – The timeout interval for a confirmed commit.
- persist (str) – Make a confirmed commit persistent. A persistent confirmed commit is not aborted if the NETCONF session terminates. The only way to abort a persistent confirmed commit is to let the timer expire, or to use the <cancel-commit> operation. The value of this parameter is a token that must be given in the ‘persist-id’ parameter of <commit> or <cancel-commit> operations in order to confirm or cancel the persistent confirmed commit. The token should be a random string.
- persist_id (str) – This parameter is given in order to commit a persistent confirmed commit. The value must be equal to the value given in the ‘persist’ parameter to the <commit> operation. If it does not match, the operation fails with an ‘invalid-value’ error.
Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
copy_config
(provider, target, source, with_defaults_option=None)¶Execute a copy-config operation to create or replace an entire configuration datastore with the contents of another complete configuration datastore.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- target – Particular configuration to copy to. Valid options are
Datastore.candidate
,Datastore.running
,Datastore.startup
and url(str
) if the device has such feature advertised in device capability.- source – Particular configuration to copy from. Valid options are
Datastore.candidate
,Datastore.running
,Datastore.startup
and url(str
) if the deivce has such feature advertised in capability. A YDK entity object can also be used for this parameter.- with_defaults (
ietf_netconf.WithDefaultsModeEnum
) – The explicit defaults processing mode requested.Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
delete_config
(provider, target)¶Execute an delete-config operation to delete a configuration datastore.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- target – Particular configuration to delete. Valid options are
Datastore.startup
or url(str
).Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
discard_changes
(provider)¶Execute a discard-changes operation to revert the candidate configuration to the current running configuration.
Parameters: provider (ydk.providers.ServiceProvider) – A provider instance.
Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
edit_config
(provider, target, config, default_operation=None, error_option=None, test_option=None)¶Execute an edit-config operation to load all or part of a specified configuration to the specified target configuration.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- target – Particular configuration to copy from. Valid options are
Datastore.candidate
,Datastore.running
.- config – A YDK entity object used as a config block.
- default_operation (
EditConfigRpc.Input.DefaultOperationEnum
) – Selects the default operation for this edit-config request.- error_option (
EditConfigRpc.Input.ErrorOptionEnum
) – Selects the error option for this edit-config request.- test_option (
EditConfigRpc.Input.TestOptionEnum
) – Selects the test option for this edit-config request.Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
get_config
(provider, source, get_filter, with_defaults_option=None)¶Execute a get-config operation to retrieve all or part of a specified configuration.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- get_filter – A YDK entity object used as a subtree filter or XPath filter.
- source – Particular configuration to retrieve. Valid options are
Datastore.candidate
,Datastore.running
, andDatastore.startup
.- with_defaults (
ietf_netconf.WithDefaultsModeEnum
) – The explicit defaults processing mode requested.Returns: A YDK entity object represents copy of the running datastore subset and/or state data that matched the filter criteria (if any). An empty data container indicates that the request did not produce any results.
Return type: object
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
get
(provider, get_filter, with_defaults_option=None)¶Execute a get operation to retrieve running configuration and device state information.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- get_filter – This parameter specifies the portion of the system configuration and state data to retrieve.
- with_defaults (
ietf_netconf.WithDefaultsModeEnum
) – The explicit defaults processing mode requested.Returns: A YDK entity object represents copy of the running datastore subset and/or state data that matched the filter criteria (if any). An empty data container indicates that the request did not produce any results.
Return type: object
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
kill_session
(provider, session_id)¶Execute a kill-session operation to force the termination of a NETCONF session.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- session_id (int) – Particular session to kill.
Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
lock
(provider, target)¶Execute a lock operation to allow the client to lock the configuration system of a device.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- target – Particular configuration to lock. Valid options are
Datastore.candidate
,Datastore.running
, andDatastore.startup
if the device has such feature advertised.Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
unlock
(provider, target)¶Execute an unlock operation to release a configuration lock, previously obtained with the ‘lock’ operation.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- target – Particular configuration to unlock. Valid options are
Datastore.candidate
,Datastore.running
, andDatastore.startup
if the device has such feature advertised.Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError –
if other error has occurred
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
validate
(provider, source=None, config=None)¶Execute a validate operation to validate the contents of the specified configuration.
Parameters:
- provider (ydk.providers.ServiceProvider) – A provider instance.
- source – Particular configuration to validate. Valid options are
Datastore.candidate
,Datastore.running
,Datastore.startup
and url(str
) if the deivce has such feature advertised in device capability. A YDK entity object can also be used for this parameter.- with_defaults (
ietf_netconf.WithDefaultsModeEnum
) – The explicit defaults processing mode requested.Returns: An ok reply string if operation succeeds.
Return type: str
Raises:
- ydk.errors.YPYDataValidationError – if validation error has occurred.
- ydk.errors.YPYError –
if other error has occurred.
Possible errors could be:
- A server side error.
- If there isn’t enough information in the entity to the message (missing keys for example).
CodecService: Provides encode/decode API’s¶
-
class
ydk.services.
CodecService
¶ Bases:
ydk.services.Service
Codec Service class for supporting encoding entities and decoding payloads.
-
encode
(provider, entity)¶ - Encodes the python entity and returns the payload. Entity is either:
- an instance of an entity class defined under the ydk.models package or subpackages, or
- a dictionary containing:
- module names as keys and
- entity instances as values
Returns: encoded value can be: - an instance of an XML payload defined for a yang module, or - a dictionary containing: - module names as keys and
- instances of XML payload defined for a yang module as values
Raises: ydk.errors.YPYDataValidationError – if validation error has occurred
-
decode
(provider, payload)¶ - Decodes the the payload and returns the python entity. Payload is either:
- an instance of an XML payload defined for a yang module, or
- a dictionary containing:
- module names as keys and
- instances of XML payload defined for a yang module as values
Returns: decoded entity. Entity is either: - an instance of an entity class defined under the ydk.models package or subpackages, or - a dictionary containing: - module names as keys and
- entity instances as values
Raises: ydk.errors.YPYDataValidationError – if validation error has occurred
-
ExecutorService: Provides API to execute RPCs¶
-
class
ydk.services.
ExecutorService
¶ Bases:
ydk.services.Service
Executor Service class for supporting execution of RPCs.
-
execute_rpc(self, provider, rpc):
Create the entity
Parameters: - provider – An instance of ydk.providers.ServiceProvider
- rpc – An instance of an RPC class defined under the ydk.models package or subpackages
Returns: None
Raises: - ydk.errors.YPYDataValidationError – if validation error has occurred
- ydk.errors.YPYError – if other error has occurred
Possible Errors:
- a server side error
- there isn’t enough information in the entity to prepare the message (eg. missing keys)
-