def __new__(cls, *args, **kwargs):
        """
        :param args:
        :param kwargs:
        :return:
        """
        if VERBOSE:
            util.SMlog("RBDSR.RBDSR_GC.__new__: args = %s, kwargs = %s" %
                       (str(args), str(kwargs)))

        sr_uuid = args[0]
        xapi = args[1]
        sr_ref = xapi.session.xenapi.SR.get_by_uuid(sr_uuid)

        host_ref = util.get_localhost_uuid(xapi.session)

        _PBD = xapi.session.xenapi.PBD
        pbds = _PBD.get_all_records_where('field "SR" = "%s" and' % sr_ref +
                                          'field "host" = "%s"' % host_ref)
        pbd_ref, pbd = pbds.popitem()
        assert not pbds

        device_config = _PBD.get_device_config(pbd_ref)

        if 'driver-type' in device_config:
            DRIVER_TYPE = device_config['driver-type']
        else:
            DRIVER_TYPE = DRIVER_TYPE_DEFAULT

        subtypeclass = "%sSR_GC" % DRIVER_CLASS_PREFIX[DRIVER_TYPE]
        return object.__new__(
            type('RBDSR_GC',
                 (RBDSR_GC, globals()[subtypeclass]) + RBDSR_GC.__bases__,
                 dict(RBDSR_GC.__dict__)), *args, **kwargs)
Example #2
0
def GetHBAInformation(session, storage_conf):
    try:
	retVal = True
	list = []
	scsiIdList = []
	device_config = {}
	HBAFilter = {}

	# Generate a map of the HBAs that the user want to test against.
	if storage_conf['adapters'] != None:
	    for hba in storage_conf['adapters'].split(','):
			HBAFilter[hba] = 1
	
	try:
	    session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmohba')
	except Exception, e:
	    XenCertPrint("Got the probe data as: %s" % str(e))
	    # Now extract the HBA information from this data.
	    try:
		# the target may not return any IQNs
		# so prepare for it
		xmlstr = extract_xml_from_exception(e)
		xmlstr = xmlstr.lstrip()
		xmlstr = xmlstr.lstrip('\'')
		xmlstr = xmlstr.rstrip()
		xmlstr = xmlstr.rstrip('\]')
		xmlstr = xmlstr.rstrip('\'')
		xmlstr = xmlstr.replace('\\n', '')
		xmlstr = xmlstr.replace('\\t', '')		
		XenCertPrint("Got the probe xml as: %s" % xmlstr)
		dom = xml.dom.minidom.parseString(xmlstr)
		TgtList = dom.getElementsByTagName("Adapter")
		for tgt in TgtList:
		    map = {}
		    for node in tgt.childNodes:
			    map[node.nodeName] = node.firstChild.nodeValue
		    if len(HBAFilter) != 0:
			    if HBAFilter.has_key(map['host']):
				    list.append(map)
		    else:
			    list.append(map)
		
		bdList = dom.getElementsByTagName("BlockDevice")
		for bd in bdList:
		    for node in bd.childNodes:
			    if node.nodeName == 'SCSIid':
				    SCSIid = node.firstChild.nodeValue
			    elif node.nodeName == 'adapter':
				    adapter = ''.join(["host",node.firstChild.nodeValue])

		    if len(HBAFilter) != 0:
			    if HBAFilter.has_key(adapter):
				    scsiIdList.append(SCSIid)
		    else:
			    scsiIdList.append(SCSIid)
	
		XenCertPrint("The HBA information list being returned is: %s" % list)
	    except Exception, e:
		XenCertPrint("Failed to parse lvmohba probe xml. Exception: %s" % str(e))
