Class: Server
- Inherits:
-
Screwcap::Base
- Object
- OpenStruct
- Screwcap::Base
- Server
- Defined in:
- lib/screwcap/server.rb
Instance Method Summary collapse
- #connect! ⇒ Object
-
#initialize(opts = {}) ⇒ Server
constructor
A server is the address(es) that you run a :task on.
- #upload!(local, remote) ⇒ Object
Methods inherited from Screwcap::Base
Constructor Details
#initialize(opts = {}) ⇒ Server
A server is the address(es) that you run a :task on.
server :myserver, :address => "abc.com", :password => "xxx"
server :app_servers, :addresses => ["abc.com","def.com"], :keys => "~/.ssh/my_key"
Options
-
A server must have a :user.
-
Specify :address or :addresses
-
A :gateway. See the section about gateways for more info.
-
All Other options will be passed directly to Net::SSH.
-
:keys can be used to specify the key to use to connect to the server
-
:password specify the password to connect with. Not recommended. Use keys.
-
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/screwcap/server.rb', line 14 def initialize(opts = {}) super self.__name = opts.delete(:name) self.__user = opts.delete(:user) self.[:keys] = [opts.delete(:key)] if opts[:key] servers = opts.delete(:servers) self.__gateway = servers.select {|s| s.[:is_gateway] == true }.find {|s| s.__name == opts[:gateway] } if servers self.__connections = [] self. = opts if self.[:address] and self.[:addresses].nil? self.__addresses = [self..delete(:address)] else self.__addresses = self.[:addresses] end validate self end |
Instance Method Details
#connect! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/screwcap/server.rb', line 37 def connect! self.__addresses.each do |address| # do not re-connect. return if we have already been connected next if self.__connections.any? {|conn| conn[:address] == address } begin if self.__gateway self.__connections << {:address => address, :connection => __gateway.__get_gateway_connection.ssh(address, self.__user, ) } else self.__connections << {:address => address, :connection => Net::SSH.start(address, self.__user, ) } end rescue Net::SSH::AuthenticationFailed => e raise Net::SSH::AuthenticationFailed, "Authentication failed for server named #{self.name}. Please check your authentication credentials." end end self.__connections end |
#upload!(local, remote) ⇒ Object
56 57 58 59 60 |
# File 'lib/screwcap/server.rb', line 56 def upload! (local, remote) self.__connections.each do |conn| conn.scp.upload! local, remote end end |