Skip to content

Instantly share code, notes, and snippets.

@forforf
Created November 8, 2011 21:31
Show Gist options
  • Select an option

  • Save forforf/1349316 to your computer and use it in GitHub Desktop.

Select an option

Save forforf/1349316 to your computer and use it in GitHub Desktop.
Server Script for populating a EC2 Name Server
require 'json'
#Get Instance IP Address
my_ip = `curl -s http://instance-data/latest/meta-data/public-ipv4`
#not real names
my_server_name = "MyServer"
bootstrap_db = "http://my_iris.iriscouch.com/bootie"
#url for the record data
record_loc = bootstrap_db + "/" + my_server_name
#get rev of current record
data_raw = `curl -s GET #{record_loc}`
data = JSON.parse(data_raw)
rev = data["_rev"]
#update database to current value
new_record = {
"_id" => my_server_name,
"_rev" => rev,
"ip" => my_ip
}
new_record_json = new_record.to_json
resp = `curl -s --request PUT #{record_loc} -Hcontent-type:application/json -d \'#{new_record_json}\'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment