Class: Fog::Compute::Server
- Defined in:
- lib/fog/compute/models/server.rb
Constant Summary collapse
- INITIAL_SSHABLE_TIMEOUT =
8
Instance Attribute Summary collapse
- #private_key ⇒ Object
- #private_key_path ⇒ Object
- #public_key ⇒ Object
- #public_key_path ⇒ Object
-
#ssh_ip_address ⇒ String
IP Address used for ssh/scp interactions with server.
- #ssh_options ⇒ Object
-
#ssh_port ⇒ Integer
Port used for ssh/scp interactions with server.
- #username ⇒ Object
Attributes inherited from Model
Instance Method Summary collapse
-
#ready? ⇒ Boolean
Is the server ready to receive connections?.
- #scp(local_path, remote_path, upload_options = {}) ⇒ Object (also: #scp_upload)
- #scp_download(remote_path, local_path, download_options = {}) ⇒ Object
- #ssh(commands, options = {}, &blk) ⇒ Object
- #sshable?(options = {}) ⇒ Boolean
Methods inherited from Model
#==, #cache, #create, #destroy, #initialize, #inspect, #reload, #save, #symbolize_keys, #to_json, #update, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #associations, #attribute, #attributes, #default_values, #has_many, #has_many_identities, #has_one, #has_one_identity, #identity, #ignore_attributes, #ignored_attributes, #masks
Methods included from Fog::Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #all_associations, #all_associations_and_attributes, #all_attributes, #associations, #attributes, #dup, #filter_attributes, #identity, #identity=, #identity_name, #masks, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Attribute Details
#private_key ⇒ Object
30 31 32 |
# File 'lib/fog/compute/models/server.rb', line 30 def private_key @private_key ||= private_key_path && File.read(private_key_path) end |
#private_key_path ⇒ Object
25 26 27 28 |
# File 'lib/fog/compute/models/server.rb', line 25 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.(@private_key_path) end |
#public_key ⇒ Object
39 40 41 |
# File 'lib/fog/compute/models/server.rb', line 39 def public_key @public_key ||= public_key_path && File.read(public_key_path) end |
#public_key_path ⇒ Object
34 35 36 37 |
# File 'lib/fog/compute/models/server.rb', line 34 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.(@public_key_path) end |
#ssh_ip_address ⇒ String
By default this returns the public_ip_address
IP Address used for ssh/scp interactions with server.
53 54 55 56 57 58 |
# File 'lib/fog/compute/models/server.rb', line 53 def ssh_ip_address return public_ip_address unless @ssh_ip_address return @ssh_ip_address.call(self) if @ssh_ip_address.is_a?(Proc) @ssh_ip_address end |
#ssh_options ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/fog/compute/models/server.rb', line 60 def @ssh_options ||= {} = @ssh_options.merge(port: ssh_port) if private_key [:key_data] = [private_key] [:auth_methods] = %w(publickey) end end |
#ssh_port ⇒ Integer
By default this returns 22
Port used for ssh/scp interactions with server.
46 47 48 |
# File 'lib/fog/compute/models/server.rb', line 46 def ssh_port @ssh_port ||= 22 end |
#username ⇒ Object
21 22 23 |
# File 'lib/fog/compute/models/server.rb', line 21 def username @username ||= "root" end |
Instance Method Details
#ready? ⇒ Boolean
Is the server ready to receive connections?
Returns false by default.
Subclasses should implement #ready? appropriately.
114 115 116 |
# File 'lib/fog/compute/models/server.rb', line 114 def ready? false end |
#scp(local_path, remote_path, upload_options = {}) ⇒ Object Also known as: scp_upload
70 71 72 73 74 |
# File 'lib/fog/compute/models/server.rb', line 70 def scp(local_path, remote_path, = {}) requires :ssh_ip_address, :username Fog::SCP.new(ssh_ip_address, username, ).upload(local_path, remote_path, ) end |
#scp_download(remote_path, local_path, download_options = {}) ⇒ Object
78 79 80 81 82 |
# File 'lib/fog/compute/models/server.rb', line 78 def scp_download(remote_path, local_path, = {}) requires :ssh_ip_address, :username Fog::SCP.new(ssh_ip_address, username, ).download(remote_path, local_path, ) end |
#ssh(commands, options = {}, &blk) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/fog/compute/models/server.rb', line 84 def ssh(commands, = {}, &blk) requires :ssh_ip_address, :username = .merge() Fog::SSH.new(ssh_ip_address, username, ).run(commands, &blk) end |
#sshable?(options = {}) ⇒ Boolean
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fog/compute/models/server.rb', line 92 def sshable?( = {}) return false unless ready? && ssh_ip_address Timeout.timeout(sshable_timeout) { ssh("pwd", ) } @sshable_timeout = nil true rescue SystemCallError false rescue Net::SSH::AuthenticationFailed, Net::SSH::Disconnect @sshable_timeout = nil false rescue Timeout::Error increase_sshable_timeout false end |