File: ndb_sources.html

package info (click to toggle)
pyroute2 0.5.14-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,220 kB
  • sloc: python: 31,916; javascript: 8,256; ansic: 81; makefile: 14
file content (187 lines) | stat: -rw-r--r-- 12,186 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>RTNL sources &#8212; pyroute2 0.5.14 documentation</title>
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="_static/custom.css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Debug and logging" href="ndb_debug.html" />
    <link rel="prev" title="Database" href="ndb_schema.html" />
  </head><body>

    <div class="related" role="navigation" aria-label="related navigation">
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="ndb_debug.html" title="Debug and logging"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="ndb_schema.html" title="Database"
             accesskey="P">previous</a> |</li>
        <li class="nav-item"><a href="http://pyroute2.org">Project home</a> &#187;</li>
        <li class="nav-item nav-item-0"><a href="index.html">pyroute2 0.5.14 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="ndb.html" accesskey="U">NDB module</a> &#187;</li> 
      </ul>
        </div>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-pyroute2.ndb.source">
<span id="rtnl-sources"></span><span id="ndbsources"></span><h1>RTNL sources<a class="headerlink" href="#module-pyroute2.ndb.source" title="Permalink to this headline">¶</a></h1>
<div class="section" id="local-rtnl">
<h2>Local RTNL<a class="headerlink" href="#local-rtnl" title="Permalink to this headline">¶</a></h2>
<p>Local RTNL source is a simple <cite>IPRoute</cite> instance. By default NDB
starts with one local RTNL source names <cite>localhost</cite>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ndb</span> <span class="o">=</span> <span class="n">NDB</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ndb</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">details</span><span class="p">()</span>
<span class="go">{&#39;kind&#39;: u&#39;local&#39;, u&#39;nlm_generator&#39;: 1, &#39;target&#39;: u&#39;localhost&#39;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ndb</span><span class="o">.</span><span class="n">sources</span><span class="p">[</span><span class="s1">&#39;localhost&#39;</span><span class="p">]</span>
<span class="go">[running] &lt;IPRoute {&#39;nlm_generator&#39;: 1}&gt;</span>
</pre></div>
</div>
<p>The <cite>localhost</cite> RTNL source starts an additional async cache thread.
The <cite>nlm_generator</cite> option means that instead of collections the
<cite>IPRoute</cite> object returns generators, so <cite>IPRoute</cite> responses will not
consume memory regardless of the RTNL objects number:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ndb</span><span class="o">.</span><span class="n">sources</span><span class="p">[</span><span class="s1">&#39;localhost&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">nl</span><span class="o">.</span><span class="n">link</span><span class="p">(</span><span class="s1">&#39;dump&#39;</span><span class="p">)</span>
<span class="go">&lt;generator object _match at 0x7fa444961e10&gt;</span>
</pre></div>
</div>
<p>See also: <a class="reference internal" href="iproute.html#iproute"><span class="std std-ref">IPRoute module</span></a></p>
</div>
<div class="section" id="network-namespaces">
<h2>Network namespaces<a class="headerlink" href="#network-namespaces" title="Permalink to this headline">¶</a></h2>
<p>There are two ways to connect additional sources to an NDB instance.
One is to specify sources when creating an NDB object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ndb</span> <span class="o">=</span> <span class="n">NDB</span><span class="p">(</span><span class="n">sources</span><span class="o">=</span><span class="p">[{</span><span class="s1">&#39;target&#39;</span><span class="p">:</span> <span class="s1">&#39;localhost&#39;</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;netns&#39;</span><span class="p">:</span> <span class="s1">&#39;test01&#39;</span><span class="p">}])</span>
</pre></div>
</div>
<p>Another way is to call <cite>ndb.sources.add()</cite> method:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ndb</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">netns</span><span class="o">=</span><span class="s1">&#39;test01&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>This syntax: <cite>{target’: ‘localhost’}</cite> and <cite>{‘netns’: ‘test01’}</cite> is the
short form. The full form would be:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">&#39;target&#39;</span><span class="p">:</span> <span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="c1"># the label for the DB</span>
 <span class="s1">&#39;kind&#39;</span><span class="p">:</span> <span class="s1">&#39;local&#39;</span><span class="p">,</span>       <span class="c1"># use IPRoute class to start the source</span>
 <span class="s1">&#39;nlm_generator&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">}</span>    <span class="c1">#</span>

<span class="p">{</span><span class="s1">&#39;target&#39;</span><span class="p">:</span> <span class="s1">&#39;test01&#39;</span><span class="p">,</span>    <span class="c1"># the label</span>
 <span class="s1">&#39;kind&#39;</span><span class="p">:</span> <span class="s1">&#39;netns&#39;</span><span class="p">,</span>       <span class="c1"># use NetNS class</span>
 <span class="s1">&#39;netns&#39;</span><span class="p">:</span> <span class="s1">&#39;test01&#39;</span><span class="p">}</span>     <span class="c1">#</span>
</pre></div>
</div>
<p>See also: <a class="reference internal" href="wireguard.html#netns"><span class="std std-ref">WireGuard module</span></a></p>
</div>
<div class="section" id="remote-systems">
<h2>Remote systems<a class="headerlink" href="#remote-systems" title="Permalink to this headline">¶</a></h2>
<p>It is possible also to connect to remote systems using SSH. In order to
use this kind of sources it is required to install the
<a class="reference external" href="https://github.com/dw/mitogen">mitogen</a> module. The <cite>remote</cite> kind
of sources uses the <cite>RemoteIPRoute</cite> class. The short form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ndb</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">hostname</span><span class="o">=</span><span class="s1">&#39;worker1.example.com&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>In some more extended form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ndb</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s1">&#39;target&#39;</span><span class="p">:</span> <span class="s1">&#39;worker1.example.com&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;kind&#39;</span><span class="p">:</span> <span class="s1">&#39;remote&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;hostname&#39;</span><span class="p">:</span> <span class="s1">&#39;worker1.example.com&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;username&#39;</span><span class="p">:</span> <span class="s1">&#39;jenkins&#39;</span><span class="p">,</span>
                   <span class="s1">&#39;check_host_keys&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">})</span>
</pre></div>
</div>
<p>See also: <a class="reference internal" href="remote.html#remote"><span class="std std-ref">RemoteIPRoute</span></a></p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">RTNL sources</a><ul>
<li><a class="reference internal" href="#local-rtnl">Local RTNL</a></li>
<li><a class="reference internal" href="#network-namespaces">Network namespaces</a></li>
<li><a class="reference internal" href="#remote-systems">Remote systems</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="ndb_schema.html"
                        title="previous chapter">Database</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="ndb_debug.html"
                        title="next chapter">Debug and logging</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/ndb_sources.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="ndb_debug.html" title="Debug and logging"
             >next</a> |</li>
        <li class="right" >
          <a href="ndb_schema.html" title="Database"
             >previous</a> |</li>
        <li class="nav-item"><a href="http://pyroute2.org">Project home</a> &#187;</li>
        <li class="nav-item nav-item-0"><a href="index.html">pyroute2 0.5.14 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="ndb.html" >NDB module</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2013, Peter V. Saveliev.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.1.2.
    </div>
  </body>
</html>