<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic YDK server disconnection in Tools</title>
    <link>https://community.cisco.com/t5/tools/ydk-server-disconnection/m-p/4090000#M1889</link>
    <description>&lt;P&gt;Does anybody knows a way to clean close the provider connection in YDK 0.8.4?&lt;/P&gt;
&lt;P&gt;It complains about no attribute Disconnect() in provider or no __enter__ when used in a with clause in Python.&lt;/P&gt;</description>
    <pubDate>Thu, 21 May 2020 14:14:46 GMT</pubDate>
    <dc:creator>vsoaresf</dc:creator>
    <dc:date>2020-05-21T14:14:46Z</dc:date>
    <item>
      <title>YDK server disconnection</title>
      <link>https://community.cisco.com/t5/tools/ydk-server-disconnection/m-p/4090000#M1889</link>
      <description>&lt;P&gt;Does anybody knows a way to clean close the provider connection in YDK 0.8.4?&lt;/P&gt;
&lt;P&gt;It complains about no attribute Disconnect() in provider or no __enter__ when used in a with clause in Python.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 14:14:46 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-server-disconnection/m-p/4090000#M1889</guid>
      <dc:creator>vsoaresf</dc:creator>
      <dc:date>2020-05-21T14:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: YDK server disconnection</title>
      <link>https://community.cisco.com/t5/tools/ydk-server-disconnection/m-p/4091019#M1890</link>
      <description>&lt;P&gt;Hello vsoaresf&lt;/P&gt;&lt;P&gt;Currently the YDK does not implement closing of NetconfSession. It is getting closed by destructor when class instance is out of scope. It is designed this way to avoid dangling NetconfSession class instances, which are not connected to the device. Correspondently you have to design your application. Do not use global variables for NetconfSession or NetconfServiceProvider, but rather use them inside functions, which are called by data processing application. When function is finished, the class instance will be destroyed automatically and connection will be dropped.&lt;/P&gt;&lt;P&gt;Here is simple example:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;#!/usr/bin/env python&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;#&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;ydk.services &lt;SPAN&gt;import &lt;/SPAN&gt;CRUDService&lt;BR /&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;ydk.providers &lt;SPAN&gt;import &lt;/SPAN&gt;NetconfServiceProvider&lt;BR /&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;ydk.models.openconfig &lt;SPAN&gt;import &lt;/SPAN&gt;openconfig_interfaces&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;nc_read&lt;/SPAN&gt;(device&lt;SPAN&gt;, &lt;/SPAN&gt;filter):&lt;BR /&gt;    provider = NetconfServiceProvider(&lt;BR /&gt;        &lt;SPAN&gt;address&lt;/SPAN&gt;=device[&lt;SPAN&gt;'address'&lt;/SPAN&gt;]&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;port&lt;/SPAN&gt;=device[&lt;SPAN&gt;'port'&lt;/SPAN&gt;]&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;username&lt;/SPAN&gt;=device[&lt;SPAN&gt;'username'&lt;/SPAN&gt;]&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;password&lt;/SPAN&gt;=device[&lt;SPAN&gt;'password'&lt;/SPAN&gt;]&lt;BR /&gt;    )&lt;BR /&gt;    crud = CRUDService()&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;crud.read(provider&lt;SPAN&gt;, &lt;/SPAN&gt;filter)&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if &lt;/SPAN&gt;__name__ == &lt;SPAN&gt;'__main__'&lt;/SPAN&gt;:&lt;BR /&gt;    device = {&lt;BR /&gt;        &lt;SPAN&gt;'address'&lt;/SPAN&gt;: &lt;SPAN&gt;'ios-xe-mgmt.cisco.com'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;'port'&lt;/SPAN&gt;: &lt;SPAN&gt;10000&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;'username'&lt;/SPAN&gt;: &lt;SPAN&gt;'developer'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;'password'&lt;/SPAN&gt;: &lt;SPAN&gt;'C1sco12345'&lt;BR /&gt;&lt;/SPAN&gt;    }&lt;BR /&gt;    interfaces = openconfig_interfaces.Interfaces()&lt;BR /&gt;    all_interfaces = nc_read(device&lt;SPAN&gt;, &lt;/SPAN&gt;interfaces)&lt;BR /&gt;    &lt;SPAN&gt;# Process all_interfaces entity&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Inside &lt;EM&gt;main&lt;/EM&gt;&amp;nbsp;you can safely call &lt;EM&gt;nc_read&lt;/EM&gt;&amp;nbsp;function as many times as you want for any device and any filter. Each time it is called there will be established Netconf session with device and after operation it will be safely closed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 22:25:21 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-server-disconnection/m-p/4091019#M1890</guid>
      <dc:creator>yangorelik</dc:creator>
      <dc:date>2020-05-22T22:25:21Z</dc:date>
    </item>
  </channel>
</rss>

