def loginIscsiTarget(paths): def have_devices(): return all(map(os.path.exists, paths)) if have_devices(): logger.debug("loginIscsiTarget: nothing to do") return pdskid_str = extract_pdskid_from_iscsi_path(paths[0]) iqn = "iqn.%s:%s" % (iqn_prefix_iscsi, pdskid_str) def login(path): ip_str = extract_ip_from_iscsi_path(path) logger.debug("iscsi new: iqn %s portal %s path %s" % (iqn, ip_str, path)) assert pdskid_str == extract_pdskid_from_iscsi_path(path) executeiscsiadm("iscsiadm -m node -o new -T %s -p %s" % (iqn, ip_str)) map(login, paths) logger.debug("iscsi login: iqn %s" % iqn) command = "iscsiadm -m node -T %s --login" % iqn def condition(): return not have_devices() executecommand_retry(command, condition, ISCSIADM_RETRY_TIMES) time_left = LOGIN_TIMEOUT while not have_devices() and time_left > 0: time_left -= 1 time.sleep(1) map(getMultiPathDevice, paths)
def getMultiPathDevice(dev_disk_by_path): # input: /dev/disk/by-path/ip-10.100.10.3:3260-iscsi-iqn.2000-11.jp.co.valinux:00000006-lun-1 # output: /dev/mapper/mpath5 dev_path = "" # iSCSI device path --> wwid wwid = "" command = "scsi_id -g -u /dev/%s" % os.path.realpath(dev_disk_by_path).split("/dev/")[1] def condition(): return os.path.exists(dev_disk_by_path) wwid = executecommand_retry(command, condition, SCSI_ID_RETRY_TIMES) # wwid --> Multipath device path dev_name = "" for i in range(0, GETMULTIPATHDEVICE_RETRY_TIMES): try: executecommand("multipath") dev_name = executecommand("dmsetup info --noheadings -c -u mpath-%s -o name" % (wwid)) return getDmDevPath(dev_name) except: time.sleep(GETMULTIPATHDEVICE_RETRY_INTERVAL) logger.error("getMultiPathDevice: multipath -v3: %s", executecommand("multipath -v3")) raise Exception, "retry over"