Class: Hazetug::Haze::DigitalOcean

Inherits:
Hazetug::Haze show all
Includes:
CloudServer
Defined in:
lib/hazetug/haze/digital_ocean.rb

Constant Summary

Constants inherited from Hazetug::Haze

RE_BITS

Constants included from NetSSH::Mixin

NetSSH::Mixin::NET_SSH_OPTIONS

Instance Attribute Summary

Attributes inherited from Hazetug::Haze

#compute_name, #config

Instance Method Summary collapse

Methods included from CloudServer

#bits_from_string, #image_from_string, #lookup, #memory_in_megabytes, #provision_server, #server_args, #wait_for_ssh

Methods inherited from Hazetug::Haze

[], defaults, #provision, #ready?, requires, #update_access_settings

Methods included from UI::Mixin

included

Constructor Details

#initialize(config = {}) ⇒ DigitalOcean

Returns a new instance of DigitalOcean.



11
12
13
14
15
# File 'lib/hazetug/haze/digital_ocean.rb', line 11

def initialize(config={})
  super
  @config[:bits] = bits_from_string(@config[:image])
  @config[:image_slug] = image_from_string(@config[:image])
end

Instance Method Details

#compare_flavor?(o) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/hazetug/haze/digital_ocean.rb', line 36

def compare_flavor?(o)
  a = o.attributes
  value = config[:flavor]
  a[:memory] == memory_in_megabytes(value) ||
  a[:name].match(/^#{value}/i)
end

#compare_image?(o) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/hazetug/haze/digital_ocean.rb', line 43

def compare_image?(o)
  a = o.attributes
  img_id = image_from_string(a[:name])
  bits = bits_from_string(a[:name])
  img_id.match(/^#{config[:image_slug]}/) && bits == config[:bits]
end

#compare_location?(o) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/hazetug/haze/digital_ocean.rb', line 29

def compare_location?(o)
  a = o.attributes
  value = config[:location]
  a[:name].match(/^#{value}/i) != nil ||
  a['slug'] == config[:location] || a['slug'].match(/^#{value}/) != nil
end

#create_server_argsObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hazetug/haze/digital_ocean.rb', line 17

def create_server_args
  {
    :name => config[:name],
    :region_id => lookup(:location).id,
    :flavor_id => lookup(:flavor).id,
    :image_id  => lookup(:image).id,
    :ssh_key_ids => ssh_key_ids,
    :backups_active => config[:backups_active],
    :private_networking => config[:private_networking]
  }
end

#private_ip_addressObject



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

def private_ip_address
  server and server.private_ip_address
end

#public_ip_addressObject



50
51
52
# File 'lib/hazetug/haze/digital_ocean.rb', line 50

def public_ip_address
  server and server.public_ip_address
end