Module: Hazetug::Haze::CloudServer

Included in:
DigitalOcean, Linode
Defined in:
lib/hazetug/haze/cloud_server.rb

Instance Method Summary collapse

Instance Method Details

#bits_from_string(string) ⇒ Object

Bits from string, when can’t be fetched default is 64



53
54
55
56
# File 'lib/hazetug/haze/cloud_server.rb', line 53

def bits_from_string(string)
  m = string.match(Haze::RE_BITS)
  m ? m.captures.compact.first.to_s.to_i : 64
end

#create_server_argsObject

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/hazetug/haze/cloud_server.rb', line 62

def create_server_args
  raise NotImplementedError, "#create_server_arguments not implemented"
end

#image_from_string(string) ⇒ Object



45
46
47
48
49
50
# File 'lib/hazetug/haze/cloud_server.rb', line 45

def image_from_string(string)
  string.downcase.sub(/\s*lts\s*/, '').
    sub(RE_BITS, '').
    sub(/\s+$/, '').
    gsub(/ /, '-')
end

#lookup(model, *args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hazetug/haze/cloud_server.rb', line 24

def lookup(model, *args)
  collection_method = model.to_s + 's'
  compare_method = "compare_#{model}?"
  found = compute.send(collection_method).select do |o|
    self.send(compare_method, o, *args)
  end
  if found.size > 1
    ui.error "More than one #{model} found for #{config[model]}"
  elsif found.empty?
    ui.fatal "#{model} not found for #{config[model]}"
    raise ArgumentError, "Wrong argument #{config[model]}"
  end
  found.first
end

#memory_in_megabytes(string) ⇒ Object



39
40
41
42
43
# File 'lib/hazetug/haze/cloud_server.rb', line 39

def memory_in_megabytes(string)
  mult = 1
  mult = 1024 if string.match(/gb$/i)
  string.to_i * mult
end

#provision_serverObject



5
6
7
8
9
10
# File 'lib/hazetug/haze/cloud_server.rb', line 5

def provision_server
  ui.info "[#{compute_name}] creating server #{config[:name]}"
  self.server = compute.servers.create(server_args)
  server.wait_for { ready? }
  ui.info "[#{compute_name}] server #{config[:name]} created, ip: #{server.ssh_ip_address}"
end

#server_argsObject



58
59
60
# File 'lib/hazetug/haze/cloud_server.rb', line 58

def server_args
  @server_args ||= create_server_args
end

#wait_for_sshObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hazetug/haze/cloud_server.rb', line 12

def wait_for_ssh
  server.username = config[:ssh_user] || 'root'
  server.ssh_port = config[:ssh_port]
  server.ssh_options = net_ssh_options

  ui.info "[#{compute_name}] waiting for active ssh on #{server.ssh_ip_address}"
  server.wait_for(30) { sshable? }
  @ready = true
rescue Fog::Errors::TimeoutError
  ui.error "[#{compute_name}] ssh failed to #{config[:name]}, ip: #{server.ssh_ip_address}"
end