Example #3
0
def GetListPortalScsiIdForIqn(session, server, targetIqn, chapUser = None, chapPassword = None):
    try:
	listPortal = []
	listSCSIId= []
	device_config = {}
	device_config['target'] = server
	if chapUser != None and chapPassword != None:
	    device_config['chapuser'] = chapUser
	    device_config['chappassword'] = chapPassword

	try:
	    session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmoiscsi')
	except Exception, e:
	    XenCertPrint("Got the probe data as: %s" % str(e))
	    
	# Now extract the IQN list from this data.
	try:
	    # the target may not return any IQNs
	    # so prepare for it
	    items = str(e).split(',')
	    xmlstr = ''
	    for i in range(3,len(items)):
		xmlstr += items[i]
		xmlstr += ','
	    
	    #xmlstr = str(e).split(',')[3]
	    xmlstr = xmlstr.strip(',')
	    xmlstr = xmlstr.lstrip()
	    xmlstr = xmlstr.lstrip('\'')
	    xmlstr = xmlstr.rstrip()
	    xmlstr = xmlstr.rstrip('\]')
	    xmlstr = xmlstr.rstrip('\'')
	    xmlstr = xmlstr.replace('\\n', '')
	    xmlstr = xmlstr.replace('\\t', '')		
	    XenCertPrint("Got the probe xml as: %s" % xmlstr)
	    dom = xml.dom.minidom.parseString(xmlstr)
	    TgtList = dom.getElementsByTagName("TGT")		
	    for tgt in TgtList:
		iqn = None
		portal = None
		for node in tgt.childNodes:
		    if node.nodeName == 'TargetIQN':
			iqn = node.firstChild.nodeValue
		
		    if node.nodeName == 'IPAddress':
			portal = node.firstChild.nodeValue

		XenCertPrint("Got iqn: %s, portal: %s" % (iqn, portal))
		XenCertPrint("The target IQN is: %s" % targetIqn)
		if iqn == '*':
		    continue
		for targetiqn in targetIqn.split(','):
		    if iqn == targetiqn:
			listPortal.append(portal)
			break
	    
	    XenCertPrint("The portal list at the end of the iteration is: %s" % listPortal)
	except Exception, e:
	    raise Exception("The target %s did not return any IQNs on probe. Exception: %s" % (server, str(e)))
Example #4
0
def GetHBAInformation(session, storage_conf):
    try:
	retVal = True
	list = []
	scsiIdList = []
	device_config = {}
	HBAFilter = {}

	# Generate a map of the HBAs that the user want to test against.
	if storage_conf['adapters'] != None:
	    for hba in storage_conf['adapters'].split(','):
			HBAFilter[hba] = 1
	
	try:
	    session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmohba')
	except Exception, e:
	    XenCertPrint("Got the probe data as: %s" % str(e))
	    # Now extract the HBA information from this data.
	    try:
		# the target may not return any IQNs
		# so prepare for it
		xmlstr = extract_xml_from_exception(e)
		xmlstr = xmlstr.lstrip()
		xmlstr = xmlstr.lstrip('\'')
		xmlstr = xmlstr.rstrip()
		xmlstr = xmlstr.rstrip('\]')
		xmlstr = xmlstr.rstrip('\'')
		xmlstr = xmlstr.replace('\\n', '')
		xmlstr = xmlstr.replace('\\t', '')		
		XenCertPrint("Got the probe xml as: %s" % xmlstr)
		dom = xml.dom.minidom.parseString(xmlstr)
		TgtList = dom.getElementsByTagName("Adapter")
		for tgt in TgtList:
		    map = {}
		    for node in tgt.childNodes:
			    map[node.nodeName] = node.firstChild.nodeValue
		    if len(HBAFilter) != 0:
			    if HBAFilter.has_key(map['host']):
				    list.append(map)
		    else:
			    list.append(map)
		
		bdList = dom.getElementsByTagName("BlockDevice")
		for bd in bdList:
		    for node in bd.childNodes:
			    if node.nodeName == 'SCSIid':
				    SCSIid = node.firstChild.nodeValue
			    elif node.nodeName == 'adapter':
				    adapter = ''.join(["host",node.firstChild.nodeValue])

		    if len(HBAFilter) != 0:
			    if HBAFilter.has_key(adapter):
				    scsiIdList.append(SCSIid)
		    else:
			    scsiIdList.append(SCSIid)
	
		XenCertPrint("The HBA information list being returned is: %s" % list)
	    except Exception, e:
		XenCertPrint("Failed to parse lvmohba probe xml. Exception: %s" % str(e))
