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.

Revisions

  1. futoase created this gist Feb 13, 2018.
    29 changes: 29 additions & 0 deletions create-digital-ocean-instance.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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