diff options
Diffstat (limited to 'classes/Net/SSH/Multi/Server.html')
-rw-r--r-- | classes/Net/SSH/Multi/Server.html | 438 |
1 files changed, 438 insertions, 0 deletions
diff --git a/classes/Net/SSH/Multi/Server.html b/classes/Net/SSH/Multi/Server.html new file mode 100644 index 0000000..17be26b --- /dev/null +++ b/classes/Net/SSH/Multi/Server.html @@ -0,0 +1,438 @@ +<!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::Server [Control multiple Net::SSH connections via a single interface.]</title> + <meta content='text/html; charset=utf-8' http-equiv='Content-Type'> + <link href='../../../../rdoc-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'>Class</span> + Net::SSH::Multi::Server + </h1> + <ol class='paths'> + <li> + <a href="../../../../files/lib/net/ssh/multi/server_rb.html">lib/net/ssh/multi/server.rb</a> + </li> + </ol> + <div class='parent'> + Parent: + <strong>Object</strong> + </div> + </div> + <div id='content'> + <div id='text'> + <div id='description'> + <p> + Encapsulates the connection information for a single remote server, as well + as the <a href="../../SSH.html">Net::SSH</a> session corresponding to that + information. You’ll rarely need to instantiate one of these directly: + instead, you should use <a + href="Session.html#M000069">Net::SSH::Multi::Session#use</a>. + </p> + </div> + <div id='method-list'> + <h2>Methods</h2> + <h3>public class</h3> + <ol> + <li><a href="#M000046">new</a></li> + </ol> + <h3>public instance</h3> + <ol> + <li><a href="#M000050"><=></a></li> + <li><a href="#M000047">[]</a></li> + <li><a href="#M000048">[]=</a></li> + <li><a href="#M000057">busy?</a></li> + <li><a href="#M000058">close</a></li> + <li><a href="#M000055">fail!</a></li> + <li><a href="#M000054">failed?</a></li> + <li><a href="#M000051">hash</a></li> + <li><a href="#M000053">inspect</a></li> + <li><a href="#M000049">port</a></li> + <li><a href="#M000056">session</a></li> + <li><a href="#M000052">to_s</a></li> + </ol> + </div> + <div id='context'> + <div id='includes'> + <h2>Included modules</h2> + <ol> + <li>Comparable</li> + </ol> + </div> + </div> + <div id='section'> + <div id='aliases-list'> + <h2>External Aliases</h2> + <div class='name-list'> + <table summary='External aliases'> + <tr class='top-aligned-row context-row'> + <td class='context-item-name'>==</td> + <td>-></td> + <td class='context-item-value'>eql?</td> + </tr> + </table> + </div> + </div> + <div id='attribute-list'> + <h2 class='section-bar'>Attributes</h2> + <div class='name-list'> + <table> + <tr class='top-aligned-row context-row'> + <td class='context-item-name'>gateway</td> + <td class='context-item-value'>[R]</td> + <td class='context-item-desc'> + + The Net::SSH::Gateway instance to use to establish the connection. Will be + <tt>nil</tt> if the connection should be established without a gateway. + </td> + </tr> + <tr class='top-aligned-row context-row'> + <td class='context-item-name'>host</td> + <td class='context-item-value'>[R]</td> + <td class='context-item-desc'> + + The host name (or IP address) of the server to connect to. + </td> + </tr> + <tr class='top-aligned-row context-row'> + <td class='context-item-name'>master</td> + <td class='context-item-value'>[R]</td> + <td class='context-item-desc'> + + The <a href="Session.html">Net::SSH::Multi::Session</a> instance that + manages this server instance. + </td> + </tr> + <tr class='top-aligned-row context-row'> + <td class='context-item-name'>options</td> + <td class='context-item-value'>[R]</td> + <td class='context-item-desc'> + + The Hash of additional options to pass to <a + href="../../SSH.html">Net::SSH</a> when connecting (including things like + :password, and so forth). + </td> + </tr> + <tr class='top-aligned-row context-row'> + <td class='context-item-name'>user</td> + <td class='context-item-value'>[R]</td> + <td class='context-item-desc'> + + The user name to use when logging into the server. + </td> + </tr> + </table> + </div> + </div> + <div id='methods'> + <h2>Public class methods</h2> + <div class='method public-class' id='method-M000046'> + <a name='M000046'> </a> + <div class='synopsis'> + <span class='name'>new</span> + <span class='arguments'>(master, host, options={})</span> + </div> + <div class='description'> + <p> + Creates a new <a href="Server.html">Server</a> instance with the given + connection information. The <tt>master</tt> argument must be a reference to + the <a href="Session.html">Net::SSH::Multi::Session</a> instance that will + manage this server reference. The <tt>options</tt> hash must conform to the + options described for Net::SSH::start, with two additions: + </p> + <ul> + <li>:via => a Net::SSH::Gateway instance to use when establishing a connection + to this server. + + </li> + <li>:user => the name of the user to use when logging into this server. + + </li> + </ul> + <p> + The <tt>host</tt> argument may include the username and port number, in + which case those values take precedence over similar values given in the + <tt>options</tt>: + </p> + <pre>server = Net::SSH::Multi::Server.new(session, 'user@host:1234')
puts server.user #-> user
puts server.port #-> 1234</pre> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000046-source'); return false"> + [show source] + </a> + <pre id='M000046-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 43</span>
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">master</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">options</span>={})
44: <span class="ruby-ivar">@master</span> = <span class="ruby-identifier">master</span>
45: <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">dup</span>
46: 
47: <span class="ruby-ivar">@user</span>, <span class="ruby-ivar">@host</span>, <span class="ruby-identifier">port</span> = <span class="ruby-identifier">host</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/^(?:([^;,:=]+)@|)(.*?)(?::(\d+)|)$/</span>)[<span class="ruby-value">1</span>,<span class="ruby-value">3</span>]
48: 
49: <span class="ruby-identifier">user_opt</span>, <span class="ruby-identifier">port_opt</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:user</span>), <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:port</span>)
50: 
51: <span class="ruby-ivar">@user</span> = <span class="ruby-ivar">@user</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">user_opt</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">master</span>.<span class="ruby-identifier">default_user</span>
52: <span class="ruby-identifier">port</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">port_opt</span>
53: 
54: <span class="ruby-ivar">@options</span>[<span class="ruby-identifier">:port</span>] = <span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">port</span>
55: 
56: <span class="ruby-ivar">@gateway</span> = <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:via</span>)
57: <span class="ruby-ivar">@failed</span> = <span class="ruby-keyword kw">false</span>
58: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <h2>Public instance methods</h2> + <div class='method public-instance' id='method-M000050'> + <a name='M000050'> </a> + <div class='synopsis'> + <span class='name'><=></span> + <span class='arguments'>(server)</span> + </div> + <div class='description'> + <p> + Gives server definitions a sort order, and allows comparison. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000050-source'); return false"> + [show source] + </a> + <pre id='M000050-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 79</span>
79: <span class="ruby-keyword kw">def</span> <span class="ruby-operator"><=></span>(<span class="ruby-identifier">server</span>)
80: [<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">user</span>] <span class="ruby-operator"><=></span> [<span class="ruby-identifier">server</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">server</span>.<span class="ruby-identifier">port</span>, <span class="ruby-identifier">server</span>.<span class="ruby-identifier">user</span>]
81: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000047'> + <a name='M000047'> </a> + <div class='synopsis'> + <span class='name'>[]</span> + <span class='arguments'>(key)</span> + </div> + <div class='description'> + <p> + Returns the value of the server property with the given <tt>key</tt>. <a + href="Server.html">Server</a> properties are described via the + <tt>:properties</tt> key in the options hash when defining the <a + href="Server.html">Server</a>. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000047-source'); return false"> + [show source] + </a> + <pre id='M000047-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 63</span>
63: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">key</span>)
64: (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:properties</span>] <span class="ruby-operator">||</span> {})[<span class="ruby-identifier">key</span>]
65: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000048'> + <a name='M000048'> </a> + <div class='synopsis'> + <span class='name'>[]=</span> + <span class='arguments'>(key, value)</span> + </div> + <div class='description'> + <p> + Sets the given key/value pair in the <tt>:properties</tt> key in the + options hash. If the options hash has no :properties key, it will be + created. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000048-source'); return false"> + [show source] + </a> + <pre id='M000048-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 69</span>
69: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
70: (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:properties</span>] <span class="ruby-operator">||=</span> {})[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
71: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000057'> + <a name='M000057'> </a> + <div class='synopsis'> + <span class='name'>busy?</span> + <span class='arguments'>(include_invisible=false)</span> + </div> + <div class='description'> + <p> + Returns <tt>true</tt> if the session has been opened, and the session is + currently busy (as defined by Net::SSH::Connection::Session#busy?). + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000057-source'); return false"> + [show source] + </a> + <pre id='M000057-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 143</span>
143: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">busy?</span>(<span class="ruby-identifier">include_invisible</span>=<span class="ruby-keyword kw">false</span>)
144: <span class="ruby-identifier">session</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">session</span>.<span class="ruby-identifier">busy?</span>(<span class="ruby-identifier">include_invisible</span>)
145: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000058'> + <a name='M000058'> </a> + <div class='synopsis'> + <span class='name'>close</span> + <span class='arguments'>()</span> + </div> + <div class='description'> + <p> + Closes this server’s session. If the session has not yet been opened, + this does nothing. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000058-source'); return false"> + [show source] + </a> + <pre id='M000058-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 149</span>
149: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
150: <span class="ruby-identifier">session</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">session</span>
151: <span class="ruby-keyword kw">ensure</span>
152: <span class="ruby-identifier">master</span>.<span class="ruby-identifier">server_closed</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">session</span>
153: <span class="ruby-ivar">@session</span> = <span class="ruby-keyword kw">nil</span>
154: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000055'> + <a name='M000055'> </a> + <div class='synopsis'> + <span class='name'>fail!</span> + <span class='arguments'>(flag=true)</span> + </div> + <div class='description'> + <p> + Indicates (by default) that this server has just failed a connection + attempt. If <tt>flag</tt> is false, this can be used to reset the failed + flag so that a retry may be attempted. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000055-source'); return false"> + [show source] + </a> + <pre id='M000055-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 115</span>
115: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fail!</span>(<span class="ruby-identifier">flag</span>=<span class="ruby-keyword kw">true</span>)
116: <span class="ruby-ivar">@failed</span> = <span class="ruby-identifier">flag</span>
117: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000054'> + <a name='M000054'> </a> + <div class='synopsis'> + <span class='name'>failed?</span> + <span class='arguments'>()</span> + </div> + <div class='description'> + <p> + Returns <tt>true</tt> if this server has ever failed a connection attempt. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000054-source'); return false"> + [show source] + </a> + <pre id='M000054-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 108</span>
108: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">failed?</span>
109: <span class="ruby-ivar">@failed</span>
110: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000051'> + <a name='M000051'> </a> + <div class='synopsis'> + <span class='name'>hash</span> + <span class='arguments'>()</span> + </div> + <div class='description'> + <p> + Generates a <tt>Fixnum</tt> hash value for this object. This function has + the property that +a.eql?(b)+ implies +a.hash == b.hash+. The hash value is + used by class <tt>Hash</tt>. Any hash value that exceeds the capacity of a + <tt>Fixnum</tt> will be truncated before being used. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000051-source'); return false"> + [show source] + </a> + <pre id='M000051-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 89</span>
89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hash</span>
90: <span class="ruby-ivar">@hash</span> <span class="ruby-operator">||=</span> [<span class="ruby-identifier">host</span>, <span class="ruby-identifier">user</span>, <span class="ruby-identifier">port</span>].<span class="ruby-identifier">hash</span>
91: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000053'> + <a name='M000053'> </a> + <div class='synopsis'> + <span class='name'>inspect</span> + <span class='arguments'>()</span> + </div> + <div class='description'> + <p> + Returns a human-readable representation of this server instance. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000053-source'); return false"> + [show source] + </a> + <pre id='M000053-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 103</span>
103: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>
104: <span class="ruby-ivar">@inspect</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">"#<%s:0x%x %s>"</span> <span class="ruby-operator">%</span> [<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">object_id</span>, <span class="ruby-identifier">to_s</span>]
105: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000049'> + <a name='M000049'> </a> + <div class='synopsis'> + <span class='name'>port</span> + <span class='arguments'>()</span> + </div> + <div class='description'> + <p> + Returns the port number to use for this connection. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000049-source'); return false"> + [show source] + </a> + <pre id='M000049-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 74</span>
74: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">port</span>
75: <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:port</span>] <span class="ruby-operator">||</span> <span class="ruby-value">22</span>
76: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000056'> + <a name='M000056'> </a> + <div class='synopsis'> + <span class='name'>session</span> + <span class='arguments'>(require_session=false)</span> + </div> + <div class='description'> + <p> + Returns the <a href="../../SSH.html">Net::SSH</a> session object for this + server. If <tt>require_session</tt> is false and the session has not + previously been created, this will return <tt>nil</tt>. If + <tt>require_session</tt> is true, the session will be instantiated if it + has not already been instantiated, via the <tt>gateway</tt> if one is + given, or directly (via Net::SSH::start) otherwise. + </p> + <pre>if server.session.nil?
 puts "connecting..."
 server.session(true)
