Created
July 13, 2015 13:31
-
-
Save baude/961e7e22c04c1ed28fdc to your computer and use it in GitHub Desktop.
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 characters
| from image_scanner_client.image_scanner_client import Client | |
| from image_scanner_client.image_scanner_client import ImageScannerClientError | |
| from image_scanner_client.xml_parse import ParseOvalXML | |
| import json | |
| import sys | |
| import time | |
| def debug_print(json_data): | |
| ''' Simple helper function to pretty-print JSON data ''' | |
| print json.dumps(json_data, indent=4, separators=(',', ': ')) | |
| def status_sleep(status): | |
| print status | |
| time.sleep(5) | |
| # Edit this connection as needed | |
| image_scanner = Client("localhost", "5001", "4") | |
| try: | |
| # (1) Good image name | |
| shoulderror = False | |
| scan_results = image_scanner.scan_list(['bef54']) | |
| sys.exit(1) | |
| status_sleep("(1) Good image passed") | |
| # Should throw a image_scanner_client.image_scanner_client.ImageScannerClientError: | |
| # with a sensical error message | |
| scan_results = image_scanner.scan_list(['1234']) | |
| status__sleep("(2) Should throw exception") | |
| # Scan only active containers | |
| #scan_results = image_scanner.scan_all_containers(onlyactive=True) | |
| # Scan all containers | |
| #scan_results = image_scanner.scan_all_containers() | |
| # Scan only images | |
| #scan_results = image_scanner.scan_images() | |
| # Scan active containers and print a summary | |
| scan_results = image_scanner.scan_all_containers(onlyactive=True) | |
| # Instantiate xmlp | |
| xmlp = ParseOvalXML() | |
| # Fetch the detailed summary from the scan | |
| summary = image_scanner.get_docker_json(scan_results['json_url']) | |
| # Pretty print the summary | |
| xmlp.pprint(summary) | |
| # List the the glibc rpms in each container | |
| # Assumes they are RHEL containers | |
| for container, rpms in xmlp.return_rpm_by_docker_obj(summary).iteritems(): | |
| print "Container {0} has these glibc rpms: {1}"\ | |
| .format(container, | |
| ", ".join([x for x in rpms if x.startswith("glibc")])) | |
| except ImageScannerClientError as scan_error: | |
| if shoulderror: | |
| print "Caught an image-scanner error of: {0}".format(scan_error) | |
| else: | |
| print "Caught an un-expected error of: {0}".format(scan_error) | |
| sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment