Forked from sideangleside/sat6ShowHostPackages.py
Last active
April 24, 2025 14:10
-
-
Save chornberger-c2c/7edfc497dff225978dd6dfcd0c9caeb5 to your computer and use it in GitHub Desktop.
Revisions
-
chornberger-c2c revised this gist
Jul 21, 2023 . No changes.There are no files selected for viewing
-
chornberger-c2c revised this gist
Jun 22, 2023 . No changes.There are no files selected for viewing
-
chornberger-c2c revised this gist
Jun 16, 2023 . No changes.There are no files selected for viewing
-
chornberger-c2c revised this gist
Mar 10, 2023 . No changes.There are no files selected for viewing
-
chornberger-c2c revised this gist
Oct 27, 2022 . No changes.There are no files selected for viewing
-
chornberger-c2c revised this gist
Feb 22, 2022 . No changes.There are no files selected for viewing
-
chornberger-c2c revised this gist
Jan 27, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -33,7 +33,7 @@ if not ( options.login and options.server): print "Must specify a login & server (will prompt for password if omitted). See usage:" parser.print_help() print "\nExample usage: ./sat6ShowHostSubscriptions.py -l admin -s sat6.example.com " sys.exit(1) else: login = options.login -
chornberger-c2c revised this gist
Jan 27, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -85,5 +85,4 @@ raise sys.exit(2) sys.exit(0) -
chornberger-c2c revised this gist
Jan 27, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -74,8 +74,8 @@ if packagedata.has_key("errors"): print packagedata["errors"] if packagedata["results"]: for package in packagedata['results']: print "%s; %s" % (host["certname"], package["name"]) except urllib2.HTTPError as e: if str(e) == "HTTP Error 400: Bad Request": msg = e.read().decode() -
chornberger-c2c revised this gist
Jan 27, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -77,10 +77,10 @@ for package in packagedata['results']: print "%s; %s" % (host["certname"], package["name"]) except urllib2.HTTPError as e: if str(e) == "HTTP Error 400: Bad Request": msg = e.read().decode() errormsg = json.loads(msg) print "%s; %s" % (host["certname"], str(errormsg["displayMessage"])) if str(e) != "HTTP Error 400: Bad Request": raise sys.exit(2) -
chornberger-c2c revised this gist
Jan 27, 2022 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -77,8 +77,13 @@ for package in packagedata['results']: print "%s; %s" % (host["certname"], package["name"]) except urllib2.HTTPError as e: if str(e) == "HTTP Error 400: Bad Request": msg = e.read().decode() errormsg = json.loads(msg) print "%s; %s" % (host["certname"], str(errormsg["displayMessage"])) if str(e) != "HTTP Error 400: Bad Request": raise sys.exit(2) sys.exit(0) -
chornberger-c2c renamed this gist
Jan 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
chornberger-c2c revised this gist
Jan 27, 2022 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ #!/usr/bin/env python # File: sat6ShowHostSubscriptions.py # Authors: Rich Jerrido <[email protected]> # Christopher Hornberger <[email protected]> # # Purpose: given an hostname and login to Satelite, show me all the # hosts and their subscriptions. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -45,7 +47,7 @@ ssl._create_default_https_context = ssl._create_unverified_context #### Get the list of hosts url = "https://" + server + "/api/v2/hosts?per_page=9999" try: request = urllib2.Request(url) print "Attempting to connect: " + url @@ -62,7 +64,7 @@ hostdata = json.load(result) for host in hostdata['results']: detailedurl = "https://" + server + "/api/v2/hosts/" + str(host["id"]) + "/subscriptions/" try: sysinfo = urllib2.Request(detailedurl) base64string = base64.encodestring('%s:%s' % (login, password)).strip() @@ -73,7 +75,7 @@ print packagedata["errors"] if packagedata["results"]: for package in packagedata['results']: print "%s; %s" % (host["certname"], package["name"]) except urllib2.HTTPError as e: if str(e) != "HTTP Error 400: Bad Request": raise -
sideangleside created this gist
Jun 1, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ #!/usr/bin/env python # File: sat6ShowHostPackages.py # Author: Rich Jerrido <[email protected]> # Purpose: given an hostname and login to Satelite, show me all the # hosts and their installed packages # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. import json import getpass import urllib2 import base64 import sys import ssl from optparse import OptionParser parser = OptionParser() parser.add_option("-l", "--login", dest="login", help="Login user", metavar="LOGIN") parser.add_option("-p", "--password", dest="password", help="Password for specified user. Will prompt if omitted", metavar="PASSWORD") parser.add_option("-s", "--server", dest="server", help="FQDN of sat6 instance", metavar="SERVER") (options, args) = parser.parse_args() if not ( options.login and options.server): print "Must specify a login & server (will prompt for password if omitted). See usage:" parser.print_help() print "\nExample usage: ./sat6ShowHostPackages.py -l admin -s sat6.example.com " sys.exit(1) else: login = options.login password = options.password server = options.server if not password: password = getpass.getpass("%s's password:" % login) if hasattr(ssl, '_create_unverified_context'): ssl._create_default_https_context = ssl._create_unverified_context #### Get the list of hosts url = "https://" + server + "/katello/api/systems?per_page=9999" try: request = urllib2.Request(url) print "Attempting to connect: " + url base64string = base64.encodestring('%s:%s' % (login, password)).strip() request.add_header("Authorization", "Basic %s" % base64string) result = urllib2.urlopen(request) 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: print "FATAL Error - %s" % (e) sys.exit(2) hostdata = json.load(result) for host in hostdata['results']: detailedurl = "https://" + server + "/katello/api/systems/" + host["uuid"] + "/packages/" try: sysinfo = urllib2.Request(detailedurl) base64string = base64.encodestring('%s:%s' % (login, password)).strip() sysinfo.add_header("Authorization", "Basic %s" % base64string) sysresult = urllib2.urlopen(sysinfo) packagedata = json.load(sysresult) if packagedata.has_key("errors"): print packagedata["errors"] if packagedata["results"]: for package in packagedata['results']: print "%s,%s,%s" % (host["name"], package["nvrea"], package["vendor"]) except urllib2.HTTPError as e: if str(e) != "HTTP Error 400: Bad Request": raise sys.exit(2) sys.exit(0)