Class: SimpleProvision::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_provision/server.rb

Constant Summary collapse

ServerNotFound =
Class.new(StandardError)
MissingDropletName =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, options) ⇒ Server

Returns a new instance of Server.



10
11
12
# File 'lib/simple_provision/server.rb', line 10

def initialize(connection, options)
  @connection, @options = connection, options
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



8
9
10
# File 'lib/simple_provision/server.rb', line 8

def server
  @server
end

Instance Method Details

#configureObject

Raises:



14
15
16
17
18
19
20
21
22
23
# File 'lib/simple_provision/server.rb', line 14

def configure
  get(options[:droplet_name]) if server.nil?
  raise ServerNotFound, "Unable to find server with Droplet name #{options[:droplet_name]}." if server.nil?

  SimpleProvision::SCP.new(server, options).to_server
  scripts = options.fetch(:scripts).map do |script|
    "#{environment_exports} bash -c '#{script}'"
  end
  server.ssh(scripts)
end

#environment_exportsObject



25
26
27
28
29
30
31
32
33
# File 'lib/simple_provision/server.rb', line 25

def environment_exports
  @environment_exports ||= begin
                             if options[:env].nil?
                               ""
                             else
                               options[:env].map { |k, v| [k, Shellwords.escape(v)].join("=") }.join(" ")
                             end
                           end
end