Example #5
0
def GetListPortalScsiIdForIqn(session, server, targetIqn, chapUser = None, chapPassword = None):
    try:
	listPortal = []
	listSCSIId= []
	device_config = {}
	device_config['target'] = server
	if chapUser != None and chapPassword != None:
	    device_config['chapuser'] = chapUser
	    device_config['chappassword'] = chapPassword

	try:
	    session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmoiscsi')
	except Exception, e:
	    XenCertPrint("Got the probe data as: %s" % str(e))
	    
	# Now extract the IQN list from this data.
	try:
	    # the target may not return any IQNs
	    # so prepare for it
	    items = str(e).split(',')
	    xmlstr = ''
	    for i in range(3,len(items)):
		xmlstr += items[i]
		xmlstr += ','
	    
	    #xmlstr = str(e).split(',')[3]
	    xmlstr = xmlstr.strip(',')
	    xmlstr = xmlstr.lstrip()
	    xmlstr = xmlstr.lstrip('\'')
	    xmlstr = xmlstr.rstrip()
	    xmlstr = xmlstr.rstrip('\]')
	    xmlstr = xmlstr.rstrip('\'')
	    xmlstr = xmlstr.replace('\\n', '')
	    xmlstr = xmlstr.replace('\\t', '')		
	    XenCertPrint("Got the probe xml as: %s" % xmlstr)
	    dom = xml.dom.minidom.parseString(xmlstr)
	    TgtList = dom.getElementsByTagName("TGT")		
	    for tgt in TgtList:
		iqn = None
		portal = None
		for node in tgt.childNodes:
		    if node.nodeName == 'TargetIQN':
			iqn = node.firstChild.nodeValue
		
		    if node.nodeName == 'IPAddress':
			portal = node.firstChild.nodeValue

		XenCertPrint("Got iqn: %s, portal: %s" % (iqn, portal))
		XenCertPrint("The target IQN is: %s" % targetIqn)
		if iqn == '*':
		    continue
		for targetiqn in targetIqn.split(','):
		    if iqn == targetiqn:
			listPortal.append(portal)
			break
	    
	    XenCertPrint("The portal list at the end of the iteration is: %s" % listPortal)
	except Exception, e:
	    raise Exception("The target %s did not return any IQNs on probe. Exception: %s" % (server, str(e)))
Example #6
0
File: SR.py Project: euanh/sm
    def from_uuid(session, sr_uuid):
        import imp

        _SR = session.xenapi.SR
        sr_ref = _SR.get_by_uuid(sr_uuid)
        sm_type = _SR.get_type(sr_ref)

        # NB. load the SM driver module

        _SM = session.xenapi.SM
        sms = _SM.get_all_records_where('field "type" = "%s"' % sm_type)
        sm_ref, sm = sms.popitem()
        assert not sms

        driver_path = _SM.get_driver_filename(sm_ref)
        driver_real = os.path.realpath(driver_path)
        module_name = os.path.basename(driver_path)

        module = imp.load_source(module_name, driver_real)
        target = driver(sm_type)

        # NB. get the host pbd's device_config

        host_ref = util.get_localhost_uuid(session)

        _PBD = session.xenapi.PBD
        pbds = _PBD.get_all_records_where('field "SR" = "%s" and' % sr_ref +
                                          'field "host" = "%s"' % host_ref)
        pbd_ref, pbd = pbds.popitem()
        assert not pbds

        device_config = _PBD.get_device_config(pbd_ref)

        # NB. make srcmd, to please our supersized SR constructor.
        # FIXME

        from SRCommand import SRCommand
        cmd = SRCommand(module.DRIVER_INFO)
        cmd.dconf = device_config
        cmd.params = {
            'session_ref': session._session,
            'host_ref': host_ref,
            'device_config': device_config,
            'sr_ref': sr_ref,
            'sr_uuid': sr_uuid,
            'command': 'nop'
        }

        return target(cmd, sr_uuid)
