Skip to content

Instantly share code, notes, and snippets.

@CFSworks
Last active August 29, 2015 14:15
Show Gist options
  • Save CFSworks/82af13b4a98689cd8a31 to your computer and use it in GitHub Desktop.
Save CFSworks/82af13b4a98689cd8a31 to your computer and use it in GitHub Desktop.
Vultr host-information lookup (for use in startup scripts)
#!/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)
#!/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