本文整理汇总了Python中xen.xend.server.DevController.DevController类的典型用法代码示例。如果您正苦于以下问题:Python DevController类的具体用法?Python DevController怎么用?Python DevController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DevController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createDevice
def createDevice(self, config):
bridge = config.get('bridge')
if bridge is not None:
bridge_result = commands.getstatusoutput("/sbin/ifconfig %s" % bridge)
if bridge_result[0] != 0:
raise VmError('Network bridge does not exist: %s' % bridge)
DevController.createDevice(self, config)
示例2: destroyDevice
def destroyDevice(self, devid):
try:
DevController.destroyDevice(self, int(devid))
time.sleep(5)
t = xstransact()
frontpath = self.frontendPath(int(devid))
backpath = t.Read(frontpath, "backend")
if backpath:
t.Remove(backpath)
log.debug("in try: removed %s" % backpath)
t.Remove(frontpath)
log.debug("in try: removed %s" % frontpath)
except ValueError:
devid_end = type(devid) is str and devid.split("/")[-1] or None
for i in self.deviceIDs():
d = self.readBackend(i, "dev")
if d == devid or (devid_end and d == devid_end):
DevController.destroyDevice(self, i)
time.sleep(5)
frontpath = self.frontendPath(int(devid))
backpath = t.Read(frontpath, "backend")
if backpath:
t.Remove(backpath)
log.debug("in err: removed %s" % backpath)
t.Remove(frontpath)
log.debug("in err: removed %s" % frontpath)
return
raise VmError("Device %s not connected" % devid)
示例3: destroyDevice
def destroyDevice(self, devid):
try:
DevController.destroyDevice(self, int(devid))
except ValueError:
devid_end = type(devid) is str and devid.split('/')[-1] or None
for i in self.deviceIDs():
d = self.readBackend(i, 'dev')
if d == devid or (devid_end and d == devid_end):
DevController.destroyDevice(self, i)
return
raise VmError("Device %s not connected" % devid)
示例4: configuration
def configuration(self, devid):
"""@see DevController.configuration"""
result = DevController.configuration(self, devid)
(script, ip, bridge, mac, typ, vifname, rate) = self.readBackend(
devid, 'script', 'ip', 'bridge', 'mac', 'type', 'vifname', 'rate')
if script:
result.append(['script',
script.replace(xroot.network_script_dir + os.sep,
"")])
if ip:
for i in ip.split(" "):
result.append(['ip', i])
if bridge:
result.append(['bridge', bridge])
if mac:
result.append(['mac', mac])
if typ:
result.append(['type', typ])
if vifname:
result.append(['vifname', vifname])
if rate:
result.append(['rate', formatRate(rate)])
return result
示例5: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
result = DevController.getDeviceConfiguration(self, devid, transaction)
if transaction is None:
devinfo = self.readBackend(devid, *CONFIG_ENTRIES)
else:
devinfo = self.readBackendTxn(transaction, devid, *CONFIG_ENTRIES)
return dict([(CONFIG_ENTRIES[i], devinfo[i])
for i in range(len(CONFIG_ENTRIES))
if devinfo[i] is not None])
示例6: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
result = DevController.getDeviceConfiguration(self, devid, transaction)
if transaction is None:
devinfo = self.readBackend(devid, *self.valid_cfg)
else:
devinfo = self.readBackendTxn(transaction, devid, *self.valid_cfg)
config = dict(zip(self.valid_cfg, devinfo))
config = dict([(key, val) for key, val in config.items()
if val != None])
return config
示例7: destroyDevice
def destroyDevice(self, devid):
"""@see DevController.destroyDevice"""
# If we are given a device name, then look up the device ID from it,
# and destroy that ID instead. If what we are given is an integer,
# then assume it's a device ID and pass it straight through to our
# superclass's method.
try:
DevController.destroyDevice(self, int(devid))
except ValueError:
devid_end = type(devid) is str and devid.split('/')[-1] or None
for i in self.deviceIDs():
d = self.readBackend(i, 'dev')
if d == devid or (devid_end and d == devid_end):
DevController.destroyDevice(self, i)
return
raise VmError("Device %s not connected" % devid)
示例8: configuration
def configuration(self, devid):
result = DevController.configuration(self, devid)
instance = self.readBackend(devid, 'instance')
if instance:
result.append(['instance', instance])
return result
示例9: destroyDevice
def destroyDevice(self, devid, force):
"""@see DevController.destroyDevice"""
# vbd device IDs can be either string or integer. Further, the
# following string values are possible:
# - devicetype/deviceid (vbd/51728)
# - devicetype/devicename (/dev/xvdb)
# - devicename (xvdb)
# Let our superclass handle integer or devicetype/deviceid forms.
# If we are given a device name form, then look up the device ID
# from it, and destroy that ID instead.
try:
DevController.destroyDevice(self, devid, force)
except ValueError:
dev = self.convertToDeviceNumber(devid)
for i in self.deviceIDs():
if i == dev:
DevController.destroyDevice(self, i, force)
return
raise VmError("Device %s not connected" % devid)
示例10: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
"""@see DevController.configuration"""
result = DevController.getDeviceConfiguration(self, devid, transaction)
for x in ( 'script', 'ip', 'bridge', 'mac',
'type', 'vifname', 'rate', 'uuid', 'model', 'accel',
'security_label'):
if transaction is None:
y = self.readBackend(devid, x)
else:
y = self.readBackendTxn(transaction, devid, x)
if y:
result[x] = y
return result
示例11: configuration
def configuration(self, devid):
"""@see DevController.configuration"""
result = DevController.configuration(self, devid)
(dev, typ, params, mode) = self.readBackend(devid,
'dev', 'type', 'params',
'mode')
if dev:
result.append(['dev', dev])
if typ and params:
result.append(['uname', typ + ":" + params])
if mode:
result.append(['mode', mode])
return result
示例12: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
"""@see DevController.configuration"""
if transaction is None:
read_fn = xstransact.Read
else:
read_fn = transaction.read
def front_read(x):
return read_fn(frontpath + x)
def back_read(x):
return read_fn(backpath + x)
result = DevController.getDeviceConfiguration(self, devid, transaction)
dev = self.convertToDeviceNumber(devid)
frontpath = self.frontendPath(dev) + "/"
backpath = front_read("backend") + "/"
front_mac = front_read("mac")
back_mac = back_read("mac")
front_trusted = back_read("remote-trusted")
back_trusted = back_read("local-trusted")
max_bypasses = back_read("max-bypasses")
bridge = back_read("bridge")
pdev = back_read("pdev")
if front_mac:
result["front_mac"] = front_mac
if back_mac:
result["back_mac"] = back_mac
if front_trusted:
result["front_trusted"] = front_trusted
if back_trusted:
result["back_trusted"] = back_trusted
if bridge:
result["bridge"] = bridge
if pdev:
result["pdev"] = pdev
if max_bypasses:
result["max-bypasses"] = max_bypasses
return result
示例13: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
"""@see DevController.configuration"""
config = DevController.getDeviceConfiguration(self, devid, transaction)
if transaction is None:
hcinfo = self.readBackend(devid, 'usb-ver', 'num-ports')
else:
hcinfo = self.readBackendTxn(transaction, devid,
'usb-ver', 'num-ports')
(usbver, numports) = hcinfo
config['usb-ver'] = str(usbver)
config['num-ports'] = str(numports)
for i in range(1, int(numports) + 1):
if transaction is None:
config['port-%i' % i] = self.readBackend(devid, 'port/%i' % i)
else:
config['port-%i' % i] = self.readBackendTxn(transaction, devid,
'port/%i' % i)
return config
示例14: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
"""@see DevController.configuration"""
result = DevController.getDeviceConfiguration(self, devid, transaction)
config_path = "device/%s/%d/" % (self.deviceClass, devid)
devinfo = ()
for x in ( 'script', 'ip', 'bridge', 'mac',
'type', 'vifname', 'rate', 'uuid', 'model', 'accel',
'security_label'):
if transaction is None:
y = self.vm._readVm(config_path + x)
else:
y = self.vm._readVmTxn(transaction, config_path + x)
devinfo += (y,)
(script, ip, bridge, mac, typ, vifname, rate, uuid,
model, accel, security_label) = devinfo
if script:
result['script'] = script
if ip:
result['ip'] = ip
if bridge:
result['bridge'] = bridge
if mac:
result['mac'] = mac
if typ:
result['type'] = typ
if vifname:
result['vifname'] = vifname
if rate:
result['rate'] = rate
if uuid:
result['uuid'] = uuid
if model:
result['model'] = model
if accel:
result['accel'] = accel
if security_label:
result['security_label'] = security_label
return result
示例15: getDeviceConfiguration
def getDeviceConfiguration(self, devid, transaction = None):
result = DevController.getDeviceConfiguration(self, devid, transaction)
num_devs = self.readBackend(devid, 'num_devs')
pci_devs = []
vslots = self.readBackend(devid, 'vslots')
if vslots is not None:
if vslots[-1] == ";":
vslots = vslots[:-1]
slot_list = vslots.split(';')
for i in range(int(num_devs)):
dev_config = self.readBackend(devid, 'dev-%d' % i)
pci_match = re.match(r"((?P<domain>[0-9a-fA-F]{1,4})[:,])?" +
r"(?P<bus>[0-9a-fA-F]{1,2})[:,]" +
r"(?P<slot>[0-9a-fA-F]{1,2})[.,]" +
r"(?P<func>[0-7]{1,2})$", dev_config)
if pci_match!=None:
pci_dev_info = pci_match.groupdict()
dev_dict = {'domain': '0x%(domain)s' % pci_dev_info,
'bus': '0x%(bus)s' % pci_dev_info,
'slot': '0x%(slot)s' % pci_dev_info,
'func': '0x%(func)s' % pci_dev_info}
# Per device uuid info
dev_dict['uuid'] = self.readBackend(devid, 'uuid-%d' % i)
#append vslot info
if vslots is not None:
try:
dev_dict['vslt'] = slot_list[i]
except IndexError:
dev_dict['vslt'] = '0x0'
pci_devs.append(dev_dict)
result['devs'] = pci_devs
result['uuid'] = self.readBackend(devid, 'uuid')
return result