-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Courtney Caldwell <courtneyccaldwell@gmail.com>
- Loading branch information
1 parent
b58cb70
commit b3b913d
Showing
18 changed files
with
493 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
================= | ||
How To Contribute | ||
================= | ||
|
||
While we welcome contributions, we ask that you please follow the guidelines below: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
=============================== | ||
Running Connections In Parallel | ||
=============================== | ||
|
||
It is possible to run multiple connections at the same time, and have them handled in a multi-threaded or multi-processing library. | ||
|
||
Testing is generally done using the ``concurrent.futures`` library, which is a high-level interface for asynchronously executing functions in a separate thread or process. | ||
|
||
The advantage of using ``concurrent.futures`` is that it behaves similar to the way the ``Connection`` object expects to be used, in that it runs in the hopes it works, and resolves errors after rather than interactively. | ||
|
||
Creating a bunch of connections | ||
------------------------------- | ||
|
||
Here's an example of how one might use ``concurrent.futures`` to run multiple connections at the same time. | ||
|
||
.. code-block:: python3 | ||
import concurrent.futures | ||
from fabricplus.connection import ConnectionPlus as Connection | ||
from traceback import format_exc | ||
# Create a list of hosts | ||
hosts: list[str] = [ | ||
"host1", | ||
"host2", | ||
"host3", | ||
"host4", | ||
"host5", | ||
"host6", | ||
"host7", | ||
"host8", | ||
"host9", | ||
"host10", | ||
] | ||
connections: list[Connection] = [] | ||
# Create a list of connections, concurrently | ||
with concurrent.futures.ThreadPoolExecutor() as executor: | ||
futures = [executor.submit(Connection, host) for host in hosts] | ||
tb: Optional[str] = None | ||
# the code below helps handle tracebacks and errors; | ||
# with out it, silent failures may occur | ||
for future in concurrent.futures.as_completed(futures): | ||
try: | ||
tb = None | ||
connections.append(future.result()) | ||
except Exception as e: | ||
tb = traceback.format_exc() | ||
finally: | ||
if tb: | ||
print(f"Error: {tb}") | ||
# Now you can use the connections, presuming they worked | ||
with concurrent.futures.ThreadPoolExecutor() as executor: | ||
futures = [executor.submit(connection.run, "ls -l") for connection in connections] | ||
tb: Optional[str] = None | ||
for future in concurrent.futures.as_completed(futures): | ||
try: | ||
tb = None | ||
print(future.result()) | ||
except Exception as e: | ||
tb = traceback.format_exc() | ||
finally: | ||
if tb: | ||
print(f"Error: {tb}") | ||
Important Note on ``SU`` In Parallelism | ||
--------------------------------------- | ||
|
||
The ``SU`` command is a special command that is used to switch users. | ||
|
||
It is one of the features I built this library for, and it generally works great. | ||
|
||
However, on some hosts, the ``SU`` command does NOT work in a non-interactive shell. | ||
|
||
This is because of some complex kernel behaviors in older versions to avoid a security vulnerability. | ||
|
||
Personally, I have found that ``CentOS 7`` and older, as well as simmilar versions of ``RHEL`` and ``Fedora`` have all had the same issue. | ||
|
||
The same may be true for other distributions, but I have found that ``Debian`` and ``Ubuntu`` have not had this issue. | ||
|
||
If you are using a host that has this issue, you will need to use the ``sudo`` command to switch users. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en" data-content_root="./"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<title>How To Contribute — Fabric-Plus 0.1 documentation</title> | ||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=d1102ebc" /> | ||
<link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=12dfc556" /> | ||
<script src="_static/documentation_options.js?v=2709fde1"></script> | ||
<script src="_static/doctools.js?v=9a2dae69"></script> | ||
<script src="_static/sphinx_highlight.js?v=dc90522c"></script> | ||
<link rel="canonical" href="https://fabricplus.prokopto.dev/contributing.html" /> | ||
<link rel="index" title="Index" href="genindex.html" /> | ||
<link rel="search" title="Search" href="search.html" /> | ||
<link rel="next" title="paramiko_modifications.client" href="api/client.html" /> | ||
<link rel="prev" title="Running Connections In Parallel" href="parallelism.html" /> | ||
|
||
<link rel="stylesheet" href="_static/custom.css" type="text/css" /> | ||
|
||
|
||
|
||
|
||
|
||
</head><body> | ||
|
||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
|
||
|
||
<div class="body" role="main"> | ||
|
||
<section id="how-to-contribute"> | ||
<h1>How To Contribute<a class="headerlink" href="#how-to-contribute" title="Link to this heading">¶</a></h1> | ||
<p>While we welcome contributions, we ask that you please follow the guidelines below:</p> | ||
</section> | ||
|
||
|
||
</div> | ||
|
||
</div> | ||
</div> | ||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
<p class="logo"><a href="index.html"> | ||
<img class="logo" src="_static/logo.png" alt="Logo"/> | ||
</a></p> | ||
<h1 class="logo"><a href="index.html">Fabric-Plus</a></h1> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="getting-started.html">Getting Started</a></li> | ||
</ul> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="parallelism.html">Running Connections In Parallel</a></li> | ||
</ul> | ||
<ul class="current"> | ||
<li class="toctree-l1 current"><a class="current reference internal" href="#">How To Contribute</a></li> | ||
</ul> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="api/client.html"><code class="docutils literal notranslate"><span class="pre">paramiko_modifications.client</span></code></a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="api/connection.html"><code class="docutils literal notranslate"><span class="pre">connection</span></code></a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="api/transfer.html"><code class="docutils literal notranslate"><span class="pre">transfer</span></code></a></li> | ||
</ul> | ||
|
||
<div class="relations"> | ||
<h3>Related Topics</h3> | ||
<ul> | ||
<li><a href="index.html">Documentation overview</a><ul> | ||
<li>Previous: <a href="parallelism.html" title="previous chapter">Running Connections In Parallel</a></li> | ||
<li>Next: <a href="api/client.html" title="next chapter"><code class="docutils literal notranslate"><span class="pre">paramiko_modifications.client</span></code></a></li> | ||
</ul></li> | ||
</ul> | ||
</div> | ||
<search 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" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> | ||
<input type="submit" value="Go" /> | ||
</form> | ||
</div> | ||
</search> | ||
<script>document.getElementById('searchbox').style.display = "block"</script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div> | ||
</div> | ||
<div class="clearer"></div> | ||
</div> | ||
<div class="footer"> | ||
©2024, Courtney Caldwell. | ||
|
||
| | ||
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 7.3.7</a> | ||
& <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a> | ||
|
||
| | ||
<a href="_sources/contributing.rst.txt" | ||
rel="nofollow">Page source</a> | ||
</div> | ||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.