|
|
@ -1,31 +1,32 @@
|
|
|
|
#!/usr/bin/env python
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import requests
|
|
|
|
import types
|
|
|
|
import types
|
|
|
|
|
|
|
|
|
|
|
|
RACKHD_URL = 'http://localhost:8080'
|
|
|
|
RACKHD_URL = 'http://localhost:8080'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RackhdInventory(object):
|
|
|
|
class RackhdInventory(object):
|
|
|
|
def __init__(self, nodeids):
|
|
|
|
def __init__(self, nodeids):
|
|
|
|
self._inventory = {}
|
|
|
|
self._inventory = {}
|
|
|
|
for nodeid in nodeids:
|
|
|
|
for nodeid in nodeids:
|
|
|
|
self._load_inventory_data(nodeid)
|
|
|
|
self._load_inventory_data(nodeid)
|
|
|
|
inventory = {}
|
|
|
|
inventory = {}
|
|
|
|
for nodeid,info in self._inventory.items():
|
|
|
|
for (nodeid, info) in self._inventory.items():
|
|
|
|
inventory[nodeid]= (self._format_output(nodeid, info))
|
|
|
|
inventory[nodeid] = (self._format_output(nodeid, info))
|
|
|
|
print(json.dumps(inventory))
|
|
|
|
print(json.dumps(inventory))
|
|
|
|
|
|
|
|
|
|
|
|
def _load_inventory_data(self, nodeid):
|
|
|
|
def _load_inventory_data(self, nodeid):
|
|
|
|
info = {}
|
|
|
|
info = {}
|
|
|
|
info['ohai'] = RACKHD_URL + '/api/common/nodes/{0}/catalogs/ohai'.format(nodeid )
|
|
|
|
info['ohai'] = RACKHD_URL + '/api/common/nodes/{0}/catalogs/ohai'.format(nodeid)
|
|
|
|
info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid)
|
|
|
|
info['lookup'] = RACKHD_URL + '/api/common/lookups/?q={0}'.format(nodeid)
|
|
|
|
|
|
|
|
|
|
|
|
results = {}
|
|
|
|
results = {}
|
|
|
|
for key,url in info.items():
|
|
|
|
for (key, url) in info.items():
|
|
|
|
r = requests.get( url, verify=False)
|
|
|
|
r = requests.get(url, verify=False)
|
|
|
|
results[key] = r.text
|
|
|
|
results[key] = r.text
|
|
|
|
self._inventory[nodeid] = results
|
|
|
|
self._inventory[nodeid] = results
|
|
|
|
|
|
|
|
|
|
|
@ -35,8 +36,8 @@ class RackhdInventory(object):
|
|
|
|
ipaddress = ''
|
|
|
|
ipaddress = ''
|
|
|
|
if len(node_info) > 0:
|
|
|
|
if len(node_info) > 0:
|
|
|
|
ipaddress = node_info[0]['ipAddress']
|
|
|
|
ipaddress = node_info[0]['ipAddress']
|
|
|
|
output = { 'hosts':[ipaddress],'vars':{}}
|
|
|
|
output = {'hosts': [ipaddress], 'vars': {}}
|
|
|
|
for key,result in info.items():
|
|
|
|
for (key, result) in info.items():
|
|
|
|
output['vars'][key] = json.loads(result)
|
|
|
|
output['vars'][key] = json.loads(result)
|
|
|
|
output['vars']['ansible_ssh_user'] = 'monorail'
|
|
|
|
output['vars']['ansible_ssh_user'] = 'monorail'
|
|
|
|
except KeyError:
|
|
|
|
except KeyError:
|
|
|
@ -51,10 +52,10 @@ def parse_args():
|
|
|
|
return parser.parse_args()
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
#check if rackhd url(ie:10.1.1.45:8080) is specified in the environment
|
|
|
|
# check if rackhd url(ie:10.1.1.45:8080) is specified in the environment
|
|
|
|
RACKHD_URL = 'http://' + str(os.environ['RACKHD_URL'])
|
|
|
|
RACKHD_URL = 'http://' + str(os.environ['RACKHD_URL'])
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
#use default values
|
|
|
|
# use default values
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Use the nodeid specified in the environment to limit the data returned
|
|
|
|
# Use the nodeid specified in the environment to limit the data returned
|
|
|
@ -70,7 +71,7 @@ if (parse_args().host):
|
|
|
|
if (parse_args().list):
|
|
|
|
if (parse_args().list):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
url = RACKHD_URL + '/api/common/nodes'
|
|
|
|
url = RACKHD_URL + '/api/common/nodes'
|
|
|
|
r = requests.get( url, verify=False)
|
|
|
|
r = requests.get(url, verify=False)
|
|
|
|
data = json.loads(r.text)
|
|
|
|
data = json.loads(r.text)
|
|
|
|
for entry in data:
|
|
|
|
for entry in data:
|
|
|
|
if entry['type'] == 'compute':
|
|
|
|
if entry['type'] == 'compute':
|
|
|
|