-
Notifications
You must be signed in to change notification settings - Fork 1
/
digitalocean.rb
50 lines (44 loc) · 1.37 KB
/
digitalocean.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'digitalocean'
Digitalocean.client_id = "5db96853e00c384a68b3d51ac3ebee43"
Digitalocean.api_key = "ab3dd003049b32041494fce4137d1b8e"
def self.delete_proxy(ipaddress)
begin
droplets = Digitalocean::Droplet.all
droplets["droplets"].each do |drop|
if drop["ip_address"] == ipaddress
Digitalocean::Droplet.destroy(drop["id"])
end
end
rescue => err
log_error("delete_proxy failed")
log_error(err)
end
end
def self.delete_all_proxies()
begin
droplets = Digitalocean::Droplet.all
droplets["droplets"].each do |drop|
if drop["name"].include? "proxy-"
Digitalocean::Droplet.destroy(drop["id"])
end
end
rescue => err
log_error("delete_all_proxies failed")
log_error(err)
end
end
def self.create_proxy(name,size_id,image_id,region_id,howmany)
begin
status_array = Array.new
ip_array = Array.new
status = Digitalocean::Droplet.create({:name => "proxy-" + name.to_s, :size_id => size_id, :image_id => image_id, :region_id => region_id})
puts status
sleep 15
ipaddress = Digitalocean::Droplet.retrieve(status.droplet.id).droplet.ip_address
sleep 60
return ipaddress
rescue => err
log_error("create_proxy failed")
log_error(err)
end
end