Class: Conjure::Server
- Inherits:
-
Struct
- Object
- Struct
- Conjure::Server
- Defined in:
- lib/conjure/server.rb
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
Class Method Summary collapse
- .create(name_prefix, options = {}) ⇒ Object
- .droplet_options(name_prefix, options = {}) ⇒ Object
- .key_data ⇒ Object
- .ssh_options ⇒ Object
Instance Method Summary collapse
- #quote_command(command) ⇒ Object
- #run(command) ⇒ Object
- #send_file(local_name, remote_name) ⇒ Object
Instance Attribute Details
#ip_address ⇒ Object
Returns the value of attribute ip_address
4 5 6 |
# File 'lib/conjure/server.rb', line 4 def ip_address @ip_address end |
Class Method Details
.create(name_prefix, options = {}) ⇒ Object
21 22 23 |
# File 'lib/conjure/server.rb', line 21 def self.create(name_prefix, = {}) new DigitalOcean::Droplet.new((name_prefix, )).ip_address end |
.droplet_options(name_prefix, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/conjure/server.rb', line 25 def self.(name_prefix, = {}) { image: "docker", key_data: key_data, name_prefix: name_prefix, region: "nyc3", size: ([:instance_size] || "512mb"), } end |
.key_data ⇒ Object
35 36 37 38 39 |
# File 'lib/conjure/server.rb', line 35 def self.key_data ssh_dir = File. "~/.ssh" raise "Error: ~/.ssh/id_rsa.pub must exist." unless File.exist?(ssh_dir) && File.exist?("#{ssh_dir}/id_rsa.pub") File.read "#{ssh_dir}/id_rsa.pub" end |
.ssh_options ⇒ Object
13 14 15 |
# File 'lib/conjure/server.rb', line 13 def self. "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR" end |
Instance Method Details
#quote_command(command) ⇒ Object
17 18 19 |
# File 'lib/conjure/server.rb', line 17 def quote_command(command) "'" + command.gsub("'", "'\"'\"'") + "'" end |
#run(command) ⇒ Object
5 6 7 |
# File 'lib/conjure/server.rb', line 5 def run(command) `ssh #{self.class.} root@#{ip_address} #{quote_command command}` end |
#send_file(local_name, remote_name) ⇒ Object
9 10 11 |
# File 'lib/conjure/server.rb', line 9 def send_file(local_name, remote_name) `scp #{self.class.} #{local_name} root@#{ip_address}:#{remote_name}` end |