NETCONFSession
Represents a NETCONF session to a network device. NETCONFSession objects are created with Node::openNETCONFSession() method.
Each operation is executed as a separate request through the node’s effective NETCONF proxy agent, which connects to the device over SSH using the node’s SSH credentials. Consecutive calls may be served by different pooled NETCONF sessions on the proxy agent. Operations whose effect is bound to a single NETCONF session (lock, unlock, kill-session, close-session, and confirmed commit without persist) are therefore not supported.
All methods return null or false on failure; the reason is available in lastErrorMessage attribute. Calls to editConfig(), commit(), discardChanges(), and rpc() are recorded in the audit log (for rpc(), only the operation name is logged).
Instance attributes
- lastErrorMessage: String
-
Text description of the last error, or empty string if the last operation completed successfully. For rpc() calls, contains text of
rpc-errorelement if the device returned an error reply.
- nodeId: int
-
ID of the node this session is connected to.
Instance methods
- commit(): bool
-
Commit candidate configuration to the running configuration (NETCONF
commitoperation). Requires:candidatecapability on the device.Returntrueon success,falseon failure.
- discardChanges(): bool
-
Revert candidate configuration to the current running configuration (NETCONF
discard-changesoperation). Requires:candidatecapability on the device.Returntrueon success,falseon failure.
- editConfig(config, target, defaultOperation): bool
-
Modify configuration datastore (NETCONF
edit-configoperation).Table 1. Parameters config
String
Configuration to apply as XML document (content of the
configelement).target
String
Target datastore:
"running","candidate", or"startup". Optional,"running"if omitted ornull.defaultOperation
String
Default operation for the configuration elements:
"merge","replace", or"none". Optional, device default (normallymerge) is used if omitted ornull.Returntrueon success,falseif configuration document or arguments are invalid, communication failed, or the device returned an error.session = $node.openNETCONFSession(); config = "<interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\">" .. "<interface><name>eth1</name><description>Uplink to core</description></interface>" .. "</interfaces>"; if (session.editConfig(config, "candidate")) { if (!session.commit()) println("Commit failed: " .. session.lastErrorMessage); } else { println("Edit failed: " .. session.lastErrorMessage); }
- get(filter, filterType): String
-
Retrieve running configuration and device state information (NETCONF
getoperation).Table 2. Parameters filter
String
Filter limiting the returned data: XML subtree filter or XPath expression, depending on
filterType. Optional, all data is returned if omitted ornull.filterType
String
Filter type:
"subtree"or"xpath". Optional,"subtree"if omitted ornull. XPath filters require:xpathcapability on the device.ReturnThe
dataelement of the reply (including thedatatags) as XML string, ornullon failure.session = $node.openNETCONFSession(); data = session.get("<system xmlns=\"urn:ietf:params:xml:ns:yang:ietf-system\"><hostname/></system>"); if (data != null) println(data); else println("NETCONF error: " .. session.lastErrorMessage);
- getConfig(datastore, filter, filterType): String
-
Retrieve configuration from the given datastore (NETCONF
get-configoperation).Table 3. Parameters datastore
String
Source datastore:
"running","candidate", or"startup". Optional,"running"if omitted ornull.filter
String
Filter limiting the returned data: XML subtree filter or XPath expression, depending on
filterType. Optional, full configuration is returned if omitted ornull.filterType
String
Filter type:
"subtree"or"xpath". Optional,"subtree"if omitted ornull.ReturnThe
dataelement of the reply (including thedatatags) as XML string, ornullon failure.session = $node.openNETCONFSession(); interfaces = session.getConfig("running", "/if:interfaces/if:interface/if:name", "xpath");
- rpc(content): String
-
Execute arbitrary NETCONF RPC. Use this method for operations not covered by other methods, such as vendor-specific RPCs.
Table 4. Parameters content
String
RPC operation element as XML (without the
rpcenvelope).ReturnFull
rpc-replydocument as XML string, ornullif the content is not valid XML, the operation is session-scoped (see above), or communication with the device failed. A reply containingrpc-erroris still returned; check lastErrorMessage to detect it.session = $node.openNETCONFSession(); reply = session.rpc("<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\"><identifier>ietf-interfaces</identifier></get-schema>"); if ((reply == null) || (session.lastErrorMessage != "")) println("Error: " .. session.lastErrorMessage);