Class: Kitchen::Driver::DigitalOcean
- Inherits:
-
SSHBase
- Object
- SSHBase
- Kitchen::Driver::DigitalOcean
- Defined in:
- lib/kitchen/driver/digital_ocean.rb
Overview
Digital Ocean driver for Kitchen.
Constant Summary collapse
- IMAGES =
{ "ubuntu-12.04" => "ubuntu-12-04-x64", "ubuntu-14.04" => "ubuntu-14-04-x64", }
Instance Method Summary collapse
Instance Method Details
#create(state) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/kitchen/driver/digital_ocean.rb', line 64 def create(state) droplet = create_droplet state[:server_id] = droplet['id'] info("Digital Ocean instance <#{state[:server_id]}> created.") while true sleep 10 droplet = get_droplet(state[:server_id]) break if droplet \ && droplet['networks'] \ && droplet['networks']['v4'] \ && droplet['networks']['v4'].any? { |n| n['type'] == 'public' } end state[:hostname] = droplet['networks']['v4'].detect { |n| n['type'] == 'public' }['ip_address'] wait_for_sshd(state[:hostname]) ; print "(ssh ready)\n" debug("digitalocean:create #{state[:hostname]}") rescue RestClient::Exception => e raise ActionFailed, e. end |
#default_image ⇒ Object
104 105 106 |
# File 'lib/kitchen/driver/digital_ocean.rb', line 104 def default_image IMAGES.fetch(instance.platform.name) { 'ubuntu-14-04-x64' } end |
#default_name ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/kitchen/driver/digital_ocean.rb', line 108 def default_name # Generate what should be a unique server name rand_str = Array.new(8) { rand(36).to_s(36) }.join "#{instance.name}-"\ "#{Etc.getlogin.gsub('_', '-')}-"\ "#{rand_str}-"\ "#{Socket.gethostname}" end |
#destroy(state) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/kitchen/driver/digital_ocean.rb', line 89 def destroy(state) return if state[:server_id].nil? if get_droplet(state[:server_id]) destroy_droplet state[:server_id] end info("Digital Ocean instance <#{state[:server_id]}> destroyed.") state.delete(:server_id) state.delete(:hostname) rescue RestClient::Exception => e raise ActionFailed, e. end |