def scan(images=True): """ scanning method that will scan all images or containers """ # FIXME using default 'unix://var/run/docker.sock' client = docker.Client(base_url='unix://var/run/docker.sock') emu = Emulator() objs = client.images(quiet=True) driver = client.info()['Driver'] # If there are no images/containers on the machine, objs will be [''] if objs == ['']: return # does actual work here! for im in objs: try: emu.create_dirs() cid = mount_obj(emu.tmp_image_dir, im, driver) if emu.is_applicable(): print "scanning " + im[:12] emu.intial_setup() emu.chroot_and_run() emu.unmount() else: print im[:12] + " is not RHEL based" unmount_obj(emu.tmp_image_dir, cid, driver) emu.remove_dirs() except MountError as dme: force_clean(cid, client, emu) print "Red Hat Insights was unable to complete " \ "due to the below error. All mounts and devices " \ "have been removed." raise ValueError(str(dme)) except EmulatorError as eme: force_clean(cid, client, emu) print "Red Hat Insights was unable to complete " \ "due to the below error. All mounts and devices " \ "have been removed." raise ValueError(str(eme)) emu.gather_data()
def scan(images=True): """ scanning method that will scan all images or containers """ client = DockerClient() emu = Emulator() objs = client.images() if images is True else client.containers() # If there are no images/containers on the machine, objs will be [''] if objs == ['']: return # does actual work here! for im in objs: try: emu.create_dirs() mount_obj(emu.tmp_image_dir, im, client.info()['Storage Driver']) if emu.is_applicable(): print "scanning " + im[:12] emu.intial_setup() emu.chroot_and_run() emu.unmount() else: print im[:12] + " is not RHEL based" unmount_obj(emu.tmp_image_dir, client.info()['Storage Driver']) emu.remove_dirs() except MountError as dme: raise ValueError(str(dme)) emu.gather_data(images)