Class: Fog::Compute::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Server
show all
- Defined in:
- lib/fog/compute/models/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Model
#==, #initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #associations, #attribute, #attributes, #default_values, #has_many, #has_many_identities, #has_one, #has_one_identity, #identity, #ignore_attributes, #ignored_attributes, #masks
#connection, #connection=, #prepare_service_value
#_dump, #all_associations, #all_associations_and_attributes, #all_attributes, #associations, #attributes, #dup, #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
28
29
30
|
# File 'lib/fog/compute/models/server.rb', line 28
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
23
24
25
26
|
# File 'lib/fog/compute/models/server.rb', line 23
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
|
#public_key ⇒ Object
37
38
39
|
# File 'lib/fog/compute/models/server.rb', line 37
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
32
33
34
35
|
# File 'lib/fog/compute/models/server.rb', line 32
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#ssh_ip_address ⇒ String
Note:
By default this returns the public_ip_address
IP Address used for ssh/scp interactions with server.
51
52
53
54
55
|
# File 'lib/fog/compute/models/server.rb', line 51
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
57
58
59
60
61
62
63
64
65
|
# File 'lib/fog/compute/models/server.rb', line 57
def ssh_options
@ssh_options ||= {}
ssh_options = @ssh_options.merge(:port => ssh_port)
if private_key
ssh_options[:key_data] = [private_key]
ssh_options[:auth_methods] = %w(publickey)
end
ssh_options
end
|
#ssh_port ⇒ Integer
Note:
By default this returns 22
Port used for ssh/scp interactions with server.
44
45
46
|
# File 'lib/fog/compute/models/server.rb', line 44
def ssh_port
@ssh_port ||= 22
end
|
#username ⇒ Object
19
20
21
|
# File 'lib/fog/compute/models/server.rb', line 19
def username
@username ||= "root"
end
|
Instance Method Details
#scp(local_path, remote_path, upload_options = {}) ⇒ Object
Also known as:
scp_upload
67
68
69
70
71
|
# File 'lib/fog/compute/models/server.rb', line 67
def scp(local_path, remote_path, upload_options = {})
requires :ssh_ip_address, :username
Fog::SCP.new(ssh_ip_address, username, ssh_options).upload(local_path, remote_path, upload_options)
end
|
#scp_download(remote_path, local_path, download_options = {}) ⇒ Object
75
76
77
78
79
|
# File 'lib/fog/compute/models/server.rb', line 75
def scp_download(remote_path, local_path, download_options = {})
requires :ssh_ip_address, :username
Fog::SCP.new(ssh_ip_address, username, ssh_options).download(remote_path, local_path, download_options)
end
|
#ssh(commands, options = {}, &blk) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/fog/compute/models/server.rb', line 81
def ssh(commands, options = {}, &blk)
requires :ssh_ip_address, :username
options = ssh_options.merge(options)
Fog::SSH.new(ssh_ip_address, username, options).run(commands, &blk)
end
|
#sshable?(options = {}) ⇒ Boolean
89
90
91
92
93
|
# File 'lib/fog/compute/models/server.rb', line 89
def sshable?(options = {})
ready? && !ssh_ip_address.nil? && !!Timeout.timeout(8) { ssh("pwd", options) }
rescue SystemCallError, Net::SSH::AuthenticationFailed, Net::SSH::Disconnect, Timeout::Error
false
end
|