def _linux_inspector( fs: boot_inspect.system.filesystems.Filesystem) -> linux.Inspector: """Returns a linux.Inspector that is configured with all detectable Linux distros. """ return linux.Inspector(fs, _LINUX)
def inspect_device(g) -> inspect_pb2.InspectionResults: """Finds boot-related properties for a device using offline inspection. Args: g (guestfs.GuestFS): A launched, but unmounted, GuestFS instance. Example: g = guestfs.GuestFS(python_return_dict=True) g.add_drive_opts("/dev/sdb", format="raw") g.launch() results = inspect_device(g, "/dev/sdb") """ roots = g.inspect_os() if len(roots) == 0: return inspect_pb2.InspectionResults( os_count=len(roots) ) root = roots[0] mount_points = g.inspect_get_mountpoints(root) for dev, mp in sorted(mount_points.items(), key=lambda k: len(k[0])): try: g.mount_ro(mp, dev) except RuntimeError as msg: print('%s (ignored)' % msg, file=sys.stderr) fs = boot_inspect.system.filesystems.GuestFSFilesystem(g) operating_system = linux.Inspector(fs, _LINUX).inspect() if not operating_system: operating_system = windows.Inspector(g, root).inspect() if operating_system: operating_system.architecture = architecture.Inspector(g, root).inspect() g.umount_all() return inspect_pb2.InspectionResults( os_release=operating_system, os_count=1 if operating_system else 0, )
def inspect_device(g, device: str) -> model.InspectionResults: """Finds boot-related properties for a device using offline inspection. Args: g (guestfs.GuestFS): A launched, but unmounted, GuestFS instance. device: a reference to a mounted block device (eg: /dev/sdb), or to a virtual disk file (eg: /opt/images/disk.vmdk). Example: g = guestfs.GuestFS(python_return_dict=True) g.add_drive_opts("/dev/sdb", format="raw") g.launch() results = inspect_device(g, "/dev/sdb") """ roots = g.inspect_os() if len(roots) == 0: print('inspect_vm: no operating systems found', file=sys.stderr) sys.exit(1) root = roots[0] mount_points = g.inspect_get_mountpoints(root) for dev, mp in sorted(mount_points.items(), key=lambda k: len(k[0])): try: g.mount_ro(mp, dev) except RuntimeError as msg: print('%s (ignored)' % msg, file=sys.stderr) fs = boot_inspect.system.filesystems.GuestFSFilesystem(g) operating_system = linux.Inspector(fs, _LINUX).inspect() if not operating_system: operating_system = windows.Inspector(g, root).inspect() arch = architecture.Inspector(g, root).inspect() g.umount_all() return model.InspectionResults( device=device, os=operating_system, architecture=arch, )