end</pre> + <p> + Note that the sessions returned by this are “enhanced” + slightly, to make them easier to deal with in a multi-session environment: + they have a :server property automatically set on them, that refers to this + object (the <a href="Server.html">Server</a> instance that spawned them). + </p> + <pre>assert_equal server, server.session[:server]</pre> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000056-source'); return false"> + [show source] + </a> + <pre id='M000056-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 136</span>
136: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">session</span>(<span class="ruby-identifier">require_session</span>=<span class="ruby-keyword kw">false</span>)
137: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@session</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@session</span> <span class="ruby-operator">||</span> <span class="ruby-operator">!</span><span class="ruby-identifier">require_session</span>
138: <span class="ruby-ivar">@session</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">master</span>.<span class="ruby-identifier">next_session</span>(<span class="ruby-keyword kw">self</span>)
139: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + <div class='method public-instance' id='method-M000052'> + <a name='M000052'> </a> + <div class='synopsis'> + <span class='name'>to_s</span> + <span class='arguments'>()</span> + </div> + <div class='description'> + <p> + Returns a human-readable representation of this server instance. + </p> + </div> + <div class='source'> + <a class='source-toggle' href='#' onclick="toggleCode('M000052-source'); return false"> + [show source] + </a> + <pre id='M000052-source'> <span class="ruby-comment cmt"># File lib/net/ssh/multi/server.rb, line 94</span>
 94: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
 95: <span class="ruby-ivar">@to_s</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">begin</span>
 96: <span class="ruby-identifier">s</span> = <span class="ruby-node">"#{user}@#{host}"</span>
 97: <span class="ruby-identifier">s</span> <span class="ruby-operator"><<</span> <span class="ruby-node">":#{options[:port]}"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:port</span>]
 98: <span class="ruby-identifier">s</span>
 99: <span class="ruby-keyword kw">end</span>
100: <span class="ruby-keyword kw">end</span></pre> + </div> + </div> + </div> + </div> + </div> + </div> + <div id='footer-push'></div> + </div> + <div id='footer'> + <a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a> + </div> + </body> +</html> |