Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save chornberger-c2c/7edfc497dff225978dd6dfcd0c9caeb5 to your computer and use it in GitHub Desktop.

Select an option

Save chornberger-c2c/7edfc497dff225978dd6dfcd0c9caeb5 to your computer and use it in GitHub Desktop.

Revisions

  1. chornberger-c2c revised this gist Jul 21, 2023. No changes.
  2. chornberger-c2c revised this gist Jun 22, 2023. No changes.
  3. chornberger-c2c revised this gist Jun 16, 2023. No changes.
  4. chornberger-c2c revised this gist Mar 10, 2023. No changes.
  5. chornberger-c2c revised this gist Oct 27, 2022. No changes.
  6. chornberger-c2c revised this gist Feb 22, 2022. No changes.
  7. chornberger-c2c revised this gist Jan 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sat6ShowHostSubscriptions.py
    Original 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: ./sat6ShowHostPackages.py -l admin -s sat6.example.com "
    print "\nExample usage: ./sat6ShowHostSubscriptions.py -l admin -s sat6.example.com "
    sys.exit(1)
    else:
    login = options.login
  8. chornberger-c2c revised this gist Jan 27, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion sat6ShowHostSubscriptions.py
    Original file line number Diff line number Diff line change
    @@ -85,5 +85,4 @@
    raise
    sys.exit(2)


    sys.exit(0)
  9. chornberger-c2c revised this gist Jan 27, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sat6ShowHostSubscriptions.py
    Original 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"])
    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()
  10. chornberger-c2c revised this gist Jan 27, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions sat6ShowHostSubscriptions.py
    Original 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":
    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)
  11. chornberger-c2c revised this gist Jan 27, 2022. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion sat6ShowHostSubscriptions.py
    Original 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)
    sys.exit(0)
  12. chornberger-c2c renamed this gist Jan 27, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  13. chornberger-c2c revised this gist Jan 27, 2022. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions sat6ShowHostPackages.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    #!/usr/bin/env python

    # File: sat6ShowHostPackages.py
    # Author: Rich Jerrido <[email protected]>
    # 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 installed packages
    # 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 + "/katello/api/systems?per_page=9999"
    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 + "/katello/api/systems/" + host["uuid"] + "/packages/"
    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,%s" % (host["name"], package["nvrea"], package["vendor"])
    print "%s; %s" % (host["certname"], package["name"])
    except urllib2.HTTPError as e:
    if str(e) != "HTTP Error 400: Bad Request":
    raise
  14. @sideangleside sideangleside created this gist Jun 1, 2016.
    82 changes: 82 additions & 0 deletions sat6ShowHostPackages.py
    Original 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)