Class: FuckingShellScripts::Server

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

Constant Summary collapse

NoServerSelected =
Class.new(StandardError)
MissingInstanceID =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, options) ⇒ Server

Returns a new instance of Server.



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

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

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



6
7
8
# File 'lib/fucking_shell_scripts/server.rb', line 6

def server
  @server
end

Instance Method Details

#bootstrapObject



12
13
14
15
# File 'lib/fucking_shell_scripts/server.rb', line 12

def bootstrap
  build
  configure
end

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fucking_shell_scripts/server.rb', line 17

def build
  @server = connection.servers.create(
    image_id: options.fetch(:image),
    flavor_id: options.fetch(:size),
    key_name: options.fetch(:key_name),
    tags: { "Name" => name },
    groups: options.fetch(:security_groups),
    private_key_path: options.fetch(:private_key_path)
  )
  @server.username = options.fetch(:username) if options.fetch(:username)
  print "Creating #{options.fetch(:size)} from #{options.fetch(:image)}"

  server.wait_for do
    print "."
    ready?
  end

  puts "ready!"
  puts ""

  print "Waiting for ssh access"

  server.wait_for do
    print "."
    sshable?
  end

  puts "#{server.dns_name} ready!"
end

#configureObject

Raises:



47
48
49
50
51
52
53
# File 'lib/fucking_shell_scripts/server.rb', line 47

def configure
  get(options[:instance_id]) if server.nil?
  raise NoServerSelected, "Unable to find server. Try specifying the server ID." if server.nil?

  FuckingShellScripts::SCP.new(server, options).to_server
  server.ssh(options.fetch(:scripts))
end