Example #7
0
    def from_uuid(session, sr_uuid):
        import imp

        _SR = session.xenapi.SR
        sr_ref = _SR.get_by_uuid(sr_uuid)
        sm_type = _SR.get_type(sr_ref)

        # NB. load the SM driver module

        _SM = session.xenapi.SM
        sms = _SM.get_all_records_where('field "type" = "%s"' % sm_type)
        sm_ref, sm = sms.popitem()
        assert not sms

        driver_path = _SM.get_driver_filename(sm_ref)
        driver_real = os.path.realpath(driver_path)
        module_name = os.path.basename(driver_path)

        module = imp.load_source(module_name, driver_real)
        target = driver(sm_type)

        # NB. get the host pbd's device_config

        host_ref = util.get_localhost_uuid(session)

        _PBD = session.xenapi.PBD
        pbds = _PBD.get_all_records_where('field "SR" = "%s" and' % sr_ref +
                                          'field "host" = "%s"' % host_ref)
        pbd_ref, pbd = pbds.popitem()
        assert not pbds

        device_config = _PBD.get_device_config(pbd_ref)

        # NB. make srcmd, to please our supersized SR constructor.
        # FIXME

        from SRCommand import SRCommand
        cmd = SRCommand(module.DRIVER_INFO)
        cmd.dconf  = device_config
        cmd.params = { 'session_ref'    : session._session,
                       'host_ref'       : host_ref,
                       'device_config'  : device_config,
                       'sr_ref'         : sr_ref,
                       'sr_uuid'        : sr_uuid,
                       'command'        : 'nop' }

        return target(cmd, sr_uuid)
Example #8
0
def GetHBAInformation(session):
    try:
        retVal = True
        list = []
        scsiIdList = []
        device_config = {}

        try:
            session.xenapi.SR.probe(util.get_localhost_uuid(session),
                                    device_config, 'lvmohba')
        except Exception, e:
            XenCertPrint("Got the probe data as: %s" % str(e))
            # Now extract the HBA information from this data.
            try:
                # the target may not return any IQNs
                # so prepare for it
                xmlstr = str(e).split(',')[3]
                xmlstr = xmlstr.lstrip()
                xmlstr = xmlstr.lstrip('\'')
                xmlstr = xmlstr.rstrip()
                xmlstr = xmlstr.rstrip('\]')
                xmlstr = xmlstr.rstrip('\'')
                xmlstr = xmlstr.replace('\\n', '')
                xmlstr = xmlstr.replace('\\t', '')
                XenCertPrint("Got the probe xml as: %s" % xmlstr)
                dom = xml.dom.minidom.parseString(xmlstr)
                TgtList = dom.getElementsByTagName("Adapter")
                for tgt in TgtList:
                    map = {}
                    for node in tgt.childNodes:
                        map[node.nodeName] = node.firstChild.nodeValue

                    list.append(map)

                bdList = dom.getElementsByTagName("BlockDevice")
                for bd in bdList:
                    for node in bd.childNodes:
                        if node.nodeName == 'SCSIid':
                            scsiIdList.append(node.firstChild.nodeValue)

                XenCertPrint("The HBA information list being returned is: %s" %
                             list)
            except Exception, e:
                XenCertPrint(
                    "Failed to parse lvmohba probe xml. Exception: %s" %
                    str(e))
