Пример #1
0
def find_if_gfs2(impl, dbg, uri):
    srs = []
    dev_path = blkinfo.get_device_path(dbg, uri)
    unique_id = get_unique_id_from_dev_path(dev_path)
    if blkinfo.get_format(dbg, dev_path) == "LVM2_member":
        gfs2_dev_path = "/dev/" + unique_id + "/gfs2"
        # activate gfs2 LV
        cmd = ["/usr/sbin/lvchange", "-ay", unique_id + "/gfs2"]
        call(dbg, cmd)
        if blkinfo.get_format(dbg, gfs2_dev_path) == "gfs2":
            mount = False
            try: 
                mnt_path = getSRMountPath(dbg, gfs2_dev_path)
            except:
                #mount path doesn't exist
                mount = True
                mnt_path = mount_local(dbg, gfs2_dev_path)
            # stat takes sr_path which is 
            # file://<mnt_path>
            sr_path = "file://%s" % mnt_path
            srs.append(impl.stat(dbg, sr_path))
            if mount == True:
                umount(dbg, mnt_path)
                # deactivate gfs2 LV
                cmd = ["/usr/sbin/lvchange", "-an", unique_id + "/gfs2"]
                call(dbg, cmd)

    return srs
Пример #2
0
def getSRpath(dbg, uri, check=True):
    dev_path = blkinfo.get_device_path(dbg, uri)
    sr_path = os.path.abspath(mountpoint_root + dev_path)

    if check:
        if not(os.path.isdir(sr_path)) or not(os.path.ismount(sr_path)):
            raise xapi.storage.api.volume.Sr_not_attached(sr_path)
    return sr_path
Пример #3
0
def getPVName(dbg, sr):
    try:
        uri = getFromSRMetadata(dbg, sr, 'uri')
        dev_path = blkinfo.get_device_path(dbg, uri)
        cmd = ["readlink", "-f", dev_path]
        output = call(dbg, cmd)
        return output.rstrip()
    except Exception,e:
        log.debug("Exception raised in getting PV name: %s" %str(e))
Пример #4
0
def plug_device(dbg, uri):
    u = urlparse.urlparse(uri)     
    if u.scheme == 'iscsi':
        dev_path = libiscsi.zoneInLUN(dbg, uri)
    else: 
        # Assume it's a local block device
        dev_path = blkinfo.get_device_path(dbg, uri)

    if not(os.path.exists(dev_path)):
        raise xapi.storage.api.volume.Sr_not_attached(dev_path)
    return dev_path
Пример #5
0
    def probe(self, dbg, uri):
        srs = []
        uris = []

        u = urlparse.urlparse(uri)
        if u.scheme == None:
            raise xapi.storage.api.volume.SR_does_not_exist(
                  "The SR URI is invalid")

        if u.scheme == 'iscsi':
            object_map = []
            keys = libiscsi.decomposeISCSIuri(dbg, u)
            if keys['target'] == None:
                raise xapi.storage.api.volume.SR_does_not_exist(
                      "The SR URI is invalid")
            # uri has target but no IQN information
            # Return possible URI options by querying 
            # the target for IQN information
            if keys['iqn'] == None:
                iqn_map = libiscsi.discoverIQN(dbg, keys)
                if len(iqn_map) == 0:
                    raise xapi.storage.api.volume.SR_does_not_exist(
                          "No IQNs available at target")
                for record in iqn_map:
                    object_map.append(record[2])
            # uri has target and IQN but no LUN information
            # Return possible URI options by querying 
            # the target for LUN information
            elif keys['scsiid'] == None:
                try:
                    target_path = libiscsi.login(dbg, uri, keys)
                    lun_map = libiscsi.discoverLuns(dbg, target_path)
                finally: 
                    libiscsi.logout(dbg, uri, keys['iqn'])
                if len(lun_map) == 0:
                    raise xapi.storage.api.volume.SR_does_not_exist(
                          "No LUNs available at targetIQN")
                for record in lun_map:
                    object_map.append(record[4])
            # URI is complete. Find out if the underlying                
            # device is formatted using GFS2.
            else: 
                try: 
                    libiscsi.login(dbg, uri, keys)
                    dev_path = blkinfo.get_device_path(dbg, uri)
                    if blkinfo.get_format(dbg, dev_path) == "gfs2":
                        # Check if sr_path needs to be mounted
                        mnt_path = mount_local(dbg, dev_path)
                        srs.append(self.stat(dbg, uri))
                        # Unmount only if we mounted
                        umount(dbg, mnt_path)
                finally: 
                    libiscsi.logout(dbg, uri, keys['iqn'])
                    
            if len(object_map):
                for obj in object_map: 
                    new_uri = uri + "/" + obj
                    uris.append(new_uri)
        else:
            #HBA transport
            dev_path = blkinfo.get_device_path(dbg, uri)
            if blkinfo.get_format(dbg, dev_path) == "gfs2":
                mnt_path = mount_local(dbg, dev_path)
                srs.append(self.stat(dbg, uri))
                umount(dbg, mnt_path)

        return {
            "srs": srs,
            "uris": uris
        }