The <lock> operation locks a configuration database. A locked configuration database cannot be modified by other clients. The locks eliminate errors caused by simultaneous database modifications by the NETCONF manager and other NETCONF managers or Simple Network Management Protocol (SNMP) or command-line interface (CLI) scripts.
If the specified configuration database is already locked by a client, the <error-tag> element will be "lock-denied" and the <error-info> element will include the <session-id> of the lock owner.
If the <running/> configuration database is successfully locked:
RPC request
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <lock> <target> <running/> </target> </lock> </rpc>
RPC reply
<rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <ok/> </rpc-reply>
If the NMDA data set is supported, the data set format in the target configuration database is different, as shown in the following:
RPC request
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <lock xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores"> <target> <datastore xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda">ds:running</datastore> </target> </lock> </rpc>
RPC reply
<rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <ok/> </rpc-reply>
If the <running/> configuration database fails to be locked:
RPC request
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <lock> <target> <running/> </target> </lock> </rpc>
RPC reply
<rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <rpc-error> <error-type>protocol</error-type> <error-tag>lock-denied</error-tag> <error-severity>error</error-severity> <error-app-tag>43</error-app-tag> <error-message>The configuration is locked by other user. [Session ID = 629] </error-message> <error-info> <session-id>629</session-id> <error-paras> <error-para>629</error-para> </error-paras> </error-info> </rpc-error> </rpc-reply>
If the NMDA data set is supported, the data set format in the target configuration database is different, as shown in the following:
RPC request
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <lock xmlns:ds="urn:ietf:params:xml:ns:yang:ietf-datastores"> <target> <datastore xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-nmda">ds:running</datastore> </target> </lock> </rpc>
RPC reply
<rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <rpc-error> <error-type>protocol</error-type> <error-tag>lock-denied</error-tag> <error-severity>error</error-severity> <error-app-tag>43</error-app-tag> <error-message>The configuration is locked by other user. [Session ID = 629] </error-message> <error-info> <session-id>629</session-id> <error-paras> <error-para>629</error-para> </error-paras> </error-info> </rpc-error> </rpc-reply>