linux - Error while running python script in RHN satellite report generation -
trying generate errata reports rhn satellite 5.6 python script , getting error following script. not have knowledge in python, in advance.
import json import sys import argparse try: import requests except importerror: print "please install python-requests module." sys.exit(-1) def get_json(location, username, password): # performs using passed url location location += "?per_page=10000" import requests requests.packages.urllib3.disable_warnings() #r = requests.get(location, auth=(username, password),verify=false) #return r.json() def main(): parser = argparse.argumentparser(description="satellite errata reporter") # arguments parser.add_argument("-u", "--username", type=str.lower, help="username access satellite", action="store", default='user1') parser.add_argument("-p", "--password", type=str, help="password access satellite", action="store", default='password') parser.add_argument("-n", "--server", type=str.lower, help="satellite server (default: localhost)", default='localhost') parser.add_argument("-o", "--organization", type=str.lower, nargs="*", help="filter on space-delimited list of organization(s)", default='tcs_production') parser.add_argument("-e", "--environment", type=str.lower, nargs="*", help="filter on space-delimited list of lifecycle environments", default='') parser.add_argument("-c", "--collection", type=str.lower, nargs="*", help="filter on , group space-delimited list of host collections", default='') parser.add_argument("-t", "--type", type=str.lower, nargs="*", help="filter on space-delimeted list of errata types (bugfix, enhancement, and/or security)", default='') parser.add_argument("-s", "--severity", type=str.lower, nargs="*", help="filter on space-delimited list of severities (critical, important, moderate, low)", default='') args = parser.parse_args() # check username , password if not (args.username , args.password): print "no complete account information provided, exiting" exit (-1) # set api url sat_api = "http://%s/hostname/api/v2/" % args.server katello_api = "http://%s/hostname/api/" % args.server # set initial stuff prefix = "- " systems_fetched = false system_count = 0 system_errata_count = 0 # loop through organizations , skip ones don't want orgs = get_json(sat_api + "organizations/", args.username, args.password) org in orgs['results']: if args.organization , org['name'].lower not in args.organization: continue print "\nerrata organization '%s':" % org['name'] if args.collection: # loop through host collections, skip 1 don't want collections = get_json(sat_api + "organizations/" + str(org['id']) + "/host_collections/", args.username, args.password) collection in collections['results']: if collection['name'].lower() not in args.collection: continue print "\n" + prefix + "errata host collection '%s':" % collection['name'] prefix = " - " # systems in host collection systems = get_json(sat_api + "host_collections/" + str(collection['id']) + "/systems/", args.username, args.password) systems_fetched = true else: # systems in organization systems = get_json(sat_api + "organizations/" + str(org['id']) + "/systems/", args.username, args.password) systems_fetched = true if not systems_fetched: continue # loop through systems fetched collection *or* organization system in systems['results']: system_errata = get_json(sat_api + "systems/" + system['uuid'] + "/errata", args.username, args.password) first = true # filter on lifecycle environment(s) (if specified) environment = system['environment']['name'].lower() if args.environment , environment not in args.environment: continue # available errata system system_erratum in system_errata['results']: # filter on type(s) (if specified) type = system_erratum['type'].lower() if args.type , type not in args.type: continue # filter on severity(s) (if specified) if type == "security" , "security" in args.type , args.severity: severity = system_erratum['title'].split(":")[0].encode('ascii','ignore').lower() if severity not in args.severity: continue # have erratum, print system if first if first: system_count += 1 first = false print "\n" + prefix + system['name'], "("+system['environment']['name']+")\n" # print erratum id, type , title (with severity included in title) print " " + prefix + "%s: %s: %s" % (system_erratum['errata_id'],system_erratum['type'],system_erratum['title']) # count errata find system_errata_count += 1 if not first: print # print statistics if system_errata_count: print "\nnumber of errata apply: %s" % system_errata_count print "number of systems affected: %s" % system_count else: print "\nno errata found selection" print if __name__ == "__main__": main()
getting below errors
traceback (most recent call last):
file "./pyth.py", line 138, in
main()
file "./pyth.py", line 62, in main
org in orgs['results']:
Comments
Post a Comment