Last active
August 29, 2015 14:15
-
-
Save CFSworks/82af13b4a98689cd8a31 to your computer and use it in GitHub Desktop.
Vultr host-information lookup (for use in startup scripts)
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
#!/usr/bin/env python2 | |
# This script retrieves the information for your current Vultr node and prints Facter facts. | |
import urllib | |
import sys | |
import json | |
API_KEY = sys.argv[1] # This will crash unless you provide the API key. | |
def fetch(url): | |
return urllib.urlopen(url).read() | |
ip = fetch('http://169.254.169.254/current/meta-data/public-ipv4') | |
hosts = json.loads(fetch('https://api.vultr.com/v1/server/list?api_key=%s' % API_KEY)) | |
for host in hosts.values(): | |
if host.get('main_ip') == ip: | |
for k,v in host.items(): | |
print 'vultr_%s=%s' % (k.lower(), v) |
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
#!/usr/bin/env python2 | |
# This script retrieves the information for your current Vultr node and prints the JSON blob. | |
import urllib | |
import sys | |
import json | |
API_KEY = sys.argv[1] # This will crash unless you provide the API key. | |
def fetch(url): | |
return urllib.urlopen(url).read() | |
ip = fetch('http://169.254.169.254/current/meta-data/public-ipv4') | |
hosts = json.loads(fetch('https://api.vultr.com/v1/server/list?api_key=%s' % API_KEY)) | |
for host in hosts.values(): | |
if host.get('main_ip') == ip: | |
print json.dumps(host, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment