コード例 #1
0
ファイル: OCFSoISCSISR.py プロジェクト: pritha-srivastava/sm
    def create(self, sr_uuid, size):
        # Check SCSIid not already in use by other PBDs
        if util.test_SCSIid(self.session, sr_uuid, self.SCSIid):
            raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(sr_uuid)
        try:
            if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                # UPGRADE FROM GEORGE: take care of ill-formed SCSIid
                upgraded = False
                matchSCSIid = False
                for file in filter(self.iscsi.match_lun,
                                   util.listdir(self.iscsi.path)):
                    path = os.path.join(self.iscsi.path, file)
                    if not util.wait_for_path(path, ISCSISR.MAX_TIMEOUT):
                        util.SMlog(
                            "Unable to detect LUN attached to host [%s]" %
                            path)
                        continue
                    try:
                        SCSIid = scsiutil.getSCSIid(path)
                    except:
                        continue
                    try:
                        matchSCSIid = scsiutil.compareSCSIid_2_6_18(
                            self.SCSIid, path)
                    except:
                        continue
                    if (matchSCSIid):
                        util.SMlog("Performing upgrade from George")
                        try:
                            pbd = util.find_my_pbd(self.session, self.host_ref,
                                                   self.sr_ref)
                            device_config = self.session.xenapi.PBD.get_device_config(
                                pbd)
                            device_config['SCSIid'] = SCSIid
                            self.session.xenapi.PBD.set_device_config(
                                pbd, device_config)

                            self.dconf['SCSIid'] = SCSIid
                            self.SCSIid = self.dconf['SCSIid']
                        except:
                            continue
                        if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                            raise xs_errors.XenError('InvalidDev')
                        else:
                            upgraded = True
                            break
                    else:
                        util.SMlog(
                            "Not a matching LUN, skip ... scsi_id is: %s" %
                            SCSIid)
                        continue
                if not upgraded:
                    raise xs_errors.XenError('InvalidDev')
            self._pathrefresh(OCFSoISCSISR)
            OCFSSR.OCFSSR.create(self, sr_uuid, size)
        except Exception, inst:
            self.iscsi.detach(sr_uuid)
            raise xs_errors.XenError("SRUnavailable", opterr=inst)
コード例 #2
0
ファイル: LVHDoISCSISR.py プロジェクト: pritha-srivastava/sm
    def create(self, sr_uuid, size):
        # Check SCSIid not already in use by other PBDs
        if util.test_SCSIid(self.session, sr_uuid, self.SCSIid):
            raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(sr_uuid)
        try:
            if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                # UPGRADE FROM GEORGE: take care of ill-formed SCSIid
                upgraded = False
                matchSCSIid = False
                for file in filter(self.iscsi.match_lun, util.listdir(self.iscsi.path)):
                    path = os.path.join(self.iscsi.path,file)
                    if not util.wait_for_path(path, ISCSISR.MAX_TIMEOUT):
                        util.SMlog("Unable to detect LUN attached to host [%s]" % path)
                        continue
                    try:
                        SCSIid = scsiutil.getSCSIid(path)
                    except:
                        continue
                    try:
                        matchSCSIid = scsiutil.compareSCSIid_2_6_18(self.SCSIid, path)
                    except:
                        continue
                    if (matchSCSIid):
                        util.SMlog("Performing upgrade from George")
                        try:
                            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
                            device_config = self.session.xenapi.PBD.get_device_config(pbd)
                            device_config['SCSIid'] = SCSIid
                            self.session.xenapi.PBD.set_device_config(pbd, device_config)

                            self.dconf['SCSIid'] = SCSIid            
                            self.SCSIid = self.dconf['SCSIid']
                        except:
                            continue
                        if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                            raise xs_errors.XenError('InvalidDev')
                        else:
                            upgraded = True
                            break
                    else:
                        util.SMlog("Not a matching LUN, skip ... scsi_id is: %s" % SCSIid)
                        continue
                if not upgraded:
                    raise xs_errors.XenError('InvalidDev')
            self._pathrefresh(LVHDoISCSISR)
            LVHDSR.LVHDSR.create(self, sr_uuid, size)
        except Exception, inst:
            self.iscsi.detach(sr_uuid)
            raise xs_errors.XenError("SRUnavailable", opterr=inst)
コード例 #3
0
    def create(self, sr_uuid, size):
        # Check SCSIid not already in use by other PBDs
        if util.test_SCSIid(self.session, self.SCSIid):
            raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(sr_uuid)
        try:
            if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                raise xs_errors.XenError('InvalidDev')
            self._pathrefresh(LVMoISCSISR)
            super(LVMoISCSISR, self).create(sr_uuid, size)
        except Exception, inst:
            self.iscsi.detach(sr_uuid)
            raise xs_errors.XenError("SRUnavailable", opterr=inst)
コード例 #4
0
    def create(self, sr_uuid, size):
        # Check SCSIid not already in use by other PBDs
        if util.test_SCSIid(self.session, self.SCSIid):
            raise xs_errors.XenError('SRInUse')

        self.iscsi.attach(sr_uuid)
        try:
            if not self.iscsi._attach_LUN_bySCSIid(self.SCSIid):
                raise xs_errors.XenError('InvalidDev')
            self._pathrefresh(LVMoISCSISR)
            super(LVMoISCSISR, self).create(sr_uuid, size)
        except Exception, inst:
            self.iscsi.detach(sr_uuid)
            raise xs_errors.XenError("SRUnavailable", opterr=inst)
コード例 #5
0
    def _loadvdis(self):
        if self.cmd not in NEEDS_LOADVDIS:
            return 0
        if self.vdis:
            return

        self._init_hbadict()
        count = 0
        self.physical_size = 0
        root_dev_id = util.getrootdevID()

        xapi_session = self.session.xenapi
        known_scsid = {}  # dict of ids processed within the following loop

        for key in self.hbadict.iterkeys():

            # We need a fresh sm_config everytime because it is modified
            # inside this loop
            sm_config = xapi_session.SR.get_sm_config(self.sr_ref)

            # The way we create vdi_path and the following check are
            # not clear at all
            vdi_path = os.path.join("/dev", key)
            if vdi_path not in self.devs:
                continue

            scsi_id = scsiutil.getSCSIid(vdi_path)
            if scsi_id == root_dev_id:
                util.SMlog("Skipping root device %s" % scsi_id)
                continue

            # Avoid false positives: this SR can already contain this
            # SCSIid during scan.
            scsi_key = "scsi-" + scsi_id
            if scsi_key in sm_config:
                # if we know about this scsid we can skip this specific dev
                if scsi_key in known_scsid:
                    util.SMlog("This SCSI id (%s) is already added" % scsi_id)
                    continue
                else:
                    # marked as known to avoid adding it again to sm_config
                    known_scsid[scsi_key] = ""
            elif util.test_SCSIid(self.session, None, scsi_id):
                util.SMlog("This SCSI id (%s) is used by another SR" % scsi_id)
                continue

            # getuniqueserial invokes again getSCSIid -> Fix!
            uuid = scsiutil.gen_uuid_from_string(
                scsiutil.getuniqueserial(vdi_path))
            # We could have checked the SCSIid but the dictionary has
            # uuid as key.
            # We have already checked known_scsid, though. This block is
            # supposed to be always False
            if uuid in self.vdis:
                util.SMlog("Warning: unexpected code block reached with"
                           " uuid = %s" % scsi_id)
                continue

            obj = self.vdi(uuid)
            path = self.mpathmodule.path(scsi_id)
            ids = self.devs[vdi_path]
            obj._query(vdi_path, ids[4], uuid, scsi_id)
            self.vdis[uuid] = obj
            self.physical_size += obj.size

            count += 1

            # If we know about it no need to add to sm_config
            if scsi_key in known_scsid:
                continue

            # Prepare multipathing and make the other SRs know this SCSIid
            # is reserved.
            # Its counterpart is vdi_delete
            try:
                xapi_session.SR.add_to_sm_config(self.sr_ref, scsi_key, uuid)
                known_scsid[scsi_key] = ""
            except:
                util.SMlog("Warning: add_to_sm_config failed unexpectedly")

        return count
コード例 #6
0
def scan(srobj):
    systemrootID = util.getrootdevID()
    hbadict = srobj.hbadict
    hbas = srobj.hbas
    dom = xml.dom.minidom.Document()
    e = dom.createElement("Devlist")
    dom.appendChild(e)

    if not os.path.exists(DEVPATH):
        return dom.toprettyxml()
    
    devs = srobj.devs
    vdis = {}

    for key in hbadict:
        hba = hbadict[key]
        path = os.path.join("/dev",key)
        realpath = path

        obj = srobj.vdi("")
        try:
            obj._query(realpath, devs[realpath][4])
        except:
            continue
        
        # Test for root dev or existing PBD
        if len(obj.SCSIid) and len(systemrootID) and util.match_scsiID(obj.SCSIid, systemrootID):
            util.SMlog("Ignoring root device %s" % realpath)
            continue
        elif util.test_SCSIid(srobj.session, None, obj.SCSIid):
            util.SMlog("SCSIid in use, ignoring (%s)" % obj.SCSIid)
            continue
        elif not devs.has_key(realpath):
            continue
        
        ids = devs[realpath]
        obj.adapter = ids[1]
        obj.channel = ids[2]
        obj.id = ids[3]
        obj.lun = ids[4]
        obj.hba = hba['procname']
        obj.numpaths = 1
        if vdis.has_key(obj.SCSIid):
            vdis[obj.SCSIid].numpaths += 1
            vdis[obj.SCSIid].path += " [%s]" % key
        elif obj.hba == 'mpp':
            mppdict = _genMPPHBA(obj.adapter)
            if mppdict.has_key(key):
                item = mppdict[key]
                adapters = ''
                for i in item:
                    if len(adapters):
                        adapters += ', '
                        obj.numpaths += 1
                    adapters += i
                if len(adapters):
                    obj.mpp = adapters
            vdis[obj.SCSIid] = obj
        else:    
            vdis[obj.SCSIid] = obj
                    
    for key in vdis:
        obj = vdis[key]
        d = dom.createElement("BlockDevice")
        e.appendChild(d)

        for attr in ['path','numpaths','SCSIid','vendor','serial','size','adapter','channel','id','lun','hba','mpp']:
            try:
                aval = getattr(obj, attr)
            except AttributeError:
                if attr in ['mpp']:
                    continue
                raise xs_errors.XenError('InvalidArg', \
                      opterr='Missing required field [%s]' % attr)
            entry = dom.createElement(attr)
            d.appendChild(entry)
            textnode = dom.createTextNode(str(aval))
            entry.appendChild(textnode)

    for key in hbas.iterkeys():
        a = dom.createElement("Adapter")
        e.appendChild(a)
        entry = dom.createElement('host')
        a.appendChild(entry)
        textnode = dom.createTextNode(key)
        entry.appendChild(textnode)

        entry = dom.createElement('name')
        a.appendChild(entry)
        textnode = dom.createTextNode(hbas[key])
        entry.appendChild(textnode)

        entry = dom.createElement('manufacturer')
        a.appendChild(entry)
        textnode = dom.createTextNode(getManufacturer(hbas[key]))
        entry.appendChild(textnode)

        id = key.replace("host","")
        entry = dom.createElement('id')
        a.appendChild(entry)
        textnode = dom.createTextNode(id)
        entry.appendChild(textnode)

        _add_host_parameters_to_adapter(dom, a, 'fc_host', id,
                                        ['node_name', 'port_name',
                                         'port_state', 'speed',
                                         'supported_speeds'])
        _add_host_parameters_to_adapter(dom, a, 'iscsi_host', id,
                                        ['hwaddress', 'initiatorname',
                                         'ipaddress', 'port_speed',
                                         'port_state'])

    return dom.toprettyxml()
コード例 #7
0
ファイル: RawHBASR.py プロジェクト: BobBall/sm
    def _loadvdis(self):
        if self.cmd not in NEEDS_LOADVDIS:
            return 0
        if self.vdis:
            return

        self._init_hbadict()
        count = 0
        self.physical_size = 0
        root_dev_id = util.getrootdevID()

        xapi_session = self.session.xenapi
        known_scsid = {} # dict of ids processed within the following loop

        for key in self.hbadict.iterkeys():

            # We need a fresh sm_config everytime because it is modified
            # inside this loop
            sm_config = xapi_session.SR.get_sm_config(self.sr_ref)

            # The way we create vdi_path and the following check are
            # not clear at all
            vdi_path = os.path.join("/dev",key)
            if not self.devs.has_key(vdi_path):
                continue

            scsi_id = scsiutil.getSCSIid(vdi_path)
            if scsi_id == root_dev_id:
                util.SMlog("Skipping root device %s" %scsi_id)
                continue

            # Avoid false positives: this SR can already contain this
            # SCSIid during scan.
            scsi_key = "scsi-" + scsi_id
            if sm_config.has_key(scsi_key):
                # if we know about this scsid we can skip this specific dev
                if known_scsid.has_key(scsi_key):
                    util.SMlog("This SCSI id (%s) is already added" %scsi_id)
                    continue
                else:
                    # marked as known to avoid adding it again to sm_config
                    known_scsid[scsi_key] = ""
            elif util.test_SCSIid(self.session, None, scsi_id):
                util.SMlog("This SCSI id (%s) is used by another SR" %scsi_id)
                continue

            # getuniqueserial invokes again getSCSIid -> Fix!
            uuid = scsiutil.gen_uuid_from_string(
                scsiutil.getuniqueserial(vdi_path)
                )
            # We could have checked the SCSIid but the dictionary has
            # uuid as key.
            # We have already checked known_scsid, though. This block is
            # supposed to be always False
            if self.vdis.has_key(uuid):
                util.SMlog("Warning: unexpected code block reached with"
                           " uuid = %s" %scsi_id)
                continue

            obj = self.vdi(uuid)
            path = self.mpathmodule.path(scsi_id)
            ids = self.devs[vdi_path]
            obj._query(vdi_path, ids[4], uuid, scsi_id)
            self.vdis[uuid] = obj
            self.physical_size += obj.size

            count += 1

            # If we know about it no need to add to sm_config
            if known_scsid.has_key(scsi_key):
                continue

            # Prepare multipathing and make the other SRs know this SCSIid
            # is reserved.
            # Its counterpart is vdi_delete
            try:
                xapi_session.SR.add_to_sm_config(self.sr_ref, scsi_key, uuid)
                known_scsid[scsi_key] = ""
            except:
                util.SMlog("Warning: add_to_sm_config failed unexpectedly")

        return count
コード例 #8
0
ファイル: devscan.py プロジェクト: GaryKirkpatrick/sm
def scan(srobj):
    systemrootID = util.getrootdevID()
    hbadict = srobj.hbadict
    hbas = srobj.hbas
    dom = xml.dom.minidom.Document()
    e = dom.createElement("Devlist")
    dom.appendChild(e)

    if not os.path.exists(DEVPATH):
        return dom.toprettyxml()

    devs = srobj.devs
    vdis = {}

    for key in hbadict:
        hba = hbadict[key]
        path = os.path.join("/dev", key)
        realpath = path

        obj = srobj.vdi("")
        try:
            obj._query(realpath, devs[realpath][4])
        except:
            continue

        # Test for root dev or existing PBD
        if len(obj.SCSIid) and len(systemrootID) and util.match_scsiID(obj.SCSIid, systemrootID):
            util.SMlog("Ignoring root device %s" % realpath)
            continue
        elif util.test_SCSIid(srobj.session, None, obj.SCSIid):
            util.SMlog("SCSIid in use, ignoring (%s)" % obj.SCSIid)
            continue
        elif not devs.has_key(realpath):
            continue

        ids = devs[realpath]
        obj.adapter = ids[1]
        obj.channel = ids[2]
        obj.id = ids[3]
        obj.lun = ids[4]
        obj.hba = hba["procname"]
        obj.numpaths = 1
        if vdis.has_key(obj.SCSIid):
            vdis[obj.SCSIid].numpaths += 1
            vdis[obj.SCSIid].path += " [%s]" % key
        elif obj.hba == "mpp":
            mppdict = _genMPPHBA(obj.adapter)
            if mppdict.has_key(key):
                item = mppdict[key]
                adapters = ""
                for i in item:
                    if len(adapters):
                        adapters += ", "
                        obj.numpaths += 1
                    adapters += i
                if len(adapters):
                    obj.mpp = adapters
            vdis[obj.SCSIid] = obj
        else:
            vdis[obj.SCSIid] = obj

    for key in vdis:
        obj = vdis[key]
        d = dom.createElement("BlockDevice")
        e.appendChild(d)

        for attr in [
            "path",
            "numpaths",
            "SCSIid",
            "vendor",
            "serial",
            "size",
            "adapter",
            "channel",
            "id",
            "lun",
            "hba",
            "mpp",
        ]:
            try:
                aval = getattr(obj, attr)
            except AttributeError:
                if attr in ["mpp"]:
                    continue
                raise xs_errors.XenError("InvalidArg", opterr="Missing required field [%s]" % attr)
            entry = dom.createElement(attr)
            d.appendChild(entry)
            textnode = dom.createTextNode(str(aval))
            entry.appendChild(textnode)

    for key in hbas.iterkeys():
        a = dom.createElement("Adapter")
        e.appendChild(a)
        entry = dom.createElement("host")
        a.appendChild(entry)
        textnode = dom.createTextNode(key)
        entry.appendChild(textnode)

        entry = dom.createElement("name")
        a.appendChild(entry)
        textnode = dom.createTextNode(hbas[key])
        entry.appendChild(textnode)

        entry = dom.createElement("manufacturer")
        a.appendChild(entry)
        textnode = dom.createTextNode(getManufacturer(hbas[key]))
        entry.appendChild(textnode)

        id = key.replace("host", "")
        entry = dom.createElement("id")
        a.appendChild(entry)
        textnode = dom.createTextNode(id)
        entry.appendChild(textnode)

    return dom.toprettyxml()