You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The connector can also be run using <codeclass="docutils literal notranslate"><spanclass="pre">pyinfra</span><spanclass="pre">@[name</span><spanclass="pre">of</span><spanclass="pre">connector</span><spanclass="pre">in</span><spanclass="pre">pyinfra.connectors]/[hostname]</span><spanclass="pre">[deployment</span><spanclass="pre">script].py</span></code>. If executed this way
179
180
(inventory/data requested for a single host), <codeclass="docutils literal notranslate"><spanclass="pre">make_names_data(_=None)</span></code> should be updated to <codeclass="docutils literal notranslate"><spanclass="pre">make_names_data(name)</span></code> and the <codeclass="docutils literal notranslate"><spanclass="pre">name</span><spanclass="pre">==</span><spanclass="pre">None</span></code> case
180
181
handled in code separately from <codeclass="docutils literal notranslate"><spanclass="pre">name</span></code> being a valid string.</p>
181
-
<p>Its worth being aware up front that due to <codeclass="docutils literal notranslate"><spanclass="pre">make_names_data</span></code> being a <codeclass="docutils literal notranslate"><spanclass="pre">staticmethod</span></code> it has no automatic access to the parent classes attributes.
182
-
To work around this - eg to configure an API connector - configuration will have to happen outside the function and be imported in. Two examples
183
-
(<codeclass="docutils literal notranslate"><spanclass="pre">getattr</span></code> and a function) are provided below.</p>
<h2>Where to make changes<aclass="headerlink" href="#where-to-make-changes" title="Link to this heading">¶</a></h2>
254
+
<p>Connectors enable pyinfra to expand work done <codeclass="docutils literal notranslate"><spanclass="pre">in</span><spanclass="pre">its</span><spanclass="pre">5</span><spanclass="pre">stages</span><spanclass="pre"><deploy-process.html#how-pyinfra-works></span></code>_ by providing methods which can be called at
255
+
appropriate times.</p>
256
+
<p>To hook in to to the various steps with the methods outlined below.</p>
<p><codeclass="docutils literal notranslate"><spanclass="pre">make_names_data</span></code> is used to supply inventory data about a host while at ‘Loading inventory’ stage.</p>
262
+
<p>Its worth being aware up front that due to <codeclass="docutils literal notranslate"><spanclass="pre">make_names_data</span></code> being a <codeclass="docutils literal notranslate"><spanclass="pre">staticmethod</span></code> it has no automatic access to the parent classes attributes.
263
+
To work around this - eg to configure an API connector - configuration will have to happen outside the function and be imported in. Two examples
264
+
(<codeclass="docutils literal notranslate"><spanclass="pre">getattr</span></code> and a function) are provided below.</p>
<p><codeclass="docutils literal notranslate"><spanclass="pre">connect</span></code> can be used to check access to a host is possible. If the connection fails <codeclass="docutils literal notranslate"><spanclass="pre">ConnectError</span></code> should be raised with a message to display on
<p><codeclass="docutils literal notranslate"><spanclass="pre">run_shell_command</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">put_file</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">get_file</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">rsync</span></code> can be used to change behaviour of pyinfra as it performs operations.</p>
<p><codeclass="docutils literal notranslate"><spanclass="pre">disconnect</span></code> can be used after all operations complete to clean up any connection/s remaining to the hosts being managed.</p>
307
+
</section>
270
308
<sectionid="pyproject-toml">
271
309
<h2>pyproject.toml<aclass="headerlink" href="#pyproject-toml" title="Link to this heading">¶</a></h2>
272
310
<p>In order for pyinfra to gain knowledge about your connector, you need to add the following snippet to your connector’s <codeclass="docutils literal notranslate"><spanclass="pre">pyproject.toml</span></code>:</p>
0 commit comments