Created
June 25, 2013 03:15
-
-
Save arscan/5855656 to your computer and use it in GitHub Desktop.
digital ocean scripts to bring up and tear down my dev instance really quick (i probably should switch to vagrant..)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# gem install digital_ocean | |
# ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $(./thisscript) | |
require 'digital_ocean' | |
CLIENT_ID = '' | |
API_KEY = '' | |
IMAGE_NAME = '' | |
INSTANCE_NAME = '' | |
dc = DigitalOcean::API.new :client_id => CLIENT_ID, | |
:api_key => API_KEY | |
ip_address = "" | |
dc.droplets.list.droplets.each do |i| | |
if i.name =~ /#{INSTANCE_NAME}/ && i.status == 'active' | |
puts i.ip_address | |
exit | |
end | |
end | |
imageid = 0 | |
dc.images.list.images.each do |i| | |
imageid = i.id if i.name =~ /#{IMAGE_NAME}/ | |
end | |
sizeid = 0 | |
dc.sizes.list.sizes.each do |i| | |
sizeid = i.id if i.name =~ /512MB/ | |
end | |
regionid = 0 | |
dc.regions.list.regions.each do |r| | |
regionid = r.id if r.name =~/New York/ | |
end | |
if sizeid && regionid && imageid | |
res = dc.droplets.create :name => INSTANCE_NAME, | |
:size_id => sizeid, | |
:image_id=> imageid, | |
:region_id => regionid | |
else | |
puts "Couldn't find the right size, region, or existing image" | |
exit | |
end | |
while true | |
dc.droplets.list.droplets.each do |i| | |
if i.name =~ /#{INSTANCE_NAME}/ && i.status == 'active' | |
puts i.ip_address | |
exit | |
end | |
end | |
sleep 5 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# gem install digital_ocean | |
require 'digital_ocean' | |
CLIENT_ID = '' | |
API_KEY = '' | |
INSTANCE_NAME = '' | |
dc = DigitalOcean::API.new :client_id => CLIENT_ID, | |
:api_key => API_KEY | |
ip_address = "" | |
dc.droplets.list.droplets.each do |i| | |
if i.name =~ /#{INSTANCE_NAME}/ && i.status == 'active' | |
res = dc.droplets.delete i.id | |
puts res.status | |
exit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment