Skip to content

Instantly share code, notes, and snippets.

@benbonnet
Last active December 8, 2016 11:31
Show Gist options
  • Save benbonnet/28f7a1627afe76c26e2c3f3d1b8a2cee to your computer and use it in GitHub Desktop.
Save benbonnet/28f7a1627afe76c26e2c3f3d1b8a2cee to your computer and use it in GitHub Desktop.
CURL vs. Dropletkit
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
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')"'"
}'
#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