Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1.  
  2. from image_scanner_client.image_scanner_client import Client
  3. from image_scanner_client.image_scanner_client import ImageScannerClientError
  4. from image_scanner_client.xml_parse import ParseOvalXML
  5. import json
  6. import sys
  7. import time
  8.  
  9.  
  10. def debug_print(json_data):
  11. ''' Simple helper function to pretty-print JSON data '''
  12. print json.dumps(json_data, indent=4, separators=(',', ': '))
  13.  
  14.  
  15. def status_sleep(status):
  16. print status
  17. time.sleep(5)
  18.  
  19. # Edit this connection as needed
  20.  
  21. image_scanner = Client("localhost", "5001", "4")
  22.  
  23. try:
  24. # (1) Good image name
  25.  
  26. shoulderror = False
  27. scan_results = image_scanner.scan_list(['bef54'])
  28. sys.exit(1)
  29. status_sleep("(1) Good image passed")
  30.  
  31. # Should throw a image_scanner_client.image_scanner_client.ImageScannerClientError:
  32. # with a sensical error message
  33.  
  34. scan_results = image_scanner.scan_list(['1234'])
  35. status__sleep("(2) Should throw exception")
  36.  
  37. # Scan only active containers
  38. #scan_results = image_scanner.scan_all_containers(onlyactive=True)
  39.  
  40. # Scan all containers
  41. #scan_results = image_scanner.scan_all_containers()
  42.  
  43. # Scan only images
  44. #scan_results = image_scanner.scan_images()
  45.  
  46.  
  47. # Scan active containers and print a summary
  48. scan_results = image_scanner.scan_all_containers(onlyactive=True)
  49. # Instantiate xmlp
  50. xmlp = ParseOvalXML()
  51. # Fetch the detailed summary from the scan
  52. summary = image_scanner.get_docker_json(scan_results['json_url'])
  53. # Pretty print the summary
  54. xmlp.pprint(summary)
  55.  
  56. # List the the glibc rpms in each container
  57. # Assumes they are RHEL containers
  58.  
  59. for container, rpms in xmlp.return_rpm_by_docker_obj(summary).iteritems():
  60. print "Container {0} has these glibc rpms: {1}"\
  61. .format(container,
  62. ", ".join([x for x in rpms if x.startswith("glibc")]))
  63.  
  64. except ImageScannerClientError as scan_error:
  65. if shoulderror:
  66. print "Caught an image-scanner error of: {0}".format(scan_error)
  67. else:
  68. print "Caught an un-expected error of: {0}".format(scan_error)
  69. sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement