def get_device_items_sles(self, dev_path): self.logger.log( "get_device_items_sles : getting the blk info from " + str(dev_path), True) device_items = [] #first get all the device names if (dev_path is None): get_device_cmd = self.patching.lsblk_path + " -b -nl -o NAME" else: get_device_cmd = self.patching.lsblk_path + " -b -nl -o NAME " + dev_path get_device_cmd_args = Utils.HandlerUtil.HandlerUtility.split( self.logger, get_device_cmd) p = Popen(get_device_cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) lines = out_lsblk_output.splitlines() for i in range(0, len(lines)): item_value_str = lines[i].strip() if (item_value_str != ""): disk_info_item_array = Utils.HandlerUtil.HandlerUtility.split( self.logger, item_value_str) device_item = DeviceItem() device_item.name = disk_info_item_array[0] device_items.append(device_item) for i in range(0, len(device_items)): device_item = device_items[i] device_item.file_system = self.get_device_items_property( lsblk_path=self.patching.lsblk_path, dev_name=device_item.name, property_name='FSTYPE') device_item.mount_point = self.get_device_items_property( lsblk_path=self.patching.lsblk_path, dev_name=device_item.name, property_name='MOUNTPOINT') device_item.label = self.get_device_items_property( lsblk_path=self.patching.lsblk_path, dev_name=device_item.name, property_name='LABEL') device_item.uuid = self.get_device_items_property( lsblk_path=self.patching.lsblk_path, dev_name=device_item.name, property_name='UUID') #get the type of device model_file_path = '/sys/block/' + device_item.name + '/device/model' if (os.path.exists(model_file_path)): with open(model_file_path, 'r') as f: device_item.model = f.read().strip() if (device_item.model == 'Virtual Disk'): self.logger.log("model is virtual disk", True) device_item.type = 'disk' if (device_item.type != 'disk'): partition_files = glob.glob('/sys/block/*/' + device_item.name + '/partition') if (partition_files is not None and len(partition_files) > 0): self.logger.log("partition files exists", True) device_item.type = 'part' return device_items
def get_device_items_from_lsblk_list(self, lsblk_path, dev_path): self.logger.log("get_device_items_from_lsblk_list : getting the blk info from " + str(dev_path), True) device_items = [] #first get all the device names if(dev_path is None): get_device_cmd = lsblk_path + " -b -nl -o NAME" else: get_device_cmd = lsblk_path + " -b -nl -o NAME " + dev_path get_device_cmd_args = shlex.split(get_device_cmd) p = Popen(get_device_cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_lsblk_output, err = p.communicate() lines = out_lsblk_output.splitlines() device_items_temp = [] for i in range(0,len(lines)): item_value_str = lines[i].strip() if(item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() device_item.name = disk_info_item_array[0] device_items_temp.append(device_item) for i in range(0,len(device_items_temp)): device_item = device_items_temp[i] device_item.mount_point = self.get_device_items_property(lsblk_path=lsblk_path,dev_name=device_item.name,property_name='MOUNTPOINT') if (device_item.mount_point is not None): device_item.file_system = self.get_device_items_property(lsblk_path=lsblk_path,dev_name=device_item.name,property_name='FSTYPE') device_item.label = self.get_device_items_property(lsblk_path=lsblk_path,dev_name=device_item.name,property_name='LABEL') device_item.uuid = self.get_device_items_property(lsblk_path=lsblk_path,dev_name=device_item.name,property_name='UUID') device_item.type = self.get_device_items_property(lsblk_path=lsblk_path,dev_name=device_item.name,property_name='TYPE') device_items.append(device_item) self.logger.log("lsblk MOUNTPOINT=" + str(device_item.mount_point) + ", NAME=" + str(device_item.name) + ", TYPE=" + str(device_item.type) + ", FSTYPE=" + str(device_item.file_system) + ", LABEL=" + str(device_item.label) + ", UUID=" + str(device_item.uuid) + ", MODEL=" + str(device_item.model), True) return device_items
def get_device_items(self, dev_path): if(self.patching.distro_info[0].lower() == 'suse' and self.patching.distro_info[1] == '11'): return self.get_device_items_sles(dev_path) else: self.logger.log(msg=("getting the blk info from " + str(dev_path))) device_items = [] if(dev_path is None): p = Popen([self.patching.lsblk_path, '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen([self.patching.lsblk_path, '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE',dev_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) error_msg = str(err) if(error_msg is not None and error_msg.strip() != ""): self.logger.log(msg=str(err),level=CommonVariables.ErrorLevel) lines = out_lsblk_output.splitlines() for i in range(0,len(lines)): item_value_str = lines[i].strip() if(item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split('=') if(property_item_pair[0] == 'SIZE'): device_item.size = int(property_item_pair[1].strip('"')) if(property_item_pair[0] == 'NAME'): device_item.name = property_item_pair[1].strip('"') if(property_item_pair[0] == 'TYPE'): device_item.type = property_item_pair[1].strip('"') if(property_item_pair[0] == 'FSTYPE'): device_item.file_system = property_item_pair[1].strip('"') if(property_item_pair[0] == 'MOUNTPOINT'): device_item.mount_point = property_item_pair[1].strip('"') if(property_item_pair[0] == 'LABEL'): device_item.label = property_item_pair[1].strip('"') if(property_item_pair[0] == 'UUID'): device_item.uuid = property_item_pair[1].strip('"') if(property_item_pair[0] == 'MODEL'): device_item.model = property_item_pair[1].strip('"') device_items.append(device_item) return device_items
def get_device_items_sles(self, dev_path): self.logger.log(msg=("getting the blk info from " + str(dev_path))) device_items = [] # first get all the device names if dev_path is None: get_device_cmd = self.patching.lsblk_path + " -b -nl -o NAME" else: get_device_cmd = self.patching.lsblk_path + " -b -nl -o NAME " + dev_path get_device_cmd_args = shlex.split(get_device_cmd) p = Popen(get_device_cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_lsblk_output, err = p.communicate() lines = out_lsblk_output.splitlines() for i in range(0, len(lines)): item_value_str = lines[i].strip() if item_value_str != "": disk_info_item_array = item_value_str.split() device_item = DeviceItem() device_item.name = disk_info_item_array[0] device_items.append(device_item) for i in range(0, len(device_items)): device_item = device_items[i] device_item.file_system = self.get_device_items_property(dev_name=device_item.name, property_name="FSTYPE") device_item.mount_point = self.get_device_items_property( dev_name=device_item.name, property_name="MOUNTPOINT" ) device_item.label = self.get_device_items_property(dev_name=device_item.name, property_name="LABEL") device_item.uuid = self.get_device_items_property(dev_name=device_item.name, property_name="UUID") # get the type of device model_file_path = "/sys/block/" + device_item.name + "/device/model" if os.path.exists(model_file_path): with open(model_file_path, "r") as f: device_item.model = f.read().strip() if device_item.model == "Virtual Disk": self.logger.log(msg="model is virtual disk") device_item.type = "disk" if device_item.type != "disk": partition_files = glob.glob("/sys/block/*/" + device_item.name + "/partition") self.logger.log(msg="partition files exists") if partition_files is not None and len(partition_files) > 0: device_item.type = "part" return device_items
def get_device_items_sles(self,dev_path): self.logger.log("get_device_items_sles : getting the blk info from " + str(dev_path), True) device_items = [] #first get all the device names if(dev_path is None): get_device_cmd = self.patching.lsblk_path + " -b -nl -o NAME" else: get_device_cmd = self.patching.lsblk_path + " -b -nl -o NAME " + dev_path get_device_cmd_args = shlex.split(get_device_cmd) p = Popen(get_device_cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) lines = out_lsblk_output.splitlines() for i in range(0,len(lines)): item_value_str = lines[i].strip() if(item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() device_item.name = disk_info_item_array[0] device_items.append(device_item) for i in range(0,len(device_items)): device_item = device_items[i] device_item.file_system = self.get_device_items_property(lsblk_path=self.patching.lsblk_path,dev_name=device_item.name,property_name='FSTYPE') device_item.mount_point = self.get_device_items_property(lsblk_path=self.patching.lsblk_path,dev_name=device_item.name,property_name='MOUNTPOINT') device_item.label = self.get_device_items_property(lsblk_path=self.patching.lsblk_path,dev_name=device_item.name,property_name='LABEL') device_item.uuid = self.get_device_items_property(lsblk_path=self.patching.lsblk_path,dev_name=device_item.name,property_name='UUID') #get the type of device model_file_path = '/sys/block/' + device_item.name + '/device/model' if(os.path.exists(model_file_path)): with open(model_file_path,'r') as f: device_item.model = f.read().strip() if(device_item.model == 'Virtual Disk'): self.logger.log("model is virtual disk", True) device_item.type = 'disk' if(device_item.type != 'disk'): partition_files = glob.glob('/sys/block/*/' + device_item.name + '/partition') if(partition_files is not None and len(partition_files) > 0): self.logger.log("partition files exists", True) device_item.type = 'part' return device_items
def get_device_items(self, dev_path): if (self.patching.distro_info[0].lower() == 'suse' and self.patching.distro_info[1] == '11'): return self.get_device_items_sles(dev_path) else: self.logger.log("getting the blk info from " + str(dev_path), True) device_items = [] try: if (dev_path is None): p = Popen([ self.patching.lsblk_path, '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen([ self.patching.lsblk_path, '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE', dev_path ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except Exception as e: if (self.patching.distro_info[0].lower() == 'centos' or self.patching.distro_info[0].lower() == 'redhat'): if self.patching.usr_flag == 1: self.logger.log( "lsblk path is wrong.removing /usr prefix", True, 'Warning') if (dev_path is None): p = Popen([ "/bin/lsblk", '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen([ "/bin/lsblk", '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE', dev_path ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: self.logger.log( "lsblk path is wrong.Adding /usr prefix", True, 'Warning') if (dev_path is None): p = Popen([ "usr/bin/lsblk", '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen([ "usr/bin/lsblk", '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE', dev_path ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: raise Exception("lsblk path is wrong") out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) error_msg = str(err) if (error_msg is not None and error_msg.strip() != ""): self.logger.log(str(err), True) lines = out_lsblk_output.splitlines() for i in range(0, len(lines)): item_value_str = lines[i].strip() if (item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split('=') if (property_item_pair[0] == 'NAME'): device_item.name = property_item_pair[1].strip('"') if (property_item_pair[0] == 'TYPE'): device_item.type = property_item_pair[1].strip('"') if (property_item_pair[0] == 'FSTYPE'): device_item.file_system = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'MOUNTPOINT'): device_item.mount_point = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'LABEL'): device_item.label = property_item_pair[1].strip( '"') if (property_item_pair[0] == 'UUID'): device_item.uuid = property_item_pair[1].strip('"') if (property_item_pair[0] == 'MODEL'): device_item.model = property_item_pair[1].strip( '"') self.logger.log( "lsblk command mount :" + str(device_item.mount_point) + ":", True) if (device_item.mount_point is not None and device_item.mount_point != "" and device_item.mount_point != " "): device_items.append(device_item) return device_items
def get_device_items(self, dev_path): if (self.patching.distro_info[0].lower() == 'suse' and self.patching.distro_info[1] == '11'): return self.get_device_items_sles(dev_path) else: self.logger.log("getting the blk info from " + str(dev_path), True) device_items = [] lsblk_path = self.patching.lsblk_path # Get lsblk command output using lsblk_path as self.patching.lsblk_path is_lsblk_path_wrong, out_lsblk_output, error_msg = self.get_lsblk_pairs_output( lsblk_path, dev_path) # if lsblk_path was wrong, use /bin/lsblk or usr/bin/lsblk based on self.patching.usr_flag to get lsblk command output again for centos/redhat distros if (is_lsblk_path_wrong == True) and ( self.patching.distro_info[0].lower() == 'centos' or self.patching.distro_info[0].lower() == 'redhat'): if self.patching.usr_flag == 1: self.logger.log( "lsblk path is wrong, removing /usr prefix", True, 'Warning') lsblk_path = "/bin/lsblk" else: self.logger.log("lsblk path is wrong, adding /usr prefix", True, 'Warning') lsblk_path = "/usr/bin/lsblk" is_lsblk_path_wrong, out_lsblk_output, error_msg = self.get_lsblk_pairs_output( lsblk_path, dev_path) # if lsblk_path was still wrong, lsblk_path using "which" command if (is_lsblk_path_wrong == True): self.logger.log( "lsblk path is wrong. finding path using which command", True, 'Warning') out_which_output, which_error_msg = self.get_which_command_result( 'lsblk') # get lsblk command output if (out_which_output is not None): lsblk_path = str(out_which_output) is_lsblk_path_wrong, out_lsblk_output, error_msg = self.get_lsblk_pairs_output( lsblk_path, dev_path) # if error_msg contains "invalid option", then get device_items using method get_device_items_from_lsblk_list if (error_msg is not None and error_msg.strip() != "" and 'invalid option' in error_msg): device_items = self.get_device_items_from_lsblk_list( lsblk_path, dev_path) # else get device_items from parsing the lsblk command output elif (out_lsblk_output is not None): lines = out_lsblk_output.splitlines() for i in range(0, len(lines)): item_value_str = lines[i].strip() if (item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split('=') if (property_item_pair[0] == 'NAME'): device_item.name = property_item_pair[1].strip( '"') if (property_item_pair[0] == 'TYPE'): device_item.type = property_item_pair[1].strip( '"') if (property_item_pair[0] == 'FSTYPE'): device_item.file_system = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'MOUNTPOINT'): device_item.mount_point = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'LABEL'): device_item.label = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'UUID'): device_item.uuid = property_item_pair[1].strip( '"') if (property_item_pair[0] == 'MODEL'): device_item.model = property_item_pair[ 1].strip('"') self.logger.log( "lsblk MOUNTPOINT=" + str(device_item.mount_point) + ", NAME=" + str(device_item.name) + ", TYPE=" + str(device_item.type) + ", FSTYPE=" + str(device_item.file_system) + ", LABEL=" + str(device_item.label) + ", UUID=" + str(device_item.uuid) + ", MODEL=" + str(device_item.model), True) if (device_item.mount_point is not None and device_item.mount_point != "" and device_item.mount_point != " "): device_items.append(device_item) return device_items
def get_device_items(self, dev_path): if(self.patching.distro_info[0].lower() == 'suse' and self.patching.distro_info[1] == '11'): return self.get_device_items_sles(dev_path) else: self.logger.log("getting the blk info from " + str(dev_path), True) device_items = [] lsblk_path = self.patching.lsblk_path # Get lsblk command output using lsblk_path as self.patching.lsblk_path is_lsblk_path_wrong, out_lsblk_output, error_msg = self.get_lsblk_pairs_output(lsblk_path, dev_path) # if lsblk_path was wrong, use /bin/lsblk or usr/bin/lsblk based on self.patching.usr_flag to get lsblk command output again for centos/redhat distros if (is_lsblk_path_wrong == True) and (self.patching.distro_info[0].lower() == 'centos' or self.patching.distro_info[0].lower() == 'redhat'): if self.patching.usr_flag == 1: self.logger.log("lsblk path is wrong, removing /usr prefix", True, 'Warning') lsblk_path = "/bin/lsblk" else: self.logger.log("lsblk path is wrong, adding /usr prefix", True, 'Warning') lsblk_path = "/usr/bin/lsblk" is_lsblk_path_wrong, out_lsblk_output, error_msg = self.get_lsblk_pairs_output(lsblk_path, dev_path) # if lsblk_path was still wrong, lsblk_path using "which" command if (is_lsblk_path_wrong == True): self.logger.log("lsblk path is wrong. finding path using which command", True, 'Warning') out_which_output, which_error_msg = self.get_which_command_result('lsblk') # get lsblk command output if (out_which_output is not None): lsblk_path = str(out_which_output) is_lsblk_path_wrong, out_lsblk_output, error_msg = self.get_lsblk_pairs_output(lsblk_path, dev_path) # if error_msg contains "invalid option", then get device_items using method get_device_items_from_lsblk_list if (error_msg is not None and error_msg.strip() != "" and 'invalid option' in error_msg): device_items = self.get_device_items_from_lsblk_list(lsblk_path, dev_path) # else get device_items from parsing the lsblk command output elif (out_lsblk_output is not None): lines = out_lsblk_output.splitlines() for i in range(0,len(lines)): item_value_str = lines[i].strip() if(item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split('=') if(property_item_pair[0] == 'NAME'): device_item.name = property_item_pair[1].strip('"') if(property_item_pair[0] == 'TYPE'): device_item.type = property_item_pair[1].strip('"') if(property_item_pair[0] == 'FSTYPE'): device_item.file_system = property_item_pair[1].strip('"') if(property_item_pair[0] == 'MOUNTPOINT'): device_item.mount_point = property_item_pair[1].strip('"') if(property_item_pair[0] == 'LABEL'): device_item.label = property_item_pair[1].strip('"') if(property_item_pair[0] == 'UUID'): device_item.uuid = property_item_pair[1].strip('"') if(property_item_pair[0] == 'MODEL'): device_item.model = property_item_pair[1].strip('"') self.logger.log("lsblk MOUNTPOINT=" + str(device_item.mount_point) + ", NAME=" + str(device_item.name) + ", TYPE=" + str(device_item.type) + ", FSTYPE=" + str(device_item.file_system) + ", LABEL=" + str(device_item.label) + ", UUID=" + str(device_item.uuid) + ", MODEL=" + str(device_item.model), True) if(device_item.mount_point is not None and device_item.mount_point != "" and device_item.mount_point != " "): device_items.append(device_item) return device_items
def get_device_items(self, dev_path): if (self.patching.distro_info[0].lower() == 'suse' and self.patching.distro_info[1] == '11'): return self.get_device_items_sles(dev_path) else: self.logger.log(msg=("getting the blk info from " + str(dev_path))) device_items = [] if (dev_path is None): p = Popen([ self.patching.lsblk_path, '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen([ self.patching.lsblk_path, '-b', '-n', '-P', '-o', 'NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE', dev_path ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) error_msg = str(err) if (error_msg is not None and error_msg.strip() != ""): self.logger.log(msg=str(err), level=CommonVariables.ErrorLevel) lines = out_lsblk_output.splitlines() for i in range(0, len(lines)): item_value_str = lines[i].strip() if (item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split('=') if (property_item_pair[0] == 'NAME'): device_item.name = property_item_pair[1].strip('"') if (property_item_pair[0] == 'TYPE'): device_item.type = property_item_pair[1].strip('"') if (property_item_pair[0] == 'FSTYPE'): device_item.file_system = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'MOUNTPOINT'): device_item.mount_point = property_item_pair[ 1].strip('"') if (property_item_pair[0] == 'LABEL'): device_item.label = property_item_pair[1].strip( '"') if (property_item_pair[0] == 'UUID'): device_item.uuid = property_item_pair[1].strip('"') if (property_item_pair[0] == 'MODEL'): device_item.model = property_item_pair[1].strip( '"') device_items.append(device_item) return device_items
def get_device_items(self, dev_path): if self.patching.distro_info[0].lower() == "suse" and self.patching.distro_info[1] == "11": return self.get_device_items_sles(dev_path) else: self.logger.log(msg=("getting the blk info from " + str(dev_path))) device_items = [] if dev_path is None: p = Popen( [ self.patching.lsblk_path, "-b", "-n", "-P", "-o", "NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE", ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) else: p = Popen( [ self.patching.lsblk_path, "-b", "-n", "-P", "-o", "NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE", dev_path, ], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) error_msg = str(err) if error_msg is not None and error_msg.strip() != "": self.logger.log(msg=str(err), level=CommonVariables.ErrorLevel) lines = out_lsblk_output.splitlines() for i in range(0, len(lines)): item_value_str = lines[i].strip() if item_value_str != "": disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split("=") if property_item_pair[0] == "NAME": device_item.name = property_item_pair[1].strip('"') if property_item_pair[0] == "TYPE": device_item.type = property_item_pair[1].strip('"') if property_item_pair[0] == "FSTYPE": device_item.file_system = property_item_pair[1].strip('"') if property_item_pair[0] == "MOUNTPOINT": device_item.mount_point = property_item_pair[1].strip('"') if property_item_pair[0] == "LABEL": device_item.label = property_item_pair[1].strip('"') if property_item_pair[0] == "UUID": device_item.uuid = property_item_pair[1].strip('"') if property_item_pair[0] == "MODEL": device_item.model = property_item_pair[1].strip('"') device_items.append(device_item) return device_items
def get_device_items(self, dev_path): if(self.patching.distro_info[0].lower() == 'suse' and self.patching.distro_info[1] == '11'): return self.get_device_items_sles(dev_path) else: self.logger.log(msg=("getting the blk info from " + str(dev_path))) device_items = [] try: if(dev_path is None): p = Popen([self.patching.lsblk_path, '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen([self.patching.lsblk_path, '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE',dev_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except Exception as e: if(self.patching.distro_info[0].lower() == 'centos' or self.patching.distro_info[0].lower() == 'redhat'): if self.patching.usr_flag == 1: self.logger.log("lsblk path is wrong.removing /usr prefix", False, 'Warning') if(dev_path is None): p = Popen(["/bin/lsblk", '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen(["/bin/lsblk", '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE',dev_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: self.logger.log("lsblk path is wrong.Adding /usr prefix", False, 'Warning') if(dev_path is None): p = Popen(["usr/bin/lsblk", '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: p = Popen(["usr/bin/lsblk", '-b', '-n','-P','-o','NAME,TYPE,FSTYPE,MOUNTPOINT,LABEL,UUID,MODEL,SIZE',dev_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: raise Exception("lsblk path is wrong") out_lsblk_output, err = p.communicate() out_lsblk_output = str(out_lsblk_output) error_msg = str(err) if(error_msg is not None and error_msg.strip() != ""): self.logger.log(msg=str(err)) lines = out_lsblk_output.splitlines() for i in range(0,len(lines)): item_value_str = lines[i].strip() if(item_value_str != ""): disk_info_item_array = item_value_str.split() device_item = DeviceItem() disk_info_item_array_length = len(disk_info_item_array) for j in range(0, disk_info_item_array_length): disk_info_property = disk_info_item_array[j] property_item_pair = disk_info_property.split('=') if(property_item_pair[0] == 'NAME'): device_item.name = property_item_pair[1].strip('"') if(property_item_pair[0] == 'TYPE'): device_item.type = property_item_pair[1].strip('"') if(property_item_pair[0] == 'FSTYPE'): device_item.file_system = property_item_pair[1].strip('"') if(property_item_pair[0] == 'MOUNTPOINT'): device_item.mount_point = property_item_pair[1].strip('"') if(property_item_pair[0] == 'LABEL'): device_item.label = property_item_pair[1].strip('"') if(property_item_pair[0] == 'UUID'): device_item.uuid = property_item_pair[1].strip('"') if(property_item_pair[0] == 'MODEL'): device_item.model = property_item_pair[1].strip('"') device_items.append(device_item) return device_items