-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: ab0cb98f2986eaad15a741f3cfa333d8 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<!DOCTYPE html> | ||
<html class="writer-html5" lang="en" data-content_root="../../"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>cloudvision.Connector — CloudVision Python 1.21.1 documentation</title> | ||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=80d5e7a1" /> | ||
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" /> | ||
|
||
|
||
<!--[if lt IE 9]> | ||
<script src="../../_static/js/html5shiv.min.js"></script> | ||
<![endif]--> | ||
|
||
<script src="../../_static/jquery.js?v=5d32c60e"></script> | ||
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> | ||
<script src="../../_static/documentation_options.js?v=ffc33bb7"></script> | ||
<script src="../../_static/doctools.js?v=9a2dae69"></script> | ||
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script> | ||
<script src="../../_static/js/theme.js"></script> | ||
<link rel="index" title="Index" href="../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../search.html" /> | ||
</head> | ||
|
||
<body class="wy-body-for-nav"> | ||
<div class="wy-grid-for-nav"> | ||
<nav data-toggle="wy-nav-shift" class="wy-nav-side"> | ||
<div class="wy-side-scroll"> | ||
<div class="wy-side-nav-search" > | ||
|
||
|
||
|
||
<a href="../../index.html" class="icon icon-home"> | ||
CloudVision Python | ||
</a> | ||
<div class="version"> | ||
1.21.1 | ||
</div> | ||
<div role="search"> | ||
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> | ||
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" /> | ||
<input type="hidden" name="check_keywords" value="yes" /> | ||
<input type="hidden" name="area" value="default" /> | ||
</form> | ||
</div> | ||
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> | ||
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">cloudvision</a></li> | ||
</ul> | ||
|
||
</div> | ||
</div> | ||
</nav> | ||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > | ||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i> | ||
<a href="../../index.html">CloudVision Python</a> | ||
</nav> | ||
|
||
<div class="wy-nav-content"> | ||
<div class="rst-content"> | ||
<div role="navigation" aria-label="Page navigation"> | ||
<ul class="wy-breadcrumbs"> | ||
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li> | ||
<li class="breadcrumb-item"><a href="../index.html">Module code</a></li> | ||
<li class="breadcrumb-item active">cloudvision.Connector</li> | ||
<li class="wy-breadcrumbs-aside"> | ||
</li> | ||
</ul> | ||
<hr/> | ||
</div> | ||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> | ||
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for cloudvision.Connector</h1><div class="highlight"><pre> | ||
<span></span><span class="c1"># Copyright (c) 2020 Arista Networks, Inc.</span> | ||
<span class="c1"># Use of this source code is governed by the Apache License 2.0</span> | ||
<span class="c1"># that can be found in the COPYING file.</span> | ||
|
||
<span class="kn">import</span> <span class="nn">logging</span> | ||
<span class="n">name</span> <span class="o">=</span> <span class="s2">"cloudvision.Connector"</span> | ||
|
||
|
||
<div class="viewcode-block" id="process_notifs"> | ||
<a class="viewcode-back" href="../../cloudvision.Connector.html#cloudvision.Connector.process_notifs">[docs]</a> | ||
<span class="k">def</span> <span class="nf">process_notifs</span><span class="p">(</span><span class="n">stream</span><span class="p">,</span> <span class="n">paths</span><span class="o">=</span><span class="p">{},</span> <span class="n">keys</span><span class="o">=</span><span class="p">{},</span> <span class="n">nominalKeys</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> | ||
<span class="w"> </span><span class="sd">"""</span> | ||
<span class="sd"> process_notifs consume the batch coming from stream and return them</span> | ||
<span class="sd"> as a hierarchy of dataset, path, and keys. Allowing for faster access</span> | ||
<span class="sd"> of a given time serie.</span> | ||
<span class="sd"> """</span> | ||
<span class="n">res</span> <span class="o">=</span> <span class="p">{}</span> | ||
|
||
<span class="k">for</span> <span class="n">batch</span> <span class="ow">in</span> <span class="n">stream</span><span class="p">:</span> | ||
<span class="n">dname</span> <span class="o">=</span> <span class="n">batch</span><span class="p">[</span><span class="s2">"dataset"</span><span class="p">][</span><span class="s2">"name"</span><span class="p">]</span> | ||
<span class="k">for</span> <span class="n">notif</span> <span class="ow">in</span> <span class="n">batch</span><span class="p">[</span><span class="s2">"notifications"</span><span class="p">]:</span> | ||
<span class="n">time</span> <span class="o">=</span> <span class="n">notif</span><span class="p">[</span><span class="s2">"timestamp"</span><span class="p">]</span> | ||
<span class="n">path</span> <span class="o">=</span> <span class="s2">"/"</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">notif</span><span class="p">[</span><span class="s2">"path_elements"</span><span class="p">])</span> | ||
<span class="k">if</span> <span class="n">paths</span> <span class="ow">and</span> <span class="n">path</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">:</span> | ||
<span class="k">continue</span> | ||
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">notif</span><span class="p">[</span><span class="s2">"updates"</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> | ||
<span class="k">if</span> <span class="n">keys</span> <span class="ow">and</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span> | ||
<span class="k">continue</span> | ||
<span class="n">value</span> <span class="o">=</span> <span class="n">__get_val</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">nominalKeys</span><span class="p">)</span> | ||
<span class="n">res</span> <span class="o">=</span> <span class="n">__update_dict</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">dname</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">nominalKeys</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">time</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="n">res</span></div> | ||
|
||
|
||
|
||
<span class="k">def</span> <span class="nf">__get_val</span><span class="p">(</span><span class="n">nominal</span><span class="p">,</span> <span class="n">nomKeys</span><span class="p">):</span> | ||
<span class="n">res</span> <span class="o">=</span> <span class="n">nominal</span> | ||
<span class="k">if</span> <span class="n">nomKeys</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> | ||
<span class="k">return</span> <span class="n">res</span> | ||
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">nomKeys</span><span class="p">:</span> | ||
<span class="k">if</span> <span class="n">k</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">res</span><span class="p">:</span> | ||
<span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span> | ||
<span class="w"> </span><span class="sd">"""</span> | ||
<span class="sd"> Key %s not found in json %s</span> | ||
<span class="sd"> Full nominal %s</span> | ||
<span class="sd"> Nominal key path %s</span> | ||
<span class="sd"> """</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">res</span><span class="p">,</span> <span class="n">nominal</span><span class="p">,</span> <span class="n">nomKeys</span><span class="p">))</span> | ||
<span class="k">return</span> <span class="kc">None</span> | ||
<span class="n">res</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> | ||
<span class="k">return</span> <span class="n">res</span> | ||
|
||
|
||
<span class="k">def</span> <span class="nf">__update_dict</span><span class="p">(</span><span class="n">resDict</span><span class="p">,</span> <span class="n">dataset</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">nominalKeys</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">ts</span><span class="p">):</span> | ||
<span class="n">entry</span> <span class="o">=</span> <span class="n">resDict</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="n">dataset</span><span class="p">,</span> | ||
<span class="p">{})</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> | ||
<span class="p">{})</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="p">{})</span> | ||
<span class="k">if</span> <span class="n">nominalKeys</span><span class="p">:</span> | ||
<span class="n">entry</span> <span class="o">=</span> <span class="n">entry</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s2">"/"</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">nominalKeys</span><span class="p">),</span> <span class="p">{})</span> | ||
<span class="n">entry</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s2">"values"</span><span class="p">,</span> <span class="p">[])</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> | ||
<span class="n">entry</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="s2">"timestamps"</span><span class="p">,</span> <span class="p">[])</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ts</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="n">resDict</span> | ||
|
||
|
||
<div class="viewcode-block" id="sort_dict"> | ||
<a class="viewcode-back" href="../../cloudvision.Connector.html#cloudvision.Connector.sort_dict">[docs]</a> | ||
<span class="k">def</span> <span class="nf">sort_dict</span><span class="p">(</span><span class="n">resDict</span><span class="p">):</span> | ||
<span class="w"> </span><span class="sd">"""</span> | ||
<span class="sd"> sort_dict orders every timeseries in a hierarchy of dataset by its timestamps.</span> | ||
<span class="sd"> """</span> | ||
|
||
<span class="k">def</span> <span class="nf">sort_timeserie</span><span class="p">(</span><span class="n">timeserie</span><span class="p">):</span> | ||
<span class="n">timeserie</span><span class="p">[</span><span class="s2">"values"</span><span class="p">],</span> <span class="n">timeserie</span><span class="p">[</span><span class="s2">"timestamps"</span><span class="p">]</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="nb">sorted</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span> | ||
<span class="n">timeserie</span><span class="p">[</span><span class="s2">"values"</span><span class="p">],</span> | ||
<span class="n">timeserie</span><span class="p">[</span><span class="s2">"timestamps"</span><span class="p">]),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">seconds</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">nanos</span><span class="p">)))</span> | ||
|
||
<span class="n">stack</span> <span class="o">=</span> <span class="p">[</span><span class="n">resDict</span><span class="p">]</span> | ||
<span class="k">while</span> <span class="n">stack</span><span class="p">:</span> | ||
<span class="n">timeserie</span> <span class="o">=</span> <span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span> | ||
<span class="k">if</span> <span class="s2">"values"</span> <span class="ow">in</span> <span class="n">timeserie</span> <span class="ow">and</span> <span class="s2">"timestamps"</span> <span class="ow">in</span> <span class="n">timeserie</span><span class="p">:</span> | ||
<span class="n">sort_timeserie</span><span class="p">(</span><span class="n">timeserie</span><span class="p">)</span> | ||
<span class="k">else</span><span class="p">:</span> | ||
<span class="n">stack</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">timeserie</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> | ||
<span class="k">return</span> <span class="n">resDict</span></div> | ||
|
||
</pre></div> | ||
|
||
</div> | ||
</div> | ||
<footer> | ||
|
||
<hr/> | ||
|
||
<div role="contentinfo"> | ||
<p>© Copyright 2022, Arista.</p> | ||
</div> | ||
|
||
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a | ||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> | ||
provided by <a href="https://readthedocs.org">Read the Docs</a>. | ||
|
||
|
||
</footer> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
<script> | ||
jQuery(function () { | ||
SphinxRtdTheme.Navigation.enable(true); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |