Skip to content

Instantly share code, notes, and snippets.

@firegrass
Last active August 29, 2015 13:57
Show Gist options
  • Save firegrass/9685728 to your computer and use it in GitHub Desktop.
Save firegrass/9685728 to your computer and use it in GitHub Desktop.
Script resource for RunDeck to find Ganeti nodes
#!/usr/bin/env python
import urllib2, json, sys
cluster_name = 'YOUR.CLUSTER.COM'
print '# Loading nodes from {0}'.format(cluster_name)
name_filter = '*'
if len(sys.argv) > 1:
name_filter = sys.argv[1]
print '# Filtering with: ' + name_filter
r = urllib2.urlopen(' https://{0}:5080/2/instances?bulk=1'.format(cluster_name))
j = json.loads(r.read())
for n in j:
if name_filter is '*' or name_filter in n['name']:
#print str(n)
print n['name'] + ':'
print ' hostname: ' + n['name']
tags = n['tags']
pnode = [n['pnode'].replace('.YOURDOMAIN.COM','')]
oper_state = ['online']
if n['oper_state'] is False:
oper_state = ['offline']
disk_template = [n['disk_template']]
print ' tags: ' + str(tags + pnode + oper_state + disk_template).replace("u'","'")
r = urllib2.urlopen(' https://{0}:5080/2/nodes?bulk=1'.format(cluster_name))
j = json.loads(r.read())
for n in j:
if name_filter is '*' or name_filter in n['name']:
print n['name'] + ':'
print ' hostname: ' + n['name']
print ' tags: ' + str(n['tags'] + ['node']).replace("u'","'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment