Class: Kitchen::Driver::Digitalocean
- Inherits:
-
SSHBase
- Object
- SSHBase
- Kitchen::Driver::Digitalocean
- Defined in:
- lib/kitchen/driver/digitalocean.rb
Overview
Digital Ocean driver for Kitchen.
Instance Method Summary collapse
- #create(state) ⇒ Object
-
#default_image ⇒ Object
This method attempts to fetch the platform from a list of well-known platform => slug mappings, and falls back to using just the platform as provided if it can’t find a mapping.
-
#default_name ⇒ Object
Generate what should be a unique server name up to 63 total chars Base name: 15 Username: 15 Hostname: 23 Random string: 7 Separators: 3 ================ Total: 63.
- #destroy(state) ⇒ Object
Instance Method Details
#create(state) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kitchen/driver/digitalocean.rb', line 53 def create(state) server = create_server state[:server_id] = server.id info("Digital Ocean instance <#{state[:server_id]}> created.") loop do sleep 8 droplet = client.droplets.find(id: state[:server_id]) break if droplet && droplet.networks[:v4] && droplet.networks[:v4].any? { |n| n[:type] == 'public' } end droplet ||= client.droplets.find(id: state[:server_id]) state[:hostname] = droplet.networks[:v4] .find { |n| n[:type] == 'public' }['ip_address'] wait_for_sshd(state[:hostname]); print "(ssh ready)\n" debug("digitalocean:create #{state[:hostname]}") end |
#default_image ⇒ Object
This method attempts to fetch the platform from a list of well-known platform => slug mappings, and falls back to using just the platform as provided if it can’t find a mapping.
101 102 103 104 |
# File 'lib/kitchen/driver/digitalocean.rb', line 101 def default_image platform_to_slug_mapping.fetch(instance.platform.name, instance.platform.name) end |
#default_name ⇒ Object
Generate what should be a unique server name up to 63 total chars Base name: 15 Username: 15 Hostname: 23 Random string: 7 Separators: 3
Total: 63
114 115 116 117 118 119 120 121 |
# File 'lib/kitchen/driver/digitalocean.rb', line 114 def default_name [ instance.name.gsub(/\W/, '')[0..14], (Etc.getlogin || 'nologin').gsub(/\W/, '')[0..14], Socket.gethostname.gsub(/\W/, '')[0..22], Array.new(7) { rand(36).to_s(36) }.join ].join('-').gsub(/_/, '-') end |
#destroy(state) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/kitchen/driver/digitalocean.rb', line 75 def destroy(state) return if state[:server_id].nil? # A new droplet cannot be destroyed before it is active # Retry destroying the droplet as long as its status is "new" loop do droplet = client.droplets.find(id: state[:server_id]) break if !droplet if droplet.status != 'new' client.droplets.delete(id: state[:server_id]) break end info("Waiting on Digital Ocean instance <#{state[:server_id]}> to be active to destroy it, retrying in 8 seconds") sleep 8 end info("Digital Ocean instance <#{state[:server_id]}> destroyed.") state.delete(:server_id) state.delete(:hostname) end |