summaryrefslogtreecommitdiff
path: root/classes/Net/SSH/Multi.html
blob: 0e968089ada4ce21f6935f1975162541216f581a (plain)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
  <head>
    <title>Net::SSH::Multi</title>
    <meta content='text/html; charset=US-ASCII' http-equiv='Content-Type'>
    <link href='../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
    <script type='text/javascript'>
      //<![CDATA[
        function popupCode(url) {
          window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
        }
        
        function toggleCode(id) {
          var code = document.getElementById(id)
        
          code.style.display = code.style.display != 'block' ? 'block' : 'none'
          return true
        }
        
        // Make codeblocks hidden by default
        document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
      //]]>
    </script>
  </head>
  <body class='page'>
    <div class='class' id='wrapper'>
      <div class='header'>
        <h1 class='name'>
          <span class='type'>module</span>
          Net::SSH::Multi
        </h1>
        <ol class='paths'>
          <li>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/channel_rb.html">lib/net/ssh/multi/channel.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/channel_proxy_rb.html">lib/net/ssh/multi/channel_proxy.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/dynamic_server_rb.html">lib/net/ssh/multi/dynamic_server.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/pending_connection_rb.html">lib/net/ssh/multi/pending_connection.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/server_rb.html">lib/net/ssh/multi/server.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/server_list_rb.html">lib/net/ssh/multi/server_list.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/session_rb.html">lib/net/ssh/multi/session.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/session_actions_rb.html">lib/net/ssh/multi/session_actions.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/subsession_rb.html">lib/net/ssh/multi/subsession.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi/version_rb.html">lib/net/ssh/multi/version.rb</a>
          </li>
          <li class='other'>
            <a target="docwin" href="../../../files/lib/net/ssh/multi_rb.html">lib/net/ssh/multi.rb</a>
          </li>
          <li>
            <a class='show' href='#' onclick='this.parentNode.parentNode.className += " expanded"; this.parentNode.removeChild(this); return false'>show all</a>
          </li>
        </ol>
        <div class='parent'>
          Parent:
          <strong><a target="docwin" href="../SSH.html">SSH</a></strong>
        </div>
      </div>
      <div id='content'>
        <div id='text'>
          <div id='description'>
            
            <p><a href="Multi.html">Net::SSH::Multi</a> is a library for controlling
            multiple <a href="../SSH.html">Net::SSH</a> connections via a single
            interface. It exposes an API similar to that of
            Net::SSH::Connection::Session and Net::SSH::Connection::Channel, making it
            simpler to adapt programs designed for single connections to be used with
            multiple connections.</p>
            
            <p>This library is particularly useful for automating repetitive tasks that
            must be performed on multiple machines. It executes the commands in
            parallel, and allows commands to be executed on subsets of servers (defined
            by groups).</p>
            
            <pre>require 'net/ssh/multi'&#x000A;Net::SSH::Multi.start do |session|&#x000A;  # access servers via a gateway&#x000A;  session.via 'gateway', 'gateway-user'&#x000A;&#x000A;  # define the servers we want to use&#x000A;  session.use 'user1@host1'&#x000A;  session.use 'user2@host2'&#x000A;&#x000A;  # define servers in groups for more granular access&#x000A;  session.group :app do&#x000A;    session.use 'user@app1'&#x000A;    session.use 'user@app2'&#x000A;  end&#x000A;&#x000A;  # execute commands on all servers&#x000A;  session.exec &quot;uptime&quot;&#x000A;&#x000A;  # execute commands on a subset of servers&#x000A;  session.with(:app).exec &quot;hostname&quot;&#x000A;&#x000A;  # run the aggregated event loop&#x000A;  session.loop&#x000A;end</pre>
            
            <p>See <a href="Multi/Session.html">Net::SSH::Multi::Session</a> for more
            documentation.</p>
          </div>
          <div id='method-list'>
            <h2>Methods</h2>
            <h3>Public Class</h3>
            <ol>
              <li><a target="docwin" href="#method-c-start">start</a></li>
            </ol>
          </div>
          <div id='context'>
          </div>
          <div id='class-list'>
            <h2>Classes and Modules</h2>
            <ol>
              <li><a target="docwin" href="Multi/SessionActions.html">Net::SSH::Multi::SessionActions</a></li>
              <li><a target="docwin" href="Multi/Channel.html">Net::SSH::Multi::Channel</a></li>
              <li><a target="docwin" href="Multi/ChannelProxy.html">Net::SSH::Multi::ChannelProxy</a></li>
              <li><a target="docwin" href="Multi/DynamicServer.html">Net::SSH::Multi::DynamicServer</a></li>
              <li><a target="docwin" href="Multi/PendingConnection.html">Net::SSH::Multi::PendingConnection</a></li>
              <li><a target="docwin" href="Multi/Server.html">Net::SSH::Multi::Server</a></li>
              <li><a target="docwin" href="Multi/ServerList.html">Net::SSH::Multi::ServerList</a></li>
              <li><a target="docwin" href="Multi/Session.html">Net::SSH::Multi::Session</a></li>
              <li><a target="docwin" href="Multi/Subsession.html">Net::SSH::Multi::Subsession</a></li>
              <li><a target="docwin" href="Multi/Version.html">Net::SSH::Multi::Version</a></li>
            </ol>
          </div>
          <div id='section'>
            <div id='methods'>
              <h2>Public Class methods</h2>
              <div class='method public-class' id='method-method-c-start'>
                <a name='method-c-start'></a>
                <div class='synopsis'>
                  <span class='name'>start</span>
                  <span class='arguments'>(options={})</span>
                </div>
                <div class='description'>
                  
                  <p>This is a convenience method for instantiating a new <a
                  href="Multi/Session.html">Net::SSH::Multi::Session</a>. If a block is
                  given, the session will be yielded to the block automatically closed (see
                  <a
                  href="Multi/Session.html#method-i-close">Net::SSH::Multi::Session#close</a>)
                  when the block finishes. Otherwise, the new session will be returned.</p>
                  
                  <pre>Net::SSH::Multi.start do |session|&#x000A;  # ...&#x000A;end&#x000A;session = Net::SSH::Multi.start&#x000A;# ...&#x000A;session.close</pre>
                  
                  <p>Any options are passed directly to <a
                  href="Multi/Session.html#method-c-new">Net::SSH::Multi::Session.new</a>
                  (q.v.).</p>
                </div>
                <div class='source'>
                  <a class='source-toggle' href='#' onclick="toggleCode('method-c-start-source'); return false">
                    [show source]
                  </a>
                  <pre id='method-c-start-source'><span class="ruby-comment"># File lib/net/ssh/multi.rb, line 57</span>&#x000A;<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">options</span>={})&#x000A;  <span class="ruby-identifier">session</span> = <span class="ruby-constant">Session</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>)&#x000A;&#x000A;  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>&#x000A;    <span class="ruby-keyword">begin</span>&#x000A;      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">session</span>&#x000A;      <span class="ruby-identifier">session</span>.<span class="ruby-identifier">loop</span>&#x000A;      <span class="ruby-identifier">session</span>.<span class="ruby-identifier">close</span>&#x000A;    <span class="ruby-keyword">end</span>&#x000A;  <span class="ruby-keyword">else</span>&#x000A;    <span class="ruby-keyword">return</span> <span class="ruby-identifier">session</span>&#x000A;  <span class="ruby-keyword">end</span>&#x000A;<span class="ruby-keyword">end</span></pre>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id='footer-push'></div>
    </div>
    <div id='footer'>
      <a target="docwin" href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
    </div>
  </body>
</html>