Example #9
0
def GetHBAInformation(session):
    try:
	retVal = True
	list = []
	scsiIdList = []
	device_config = {}
	
	try:
	    session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmohba')
	except Exception, e:
	    XenCertPrint("Got the probe data as: %s" % str(e))
	    # Now extract the HBA information from this data.
	    try:
		# the target may not return any IQNs
		# so prepare for it
		xmlstr = str(e).split(',')[3]
		xmlstr = xmlstr.lstrip()
		xmlstr = xmlstr.lstrip('\'')
		xmlstr = xmlstr.rstrip()
		xmlstr = xmlstr.rstrip('\]')
		xmlstr = xmlstr.rstrip('\'')
		xmlstr = xmlstr.replace('\\n', '')
		xmlstr = xmlstr.replace('\\t', '')		
		XenCertPrint("Got the probe xml as: %s" % xmlstr)
		dom = xml.dom.minidom.parseString(xmlstr)
		TgtList = dom.getElementsByTagName("Adapter")
		for tgt in TgtList:
		    map = {}
		    for node in tgt.childNodes:
			map[node.nodeName] = node.firstChild.nodeValue
	
		    list.append(map)    
		
		bdList = dom.getElementsByTagName("BlockDevice")
		for bd in bdList:
		    for node in bd.childNodes:
			if node.nodeName == 'SCSIid':
			    scsiIdList.append(node.firstChild.nodeValue)
	
		XenCertPrint("The HBA information list being returned is: %s" % list)
	    except Exception, e:
		XenCertPrint("Failed to parse lvmohba probe xml. Exception: %s" % str(e))
    def __init__(self, sr_uuid, xapi, createLock, force):
        """
        :param uuid:
        :param xapi:
        :param createLock:
        :param force:
        """
        if VERBOSE:
            util.SMlog("RBDSR.RBDSR_GC.__init__: sr_uuid = %s" % sr_uuid)

        host_ref = util.get_localhost_uuid(self.xapi.session)

        _PBD = xapi.session.xenapi.PBD
        pbds = _PBD.get_all_records_where('field "SR" = "%s" and' % self.ref +
                                          'field "host" = "%s"' % host_ref)
        pbd_ref, pbd = pbds.popitem()
        assert not pbds

        device_config = _PBD.get_device_config(pbd_ref)

        if 'driver-type' in device_config:
            self.DRIVER_TYPE = device_config['driver-type']
        else:
            self.DRIVER_TYPE = DRIVER_TYPE_DEFAULT

        if 'use-rbd-meta' in self.sm_config:
            self.USE_RBD_META = self.sm_config['use-rbd-meta']

        if 'disable-caching' in self.sm_config:
            self.disable_caching = self.sm_config['disable-caching']

        if 'rbd-pool-suffix' in self.sm_config:
            self.rbd_pool_suffix = self.sm_config['rbd-pool-suffix']

        if 'cephx-id' in self.sm_config:
            self.CEPH_USER = "******" % self.sm_config['cephx-id']

        if VERBOSE:
            util.SMlog("RBDSR.RBDSR_GC.__init__: Using cephx id %s" %
                       self.CEPH_USER)

        super(RBDSR_GC, self).__init__(sr_uuid, xapi, createLock, force)
Example #11
0
    def from_session(cls, session):
        import util
        import SR as sm

        host_ref = util.get_localhost_uuid(session)

        _host = session.xenapi.host
        sr_ref = _host.get_local_cache_sr(host_ref)
        if not sr_ref:
            raise util.SMException("Local cache SR not specified")

        if sr_ref == 'OpaqueRef:NULL':
            raise util.SMException("Local caching not enabled.")

        _SR = session.xenapi.SR
        sr_uuid = _SR.get_uuid(sr_ref)

        target = sm.SR.from_uuid(session, sr_uuid)

        return cls(target.path)
Example #12
0
File: lcache.py Project: xcp-ng/sm
    def from_session(cls, session):
        import util
        import SR as sm

        host_ref = util.get_localhost_uuid(session)

        _host = session.xenapi.host
        sr_ref = _host.get_local_cache_sr(host_ref)
        if not sr_ref:
            raise util.SMException("Local cache SR not specified")

        if sr_ref == 'OpaqueRef:NULL':
            raise util.SMException("Local caching not enabled.")

        _SR = session.xenapi.SR
        sr_uuid = _SR.get_uuid(sr_ref)

        target = sm.SR.from_uuid(session, sr_uuid)

        return cls(target.path)
