Last active
December 8, 2016 11:31
-
-
Save benbonnet/28f7a1627afe76c26e2c3f3d1b8a2cee to your computer and use it in GitHub Desktop.
CURL vs. Dropletkit
This file contains hidden or 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
require "droplet_kit" | |
require "net/http" | |
userdata = " | |
#cloud-config | |
coreos: | |
etcd2: | |
discovery: https://discovery.etcd.io/xxx | |
advertise-client-urls: http://$private_ipv4:2379,http://$private_ipv4:4001 | |
initial-advertise-peer-urls: http://$private_ipv4:2380 | |
listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001 | |
listen-peer-urls: http://$private_ipv4:2380 | |
units: | |
- name: etcd2.service | |
command: start | |
- name: fleet.service | |
command: start | |
" | |
client = DropletKit::Client.new(access_token: ENV["DO_KEY"]) | |
my_ssh_keys = client.ssh_keys.all.collect{ |key| "#{key.id}" } | |
["nyc-coreos-01"].each do |name| | |
droplet = DropletKit::Droplet.new( | |
name: name, | |
region: 'nyc3', | |
image: 'coreos-stable', | |
size: '1GB', | |
private_networking: true, | |
user_data: userdata, | |
ssh_keys: my_ssh_keys | |
) | |
droplet = client.droplets.create(droplet) | |
end |
This file contains hidden or 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
curl --request POST "https://api.digitalocean.com/v2/droplets" \ | |
--header "Content-Type: application/json" \ | |
--header "Authorization: Bearer $DO_KEY" \ | |
--data '{ | |
"region":"nyc3", | |
"image":"coreos-stable", | |
"size":"512mb", | |
"name":"core-1", | |
"private_networking":true, | |
"ssh_keys":['$SSH_KEY_ID'], | |
"user_data": "'"$(cat cloud-config-2.yaml | sed 's/"/\\"/g')"'" | |
}' |
This file contains hidden or 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
#cloud-config | |
coreos: | |
etcd2: | |
discovery: https://discovery.etcd.io/xxx | |
advertise-client-urls: http://$private_ipv4:2379,http://$private_ipv4:4001 | |
initial-advertise-peer-urls: http://$private_ipv4:2380 | |
listen-client-urls: http://0.0.0.0:2379,http://0.0.0.0:4001 | |
listen-peer-urls: http://$private_ipv4:2380 | |
units: | |
- name: etcd2.service | |
command: start | |
- name: fleet.service | |
command: start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment