本文整理汇总了Python中util.find_my_pbd函数的典型用法代码示例。如果您正苦于以下问题:Python find_my_pbd函数的具体用法?Python find_my_pbd怎么用?Python find_my_pbd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_my_pbd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: detach
def detach(self, sr_uuid):
keys = []
pbdref = None
try:
pbdref = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
if self.dconf.has_key("SCSIid"):
self.mpathmodule.reset(self.dconf["SCSIid"], True) # explicitly unmap
keys.append("mpath-" + self.dconf["SCSIid"])
# Remove iscsi_sessions and multipathed keys
if pbdref <> None:
if self.cmd == "sr_detach":
keys += ["multipathed", "iscsi_sessions", "MPPEnabled"]
for key in keys:
try:
self.session.xenapi.PBD.remove_from_other_config(pbdref, key)
except:
pass
if util._decr_iscsiSR_refcount(self.targetIQN, sr_uuid) != 0:
return
if self.direct and util._containsVDIinuse(self):
return
if iscsilib._checkTGT(self.targetIQN):
try:
iscsilib.logout(self.target, self.targetIQN, all=True)
except util.CommandException, inst:
raise xs_errors.XenError("ISCSIQueryDaemon", opterr="error is %d" % inst.code)
if iscsilib._checkTGT(self.targetIQN):
raise xs_errors.XenError("ISCSIQueryDaemon", opterr="Failed to logout from target")
示例2: _synchroniseAddrList
def _synchroniseAddrList(self, addrlist):
if not self.multihomed:
return
change = False
if not self.dconf.has_key('multihomelist'):
change = True
self.mlist = []
mstr = ""
else:
self.mlist = self.dconf['multihomelist'].split(',')
mstr = self.dconf['multihomelist']
for val in addrlist:
if not val in self.mlist:
self.mlist.append(val)
if len(mstr):
mstr += ","
mstr += val
change = True
if change:
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
if pbd <> None:
device_config = self.session.xenapi.PBD.get_device_config(pbd)
device_config['multihomelist'] = mstr
self.session.xenapi.PBD.set_device_config(pbd, device_config)
except:
pass
示例3: _reset_pbd_other_config
def _reset_pbd_other_config(self):
try:
pbd_ref = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
util.SMlog("No pbd for sr_ref %s on host_ref %s" % (sr_ref, host_ref))
for key in ["multipathed"]:
try:
self.session.xenapi.PBD.remove_from_other_config(pbd_ref, key)
except:
util.SMlog("remove_from_other_config failed")
示例4: _add_pbd_other_config
def _add_pbd_other_config(self, key, value):
try:
pbd_ref = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
util.SMlog("No pbd for sr_ref %s on host_ref %s" % (sr_ref, host_ref))
return
try:
self.session.xenapi.PBD.add_to_other_config(pbd_ref, key, value)
except:
util.SMlog("add_to_other_config failed")
示例5: detach
def detach(self, sr_uuid):
LVHDSR.LVHDSR.detach(self, sr_uuid)
self.mpathmodule.reset(self.SCSIid,True,True) # explicit_unmap
try:
pbdref = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
for key in ["mpath-" + self.SCSIid, "multipathed", "MPPEnabled"]:
try:
self.session.xenapi.PBD.remove_from_other_config(pbdref, key)
except:
pass
示例6: create
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)
示例7: load
def load(self, sr_uuid):
driver = SR.driver('hba')
self.hbasr = driver(self.original_srcmd, sr_uuid)
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
print >>sys.stderr,self.hbasr.print_devs()
raise xs_errors.XenError('ConfigSCSIid')
self.SCSIid = self.dconf['SCSIid']
self._pathrefresh(OCFSoHBASR)
super(OCFSoHBASR, self).load(sr_uuid)
示例8: load
def load(self, sr_uuid):
driver = SR.driver('hba')
if 'type' not in self.original_srcmd.params['device_config'] or \
'type' in self.original_srcmd.params['device_config'] and \
self.original_srcmd.dconf['type'] == "any":
self.original_srcmd.dconf['type'] = "fcoe"
self.hbasr = driver(self.original_srcmd, sr_uuid)
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
print >>sys.stderr, self.hbasr.print_devs()
raise xs_errors.XenError('ConfigSCSIid')
self.SCSIid = self.dconf['SCSIid']
self._pathrefresh(LVHDoFCoESR)
LVHDSR.LVHDSR.load(self, sr_uuid)
示例9: load
def load(self, sr_uuid):
driver = SR.driver('hba')
self.hbasr = driver(self.original_srcmd, sr_uuid)
# If this is a vdi command, don't initialise SR
if not (util.isVDICommand(self.original_srcmd.cmd)):
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
try:
if not self.dconf.has_key('SCSIid') and self.dconf.has_key('device'):
# UPGRADE FROM MIAMI: add SCSIid key to device_config
util.SMlog("Performing upgrade from Miami")
if not os.path.exists(self.dconf['device']):
raise xs_errors.XenError('InvalidDev')
SCSIid = scsiutil.getSCSIid(self.dconf['device'])
self.dconf['SCSIid'] = SCSIid
del self.dconf['device']
if pbd <> None:
device_config = self.session.xenapi.PBD.get_device_config(pbd)
device_config['SCSIid'] = SCSIid
device_config['upgraded_from_miami'] = 'true'
del device_config['device']
self.session.xenapi.PBD.set_device_config(pbd, device_config)
except:
pass
if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
print >>sys.stderr,self.hbasr.print_devs()
raise xs_errors.XenError('ConfigSCSIid')
self.SCSIid = self.dconf['SCSIid']
self._pathrefresh(LVHDoHBASR, load = False)
LVHDSR.LVHDSR.load(self, sr_uuid)
示例10: load
def load(self, sr_uuid):
if not sr_uuid:
# This is a probe call, generate a temp sr_uuid
sr_uuid = util.gen_uuid()
driver = SR.driver('iscsi')
self.iscsi = driver(self.original_srcmd, sr_uuid)
# Be extremely careful not to throw exceptions here since this function
# is the main one used by all operations including probing and creating
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
if not self.dconf.has_key('SCSIid') and self.dconf.has_key('LUNid') and pbd <> None:
# UPGRADE FROM RIO: add SCSIid key to device_config
util.SMlog("Performing upgrade from Rio")
scsiid = self._getSCSIid_from_LUN(sr_uuid)
device_config = self.session.xenapi.PBD.get_device_config(pbd)
device_config['SCSIid'] = scsiid
device_config['upgraded_from_rio'] = 'true'
self.session.xenapi.PBD.set_device_config(pbd, device_config)
self.dconf['SCSIid'] = scsiid
# Apart from the upgrade case, user must specify a SCSIid
if not self.dconf.has_key('SCSIid'):
self._LUNprint(sr_uuid)
raise xs_errors.XenError('ConfigSCSIid')
self.SCSIid = self.dconf['SCSIid']
self._pathrefresh(LVMoISCSISR)
super(LVMoISCSISR, self).load(sr_uuid)
示例11: load
def load(self, sr_uuid):
driver = SR.driver("hba")
self.hbasr = driver(self.original_srcmd, sr_uuid)
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
try:
if not self.dconf.has_key("SCSIid") and self.dconf.has_key("device"):
# UPGRADE FROM MIAMI: add SCSIid key to device_config
util.SMlog("Performing upgrade from Miami")
if not os.path.exists(self.dconf["device"]):
raise
SCSIid = scsiutil.getSCSIid(self.dconf["device"])
self.dconf["SCSIid"] = SCSIid
del self.dconf["device"]
if pbd <> None:
device_config = self.session.xenapi.PBD.get_device_config(pbd)
device_config["SCSIid"] = SCSIid
device_config["upgraded_from_miami"] = "true"
del device_config["device"]
self.session.xenapi.PBD.set_device_config(pbd, device_config)
except:
pass
if not self.dconf.has_key("SCSIid") or not self.dconf["SCSIid"]:
print >>sys.stderr, self.hbasr.print_devs()
raise xs_errors.XenError("ConfigSCSIid")
self.SCSIid = self.dconf["SCSIid"]
self._pathrefresh(LVMoHBASR)
super(LVMoHBASR, self).load(sr_uuid)
示例12: load
def load(self, sr_uuid):
if not sr_uuid:
# This is a probe call, generate a temp sr_uuid
sr_uuid = util.gen_uuid()
driver = SR.driver('iscsi')
if self.original_srcmd.dconf.has_key('target'):
self.original_srcmd.dconf['targetlist'] = self.original_srcmd.dconf['target']
iscsi = driver(self.original_srcmd, sr_uuid)
self.iscsiSRs = []
self.iscsiSRs.append(iscsi)
if self.dconf['target'].find(',') == 0 or self.dconf['targetIQN'] == "*":
# Instantiate multiple sessions
self.iscsiSRs = []
if self.dconf['targetIQN'] == "*":
IQN = "any"
else:
IQN = self.dconf['targetIQN']
dict = {}
IQNstring = ""
IQNs = []
try:
if self.dconf.has_key('multiSession'):
IQNs = self.dconf['multiSession'].split("|")
for IQN in IQNs:
if IQN:
dict[IQN] = ""
else:
try:
IQNs.remove(IQN)
except:
# Exceptions are not expected but just in case
pass
# Order in multiSession must be preserved. It is important for dual-controllers.
# IQNstring cannot be built with a dictionary iteration because of this
IQNstring = self.dconf['multiSession']
else:
for tgt in self.dconf['target'].split(','):
try:
tgt_ip = util._convertDNS(tgt)
except:
raise xs_errors.XenError('DNSError')
iscsilib.ensure_daemon_running_ok(iscsi.localIQN)
map = iscsilib.discovery(tgt_ip,iscsi.port,iscsi.chapuser,iscsi.chappassword,targetIQN=IQN)
util.SMlog("Discovery for IP %s returned %s" % (tgt,map))
for i in range(0,len(map)):
(portal,tpgt,iqn) = map[i]
(ipaddr, port) = iscsilib.parse_IP_port(portal)
try:
util._testHost(ipaddr, long(port), 'ISCSITarget')
except:
util.SMlog("Target Not reachable: (%s:%s)" % (ipaddr, port))
continue
key = "%s,%s,%s" % (ipaddr,port,iqn)
dict[key] = ""
# Again, do not mess up with IQNs order. Dual controllers will benefit from that
if IQNstring == "":
# Compose the IQNstring first
for key in dict.iterkeys(): IQNstring += "%s|" % key
# Reinitialize and store iterator
key_iterator = dict.iterkeys()
else:
key_iterator = IQNs
# Now load the individual iSCSI base classes
for key in key_iterator:
(ipaddr,port,iqn) = key.split(',')
srcmd_copy = copy.deepcopy(self.original_srcmd)
srcmd_copy.dconf['target'] = ipaddr
srcmd_copy.dconf['targetIQN'] = iqn
srcmd_copy.dconf['multiSession'] = IQNstring
util.SMlog("Setting targetlist: %s" % srcmd_copy.dconf['targetlist'])
self.iscsiSRs.append(driver(srcmd_copy, sr_uuid))
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
if pbd <> None and not self.dconf.has_key('multiSession'):
dconf = self.session.xenapi.PBD.get_device_config(pbd)
dconf['multiSession'] = IQNstring
self.session.xenapi.PBD.set_device_config(pbd, dconf)
except:
util.logException("LVHDoISCSISR.load")
self.iscsi = self.iscsiSRs[0]
# Be extremely careful not to throw exceptions here since this function
# is the main one used by all operations including probing and creating
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
# Apart from the upgrade case, user must specify a SCSIid
if not self.dconf.has_key('SCSIid'):
# Dual controller issue
self.LUNs = {} # Dict for LUNs from all the iscsi objects
for ii in range(0, len(self.iscsiSRs)):
self.iscsi = self.iscsiSRs[ii]
self._LUNprint(sr_uuid)
for key in self.iscsi.LUNs:
self.LUNs[key] = self.iscsi.LUNs[key]
#.........这里部分代码省略.........
示例13: len
if len(iqn): IQNs += iqn.split(',')[2]
else:
IQNs.append(self.targetIQN)
sessions = 0
paths = iscsilib.get_IQN_paths()
for path in paths:
try:
if util.get_single_entry(os.path.join(path, 'targetname')) in IQNs:
sessions += 1
util.SMlog("IQN match. Incrementing sessions to %d" % sessions)
except:
util.SMlog("Failed to read targetname path," \
+ "iscsi_sessions value may be incorrect")
try:
pbdref = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
if pbdref <> None:
other_conf = self.session.xenapi.PBD.get_other_config(pbdref)
other_conf['iscsi_sessions'] = str(sessions)
self.session.xenapi.PBD.set_other_config(pbdref, other_conf)
except:
pass
if self.mpath == 'true' and self.dconf.has_key('SCSIid'):
self.mpathmodule.refresh(self.dconf['SCSIid'],npaths)
# set the device mapper's I/O scheduler
self.block_setscheduler('/dev/disk/by-scsid/%s/mapper'
% self.dconf['SCSIid'])
def detach(self, sr_uuid):
示例14: load
def load(self, sr_uuid):
if not sr_uuid:
# This is a probe call, generate a temp sr_uuid
sr_uuid = util.gen_uuid()
driver = SR.driver('iscsi')
if self.original_srcmd.dconf.has_key('target'):
self.original_srcmd.dconf['targetlist'] = self.original_srcmd.dconf['target']
iscsi = driver(self.original_srcmd, sr_uuid)
self.iscsiSRs = []
self.iscsiSRs.append(iscsi)
if self.dconf['target'].find(',') == 0 or self.dconf['targetIQN'] == "*":
# Instantiate multiple sessions
self.iscsiSRs = []
if self.dconf['targetIQN'] == "*":
IQN = "any"
else:
IQN = self.dconf['targetIQN']
dict = {}
try:
if self.dconf.has_key('multiSession'):
IQNs = self.dconf['multiSession'].split("|")
for IQN in IQNs:
if IQN:
dict[IQN] = ""
else:
for tgt in self.dconf['target'].split(','):
try:
tgt_ip = util._convertDNS(tgt)
except:
raise xs_errors.XenError('DNSError')
iscsilib.ensure_daemon_running_ok(iscsi.localIQN)
map = iscsilib.discovery(tgt_ip,iscsi.port,iscsi.chapuser,iscsi.chappassword,targetIQN=IQN)
util.SMlog("Discovery for IP %s returned %s" % (tgt,map))
for i in range(0,len(map)):
(portal,tpgt,iqn) = map[i]
(ipaddr,port) = portal.split(',')[0].split(':')
key = "%s,%s,%s" % (ipaddr,port,iqn)
dict[key] = ""
# Compose the IQNstring first
IQNstring = ""
for key in dict.iterkeys(): IQNstring += "%s|" % key
# Now load the individual iSCSI base classes
for key in dict.iterkeys():
(ipaddr,port,iqn) = key.split(',')
srcmd_copy = copy.deepcopy(self.original_srcmd)
srcmd_copy.dconf['target'] = ipaddr
srcmd_copy.dconf['targetIQN'] = iqn
srcmd_copy.dconf['multiSession'] = IQNstring
util.SMlog("Setting targetlist: %s" % srcmd_copy.dconf['targetlist'])
self.iscsiSRs.append(driver(srcmd_copy, sr_uuid))
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
if pbd <> None and not self.dconf.has_key('multiSession'):
dconf = self.session.xenapi.PBD.get_device_config(pbd)
dconf['multiSession'] = IQNstring
self.session.xenapi.PBD.set_device_config(pbd, dconf)
except:
util.logException("LVHDoISCSISR.load")
self.iscsi = self.iscsiSRs[0]
# Be extremely careful not to throw exceptions here since this function
# is the main one used by all operations including probing and creating
pbd = None
try:
pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
except:
pass
if not self.dconf.has_key('SCSIid') and self.dconf.has_key('LUNid') and pbd <> None:
# UPGRADE FROM RIO: add SCSIid key to device_config
util.SMlog("Performing upgrade from Rio")
scsiid = self._getSCSIid_from_LUN(sr_uuid)
device_config = self.session.xenapi.PBD.get_device_config(pbd)
device_config['SCSIid'] = scsiid
device_config['upgraded_from_rio'] = 'true'
self.session.xenapi.PBD.set_device_config(pbd, device_config)
self.dconf['SCSIid'] = scsiid
# Apart from the upgrade case, user must specify a SCSIid
if not self.dconf.has_key('SCSIid'):
self._LUNprint(sr_uuid)
raise xs_errors.XenError('ConfigSCSIid')
self.SCSIid = self.dconf['SCSIid']
self._pathrefresh(LVHDoISCSISR)
LVHDSR.LVHDSR.load(self, sr_uuid)
示例15: attach
def attach(self, sr_uuid):
self._mpathHandle()
multiTargets=False
npaths=0
try:
pbdref = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
if pbdref:
other_config = self.session.xenapi.PBD.get_other_config(pbdref)
multiTargets = util.sessions_less_than_targets(other_config, self.dconf)
except:
pass
if not self.attached or multiTargets:
# Verify iSCSI target and port
if self.dconf.has_key('multihomelist') and not self.dconf.has_key('multiSession'):
targetlist = self.dconf['multihomelist'].split(',')
else:
targetlist = ['%s:%d' % (self.target,self.port)]
conn = False
for val in targetlist:
(target, port) = iscsilib.parse_IP_port(val)
try:
util._testHost(target, long(port), 'ISCSITarget')
self.target = target
self.port = long(port)
conn = True
break
except:
pass
if not conn:
raise xs_errors.XenError('ISCSITarget')
# Test and set the initiatorname file
iscsilib.ensure_daemon_running_ok(self.localIQN)
# Check to see if auto attach was set
if not iscsilib._checkTGT(self.targetIQN) or multiTargets:
try:
map = []
if 'any' != self.targetIQN:
try:
map = iscsilib.get_node_records(self.targetIQN)
except:
# Pass the exception that is thrown, when there
# are no nodes
pass
if len(map) == 0:
map = iscsilib.discovery(self.target, self.port,
self.chapuser, self.chappassword,
self.targetIQN,
iscsilib.get_iscsi_interfaces())
if len(map) == 0:
self._scan_IQNs()
raise xs_errors.XenError('ISCSIDiscovery',
opterr='check target settings')
for i in range(0,len(map)):
(portal,tpgt,iqn) = map[i]
try:
(ipaddr, port) = iscsilib.parse_IP_port(portal)
if not self.multihomed and ipaddr != self.target:
continue
util._testHost(ipaddr, long(port), 'ISCSITarget')
util.SMlog("Logging in to [%s:%s]" % (ipaddr,port))
iscsilib.login(portal, iqn, self.chapuser,
self.chappassword,
self.incoming_chapuser,
self.incoming_chappassword,
self.mpath == "true")
npaths = npaths + 1
except Exception, e:
# Exceptions thrown in login are acknowledged,
# the rest of exceptions are ignored since some of the
# paths in multipath may not be reachable
if str(e).startswith('ISCSI login'):
raise
else:
pass
if not iscsilib._checkTGT(self.targetIQN):
raise xs_errors.XenError('ISCSIDevice', \
opterr='during login')
# Allow the devices to settle
time.sleep(5)
except util.CommandException, inst:
raise xs_errors.XenError('ISCSILogin', \
opterr='code is %d' % inst.code)