Class: Fog::Compute::Server
- Defined in:
- lib/fog/compute/models/server.rb
Direct Known Subclasses
AWS::Server, AWS::SpotRequest, Bluebox::Server, Brightbox::Server, Clodo::Server, Cloudstack::Server, DigitalOcean::Server, Glesys::Server, GoGrid::Server, Google::Server, HP::Server, HPV2::Server, IBM::Server, Joyent::Server, Libvirt::Server, Linode::Server, Ninefold::Server, OpenStack::Server, Openvz::Server, Ovirt::Server, Rackspace::Server, RackspaceV2::Server, Fog::Compute::StormOnDemand::Server, Vmfusion::Server, Voxel::Server, Vsphere::Server, XenServer::Server, Server
Instance Attribute Summary collapse
- #private_key ⇒ Object
- #private_key_path ⇒ Object
- #public_key ⇒ Object
- #public_key_path ⇒ Object
- #ssh_options ⇒ Object
-
#ssh_port ⇒ Integer
Port used for ssh/scp interactions with server.
- #username ⇒ Object
Attributes inherited from Model
Instance Method Summary collapse
- #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
-
#ssh_ip_address ⇒ String
IP Address used for ssh/scp interactions with server.
-
#ssh_ip_address=(proc) ⇒ Object
Sets the proc used to determine the IP Address used for ssh/scp interactions.
- #sshable?(options = {}) ⇒ Boolean
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Fog::Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Attribute Details
#private_key ⇒ Object
18 19 20 |
# File 'lib/fog/compute/models/server.rb', line 18 def private_key @private_key ||= private_key_path && File.read(private_key_path) end |
#private_key_path ⇒ Object
13 14 15 16 |
# File 'lib/fog/compute/models/server.rb', line 13 def private_key_path @private_key_path ||= Fog.credentials[:private_key_path] @private_key_path &&= File.(@private_key_path) end |
#public_key ⇒ Object
27 28 29 |
# File 'lib/fog/compute/models/server.rb', line 27 def public_key @public_key ||= public_key_path && File.read(public_key_path) end |
#public_key_path ⇒ Object
22 23 24 25 |
# File 'lib/fog/compute/models/server.rb', line 22 def public_key_path @public_key_path ||= Fog.credentials[:public_key_path] @public_key_path &&= File.(@public_key_path) end |
#ssh_options ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/compute/models/server.rb', line 61 def @ssh_options ||= {} = @ssh_options.merge({:port => ssh_port}) if private_key [:key_data] = [private_key] [:auth_methods] = ["publickey"] end end |
#ssh_port ⇒ Integer
By default this returns 22
Port used for ssh/scp interactions with server.
34 35 36 |
# File 'lib/fog/compute/models/server.rb', line 34 def ssh_port @ssh_port ||= 22 end |
#username ⇒ Object
9 10 11 |
# File 'lib/fog/compute/models/server.rb', line 9 def username @username ||= 'root' end |
Instance Method Details
#scp(local_path, remote_path, upload_options = {}) ⇒ Object Also known as: scp_upload
71 72 73 74 75 76 |
# File 'lib/fog/compute/models/server.rb', line 71 def scp(local_path, remote_path, = {}) require 'net/scp' 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
80 81 82 83 84 85 |
# File 'lib/fog/compute/models/server.rb', line 80 def scp_download(remote_path, local_path, = {}) require 'net/scp' requires :ssh_ip_address, :username Fog::SCP.new(ssh_ip_address, username, ).download(remote_path, local_path, ) end |
#ssh(commands, options = {}, &blk) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/fog/compute/models/server.rb', line 87 def ssh(commands, ={}, &blk) require 'net/ssh' requires :ssh_ip_address, :username = .merge() Fog::SSH.new(ssh_ip_address, username, ).run(commands, &blk) end |
#ssh_ip_address ⇒ String
By default this returns the public_ip_address
IP Address used for ssh/scp interactions with server.
55 56 57 58 59 |
# File 'lib/fog/compute/models/server.rb', line 55 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_ip_address=(proc) ⇒ Object
By default scp/ssh will use the public_ip_address if this proc is not set.
Sets the proc used to determine the IP Address used for ssh/scp interactions.
48 49 50 |
# File 'lib/fog/compute/models/server.rb', line 48 def ssh_ip_address=(proc) @ssh_ip_address = proc end |
#sshable?(options = {}) ⇒ Boolean
96 97 98 99 100 |
# File 'lib/fog/compute/models/server.rb', line 96 def sshable?(={}) ready? && !ssh_ip_address.nil? && !!Timeout::timeout(8) { ssh('pwd', ) } rescue SystemCallError, Net::SSH::AuthenticationFailed, Net::SSH::Disconnect, Timeout::Error false end |