示例#1
0
文件: diskutil.py 项目: xtha/pxe
def attach_rfc4173(iname, rfc4173_spec):
    """ Attach a disk given an initiator name, and spec in the following format:
     "iscsi:"<targetip>":"<protocol>":"<port>":"<LUN>":"<targetname>

     return disk, e.g. "/dev/sdb"
    """
    try:
        parts = rfc4173_spec.split(':',5)
        assert(parts[0] == "iscsi")
        targetip = parts[1]
        port = parts[3]
        lun = parts[4] and int(parts[4]) or 0        
        iqn = parts[5]
    except:
        raise IscsiDeviceException, "Cannot parse spec %s" % rfc4173_spec
    
    if port:
        targetip += ':%s' % port

    # Attach to disk
    if not os.path.exists("/etc/iscsi/initiatorname.iscsi"):
        rv, iname = util.runCmd2([ '/sbin/iscsi-iname' ], with_stdout=True)
        if rv:
            raise RuntimeError, "/sbin/iscsi-iname failed"
        open("/etc/iscsi/initiatorname.iscsi","w").write("InitiatorName=%s"  % iname)

    rv = util.runCmd2([ '/sbin/modprobe', 'iscsi_tcp' ])
    if rv:
        raise RuntimeError, "/sbin/modprobe iscsi_tcp failed"
    try:
        if not util.pidof('iscsid'):
            fd = open("/etc/iscsi/initiatorname.iscsi", "w")
            fd.write("InitiatorName=%s" % iname)
            fd.close()
            rv = util.runCmd2([ '/sbin/iscsid' ])          # start iscsiadm
            if rv:
                raise RuntimeError, "/sbin/iscsid failed"
        rv = util.runCmd2([ '/sbin/iscsiadm', '-m', 'discovery', '-t', 'sendtargets', '-p', targetip])
        if rv: 
            raise RuntimeError, "/sbin/iscsiadm -m discovery failed"
        rv = util.runCmd2([ '/sbin/iscsiadm', '-m', 'node', '-T', iqn, '-p', targetip, '-l']) # login
        if rv:
            raise RuntimeError, "/sbin/iscsiadm -m node -l failed"
    finally:
        util.runCmd2([ '/sbin/udevsettle' ])           # update /dev

    disk = rfc4173_to_disk(rfc4173_spec)
    iscsi_disks.append(disk)

    return disk
示例#2
0
def attach_rfc4173(iname, rfc4173_spec):
    """ Attach a disk given an initiator name, and spec in the following format:
     "iscsi:"<targetip>":"<protocol>":"<port>":"<LUN>":"<targetname>

     return disk, e.g. "/dev/sdb"
    """
    try:
        parts = rfc4173_spec.split(':',5)
        assert(parts[0] == "iscsi")
        targetip = parts[1]
        port = parts[3]
        lun = parts[4] and int(parts[4]) or 0        
        iqn = parts[5]
    except:
        raise IscsiDeviceException, "Cannot parse spec %s" % rfc4173_spec
    
    if port:
        targetip += ':%s' % port

    # Attach to disk
    if not os.path.exists("/etc/iscsi/initiatorname.iscsi"):
        open("/etc/iscsi/initiatorname.iscsi","w").write("InitiatorName=%s"  % iname)

    rv = util.runCmd2([ '/sbin/modprobe', 'iscsi_tcp' ])
    if rv:
        raise RuntimeError, "/sbin/modprobe iscsi_tcp failed"
    try:
        if not util.pidof('iscsid'):
            fd = open("/etc/iscsi/initiatorname.iscsi", "w")
            fd.write("InitiatorName=%s" % iname)
            fd.close()
        rv = util.runCmd2([ '/sbin/iscsiadm', '-m', 'discovery', '-t', 'sendtargets', '-p', targetip])
        if rv: 
            raise RuntimeError, "/sbin/iscsiadm -m discovery failed"
        rv = util.runCmd2([ '/sbin/iscsiadm', '-m', 'node', '-T', iqn, '-p', targetip, '-l']) # login
        if rv:
            raise RuntimeError, "/sbin/iscsiadm -m node -l failed"
    finally:
        util.runCmd2(util.udevsettleCmd())           # update /dev

    disk = rfc4173_to_disk(rfc4173_spec)
    iscsi_disks.append(disk)

    return disk
示例#3
0
def release_ibft_disks():
    if util.pidof('iscsid'):
        util.runCmd2([ '/sbin/iscsiadm', '-m', 'session', '-u'])
        util.runCmd2([ '/sbin/iscsiadm', '-k', '0'])
        iscsi_disks = []
示例#4
0
文件: diskutil.py 项目: xtha/pxe
def release_ibft_disks():
    if util.pidof('iscsid'):
        util.runCmd2([ '/sbin/iscsiadm', '-m', 'session', '-u'])
        util.runCmd2([ '/sbin/iscsiadm', '-k', '0'])
        iscsi_disks = []