Skip to content

Instantly share code, notes, and snippets.

@futoase
Created February 13, 2018 16:35
Show Gist options
  • Save futoase/9f96137fce91d74b87c59b53587ad6bd to your computer and use it in GitHub Desktop.
Save futoase/9f96137fce91d74b87c59b53587ad6bd to your computer and use it in GitHub Desktop.
create-digital-ocean-instance.rb
require 'openssl'
require 'droplet_kit'
PREFIX = 'prefix-'
CLIENT_COUNT = 50
digest = OpenSSL::Digest.new("sha256")
# get application token from https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-api-v2
# export DIGITAL_OCEAN_TOKEN=XXXXXXXX
client = DropletKit::Client.new(access_token: ENV['DIGITAL_OCEAN_TOKEN'])
my_ssh_keys = client.ssh_keys.all.collect { |key| key.fingerprint }
CLIENT_COUNT.times do
droplet = DropletKit::Droplet.new(
name: "#{PREFIX}-#{digest.hexdigest(Time.now.to_s)}",
region: 'sgp1',
image: 'ubuntu-16-04-x64',
size: '512mb',
ssh_keys: my_ssh_keys
)
p client.droplets.create(droplet)
sleep 1
end
#
#p client.droplets.all().count
#
#client.droplets.all().each do |droplet|
# p droplet.id
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment