def get_os_details(self): """ Extract the debian machine details. """ debian_version = vm_find_path(self.fs_mntpt, os.path.join\ ("etc", "debian_version"), returntype="data") ubuntu_version = vm_find_path(self.fs_mntpt, os.path.join\ ("etc", "lsb-release"), returntype="data") self.os_details['distro'] = debian_version.strip() self.os_details['os_type'] = "Linux" try: t = re.search(r"DISTRIB_DESCRIPTION=\"(?P<distrib_name>.*)\"", ubuntu_version) self.os_details['os_name'] = t.group('distrib_name') except: self.os_details['os_name'] = "Debian" self.__get_installed_apps() self.__get_installed_kernel_info() self.os_details['Applications/Internet'] = \ ', '.join(self.installed_apps) self.os_details['installed_apps_list'] = self.installed_apps return self.os_details
def get_os_details(self): """ Extract the redhat machine details. """ buffer = vm_find_path(self.fs_mntpt, os.path.join('etc', 'redhat-release'), returntype="data") self.os_details['distro'] = buffer.strip() self.os_details['os_name'] = self.os_details['distro'] self.os_details['os_type'] = 'Linux' try: package_buffer = vm_find_path(self.fs_mntpt, os.path.join('var', 'lib', 'rpm', 'Name'), returntype="list") package_hash_file = os.path.join(os.path.dirname(self.fs_mntpt), str(now())) with open(package_hash_file, 'w') as fd: for x in package_buffer.readlines(): fd.write(x) try: packages_list = bsddb.hashopen(package_hash_file).keys() except: packages_list = [] finally: os.unlink(package_hash_file) self.os_details['Applications/Internet'] = ', '.join(packages_list) self.os_details['installed_apps_list'] = packages_list except Exception: raise vm_os_details_not_found() try: kernel_pkg_buffer = vm_find_path(self.fs_mntpt, os.path.join('etc', 'grub.conf'), returntype="list") kernel_pkg_list = [] for line in kernel_pkg_buffer.readlines(): if line.find('title') == 0: kernel_pkg_list.append('kernel-%s' % str( line.split(' ')[2].replace('(', '').repalce(')', ''))) self.os_details['str_os_kernel_bld'] = ', '.join(kernel_pkg_list) except: self.os_details['str_os_kernel_bld'] = None return self.os_details
def probe_os_type(mount_point): for os_type in os_path_map.keys(): try: if vm_find_path(mount_point, os_path_map[os_type], inode=None): return os_type except: pass """
def __get_reg_path(self): for x in os_regpath_list: try: #self.reg_path = find_path(os.path.join(self.fs_mntpt, x)) self.reg_path = vm_find_path(self.fs_mntpt, x) except: self.reg_path = "" else: if self.reg_path != "": break if self.reg_path == "": raise vm_os_regpath_not_found # write the registry file self.reg_path = readfile(self.fs_mntpt, self.reg_path, "file")
def __get_installed_kernel_info(self): """ Method to extract kernel information from disk image. """ kernel_pkgs = [] buffer = vm_find_path(self.fs_mntpt, os.path.join("var", "lib", "dpkg", "status"), returntype="list") for x in buffer: if x.startswith('Package:'): details = x.split(':') if details[1].strip().startswith('linux-image'): kernel_pkgs.append(details[1].strip()) self.os_details['str_os_kernel_bld'] = ', '.join(kernel_pkgs)
def __get_installed_apps(self): """ Get the list of installed application from disk image. """ pkg_list = [] pkg_entry = dict() buffer = vm_find_path(self.fs_mntpt, os.path.join("var", "lib", "dpkg", "status"), returntype="list") for x in buffer: if x == '\n': pkg_list.append(pkg_entry) pkg_entry = dict() else: try: details = x.split(':') if details[0] in ('Package', 'Version'): pkg_entry[details[0]] = ':'.join(details[1:]).strip() except: pass self.installed_apps = ["%s-%s" % (x['Package'], x['Version']) \ for x in pkg_list] self.installed_apps.sort()