Skip to content

Commit

Permalink
Add support for Satellite 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sideangleside committed Sep 18, 2016
1 parent 80788c3 commit 8220548
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified Sample Report/Example_inventory_report.csv
100644 → 100755
Empty file.
39 changes: 35 additions & 4 deletions sat6Inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ class error_colors:
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context

try:
url = "https://" + satellite + "/api/status"
request = urllib2.Request(url)
if VERBOSE:
print "=" * 80
print "[%sVERBOSE%s] Connecting to -> %s " % (error_colors.OKGREEN, error_colors.ENDC, url)
base64string = base64.encodestring('%s:%s' % (login, password)).strip()
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
jsonresult = json.load(result)
api_version = jsonresult['api_version']
if VERBOSE:
print "=" * 80
print "[%sVERBOSE%s] API Version -> %s " % (error_colors.OKGREEN, error_colors.ENDC, api_version)
except urllib2.URLError, e:
print "Error: cannot connect to the API: %s" % (e)
print "Check your URL & try to login using the same user/pass via the WebUI and check the error!"
sys.exit(1)
except Exception, e:
print "FATAL Error - %s" % (e)
sys.exit(2)

systemdata = []

try:
Expand Down Expand Up @@ -287,9 +309,11 @@ def report_sysdata():

for system in systemdata:
sysdetailedurl = "https://" + satellite + "/katello/api/v2/systems/" + system["uuid"] + "?fields=full"
subdetailedurl = "https://" + satellite + "/katello/api/v2/systems/" + system["uuid"] + "/subscriptions"
hostdetailedurl = "https://" + satellite + "/api/v2/hosts/" + system["name"] + "/facts?per_page=99999"

if api_version == 2:
subdetailedurl = "https://" + satellite + "/api/v2/hosts/" + str(system["host_id"]) + "/subscriptions"
else:
subdetailedurl = "https://" + satellite + "/katello/api/v2/systems/" + system["uuid"] + "/subscriptions"
if VERBOSE:
print "=" * 80
print "[%sVERBOSE%s] Connecting to -> %s " % (error_colors.OKGREEN, error_colors.ENDC, sysdetailedurl)
Expand Down Expand Up @@ -347,7 +371,11 @@ def report_sysdata():
for entitlement in subdata["results"]:
# Get the Amount of subs
subName = entitlement['product_name']
host_info['amount'] = entitlement['amount']
if api_version == 2:
host_info['amount'] = entitlement['quantity_consumed']
else:
host_info['amount'] = entitlement['amount']
#host_info['amount'] = entitlement['amount']
host_info['entitlement'] = entitlement['product_name']
host_info['entitlements'] = entitlement['product_name']
host_info['organization'] = orgid
Expand All @@ -371,7 +399,10 @@ def report_sysdata():
if not subName in sub_summary:
sub_summary[subName] = {}
if virtual in sub_summary[subName]:
sub_summary[subName][virtual] += host_info['amount']
if host_info['amount'] == 'unknown':
sub_summary[subName][virtual] += 0
else:
sub_summary[subName][virtual] += int(host_info['amount'])
else:
sub_summary[subName][virtual] = host_info['amount']
except NameError:
Expand Down

0 comments on commit 8220548

Please sign in to comment.