Example #13
0
		    continue
		for targetiqn in targetIqn.split(','):
		    if iqn == targetiqn:
			listPortal.append(portal)
			break
	    
	    XenCertPrint("The portal list at the end of the iteration is: %s" % listPortal)
	except Exception, e:
	    raise Exception("The target %s did not return any IQNs on probe. Exception: %s" % (server, str(e)))
		
	#  Now probe again with each IQN in turn.
	for iqn in targetIqn.split(','):
	    try:
		device_config['targetIQN'] = iqn
		XenCertPrint("Probing with device config: %s" % device_config)
		session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmoiscsi')
	    except Exception, e:
		XenCertPrint("Got the probe data as: %s" % str(e))
    
	    # Now extract the SCSI ID list from this data.
	    try:
		# If there are no LUNs exposed, the probe data can be an empty xml
		# so be prepared for it
		items = str(e).split(',')
		xmlstr = ''
		for i in range(3,len(items)):
		    xmlstr += items[i]
		    xmlstr += ','
		#xmlstr = str(e).split(',')[3]
		xmlstr = xmlstr.strip(',')
		xmlstr = xmlstr.lstrip()
Example #14
0
                        listPortal.append(portal)
                        break

            XenCertPrint("The portal list at the end of the iteration is: %s" %
                         listPortal)
        except Exception, e:
            raise Exception(
                "The target %s did not return any IQNs on probe. Exception: %s"
                % (server, str(e)))

        #  Now probe again with each IQN in turn.
        for iqn in targetIqn.split(','):
            try:
                device_config['targetIQN'] = iqn
                XenCertPrint("Probing with device config: %s" % device_config)
                session.xenapi.SR.probe(util.get_localhost_uuid(session),
                                        device_config, 'lvmoiscsi')
            except Exception, e:
                XenCertPrint("Got the probe data as: %s" % str(e))

            # Now extract the SCSI ID list from this data.
            try:
                # If there are no LUNs exposed, the probe data can be an empty xml
                # so be prepared for it
                items = str(e).split(',')
                xmlstr = ''
                for i in range(3, len(items)):
                    xmlstr += items[i]
                    xmlstr += ','
                #xmlstr = str(e).split(',')[3]
                xmlstr = xmlstr.strip(',')
Example #15
0
def get_dom0_vm(session):
    host_ref = util.get_localhost_uuid(session)
    expr = 'field "is_control_domain" = "true" and field "resident_on" = "%s"'
    expr = expr % host_ref
    return session.xenapi.VM.get_all_records_where(expr).keys()[0]
Example #16
0
		    continue
		for targetiqn in targetIqn.split(','):
		    if iqn == targetiqn:
			listPortal.append(portal)
			break
	    
	    XenCertPrint("The portal list at the end of the iteration is: %s" % listPortal)
	except Exception, e:
	    raise Exception("The target %s did not return any IQNs on probe. Exception: %s" % (server, str(e)))
		
	#  Now probe again with each IQN in turn.
	for iqn in targetIqn.split(','):
	    try:
		device_config['targetIQN'] = iqn
		XenCertPrint("Probing with device config: %s" % device_config)
		session.xenapi.SR.probe(util.get_localhost_uuid(session), device_config, 'lvmoiscsi')
	    except Exception, e:
		XenCertPrint("Got the probe data as: %s" % str(e))
    
	    # Now extract the SCSI ID list from this data.
	    try:
		# If there are no LUNs exposed, the probe data can be an empty xml
		# so be prepared for it
		items = str(e).split(',')
		xmlstr = ''
		for i in range(3,len(items)):
		    xmlstr += items[i]
		    xmlstr += ','
		#xmlstr = str(e).split(',')[3]
		xmlstr = xmlstr.strip(',')
		xmlstr = xmlstr.lstrip()
def get_dom0_vm(session):
    host_ref = util.get_localhost_uuid(session)
    expr = 'field "is_control_domain" = "true" and field "resident_on" = "%s"'
    expr = expr % host_ref
    return session.xenapi.VM.get_all_records_where(expr).keys()[0]