Created
November 8, 2011 21:31
-
-
Save forforf/1349316 to your computer and use it in GitHub Desktop.
Server Script for populating a EC2 Name Server
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 '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