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
-
#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
52 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 52 def create(state) server = create_server state[:server_id] = server.id info("Digital Ocean instance <#{state[:server_id]}> created.") while true 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 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
84 85 86 |
# File 'lib/kitchen/driver/digitalocean.rb', line 84 def default_image 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
96 97 98 99 100 101 102 103 |
# File 'lib/kitchen/driver/digitalocean.rb', line 96 def default_name [ instance.name.gsub(/\W/, '')[0..14], Etc.getlogin.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 |
# File 'lib/kitchen/driver/digitalocean.rb', line 75 def destroy(state) return if state[:server_id].nil? client.droplets.delete(id: state[:server_id]) info("Digital Ocean instance <#{state[:server_id]}> destroyed.") state.delete(:server_id) state.delete(:hostname) end |