def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" uname = config.get('uname', '') dev = config.get('dev', '') if 'ioemu:' in dev: (_, dev) = string.split(dev, ':', 1) try: (dev, dev_type) = string.split(dev, ':', 1) except ValueError: dev_type = "disk" if not uname: if dev_type == 'cdrom': (typ, params) = ("", "") else: raise VmError( 'Block device must have physical details specified') else: try: (typ, params) = string.split(uname, ':', 1) if not self._isValidProtocol(typ): raise VmError('Block device type "%s" is invalid.' % typ) except ValueError: raise VmError( 'Block device must have physical details specified') mode = config.get('mode', 'r') if mode not in ('r', 'w', 'w!'): raise VmError('Invalid mode') back = { 'dev': dev, 'type': typ, 'params': params, 'mode': mode, } uuid = config.get('uuid') if uuid: back['uuid'] = uuid bootable = config.get('bootable', None) if bootable != None: back['bootable'] = str(bootable) if security.on() == xsconstants.XS_POLICY_USE: self.do_access_control(config, uname) (device_path, devid) = blkif.blkdev_name_to_number(dev) if devid is None: raise VmError('Unable to find number for device (%s)' % (dev)) front = {device_path: "%i" % devid, 'device-type': dev_type} protocol = config.get('protocol') if protocol: front['protocol'] = protocol return (devid, back, front)
def get_devnum(self, lv): """ Return the device number internaly used by xen for the specified LV. (This is usefull for xm block-detach ...) Raise a KeyError if the given LV is invalid. """ return blkdev_name_to_number(self.devices[lv])[1]
def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" uname = config.get('uname', '') dev = config.get('dev', '') if 'ioemu:' in dev: (_, dev) = string.split(dev, ':', 1) try: (dev, dev_type) = string.split(dev, ':', 1) except ValueError: dev_type = "disk" if not uname: if dev_type == 'cdrom': (typ, params) = ("", "") else: raise VmError( 'Block device must have physical details specified') else: try: (typ, params) = string.split(uname, ':', 1) if typ not in ('phy', 'file', 'tap'): raise VmError( 'Block device must have "phy", "file" or "tap" ' 'specified to type') except ValueError: raise VmError( 'Block device must have physical details specified') mode = config.get('mode', 'r') if mode not in ('r', 'w', 'w!'): raise VmError('Invalid mode') back = {'dev' : dev, 'type' : typ, 'params' : params, 'mode' : mode, } uuid = config.get('uuid') if uuid: back['uuid'] = uuid if security.on() == xsconstants.XS_POLICY_ACM: self.do_access_control(config, uname) (device_path, devid) = blkif.blkdev_name_to_number(dev) if devid is None: raise VmError('Unable to find number for device (%s)' % (dev)) front = { device_path : "%i" % devid, 'device-type' : dev_type } protocol = config.get('protocol') if protocol: front['protocol'] = protocol return (devid, back, front)
def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" dev = sxp.child_value(config, 'dev') (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1) back = { 'dev' : dev, 'type' : typ, 'params' : params, 'mode' : sxp.child_value(config, 'mode', 'r') } if 'ioemu:' in dev: (dummy, dev1) = string.split(dev, ':', 1) devid = blkif.blkdev_name_to_number(dev1) front = {} else: devid = blkif.blkdev_name_to_number(dev) front = { 'virtual-device' : "%i" % devid } return (devid, back, front)
def convertToDeviceNumber(self, devid): try: dev = int(devid) except ValueError: if type(devid) is not str: raise VmError("devid %s is wrong type" % str(devid)) try: dev = devid.split('/')[-1] dev = int(dev) except ValueError: (device_path, dev) = blkif.blkdev_name_to_number(dev) return dev
def get_VM_dev2num(dom_id, dev2path_list): log.debug('get_VM_dev2num') dev2num_list = {} for dev, path in dev2path_list.items(): if "file:" in path: # major = 7 blk_num = blkif.blkdev_name_to_number(dev)[1] cmd = 'cat /sys/devices/vbd-%s-%s/physical_device' % (dom_id, blk_num) (rc, stdout, stderr) = doexec(cmd) out = stdout.read(); stdout.close(); #cmd not fount rc != 0 if rc != 0: err = stderr.read(); stderr.close(); log.error('excute %s error: %s:.' % (cmd, err)) continue else: dev_num = out.strip() dev2num_list[dev] = dev_num else: major = 252 path = path.split(':')[-1] log.debug(path) cmd = "tap-ctl list -f %s | awk '{if (NF>1) print $2}'" % (path) log.debug(cmd) (rc, stdout, stderr) = doexec(cmd) out = stdout.read(); stdout.close(); #cmd not fount rc != 0 if rc != 0: err = stderr.read(); stderr.close(); log.error('excute %s error: %s:.' % (cmd, err)) continue else: num = out.strip().split('=')[-1] dev_num = '%s:%s' %(major, num) dev2num_list[dev] = dev_num return dev2num_list
def getDeviceDetails(self, config): """@see DevController.getDeviceDetails""" uname = config.get('uname', '') dev = config.get('dev', '') if 'ioemu:' in dev: (_, dev) = string.split(dev, ':', 1) try: (dev, dev_type) = string.split(dev, ':', 1) except ValueError: dev_type = "disk" if not uname: if dev_type == 'cdrom': (typ, params) = ("", "") else: raise VmError( 'Block device must have physical details specified') else: try: (typ, params) = string.split(uname, ':', 1) if not self._isValidProtocol(typ): raise VmError('Block device type "%s" is invalid.' % typ) except ValueError: raise VmError( 'Block device must have physical details specified') mode = config.get('mode', 'r') if mode not in ('r', 'w', 'w!'): raise VmError('Invalid mode') back = {'dev' : dev, 'type' : typ, 'params' : params, 'mode' : mode, } uuid = config.get('uuid') if uuid: back['uuid'] = uuid bootable = config.get('bootable', None) if bootable != None: back['bootable'] = str(bootable) if 'snapshotname' in self.vm.info: back['snapshot'] = self.vm.info['snapshotname'] self.vm.info.pop('snapshotname') if security.on() == xsconstants.XS_POLICY_USE: self.do_access_control(config, uname) (device_path, devid) = blkif.blkdev_name_to_number(dev) if devid is None: raise VmError('Unable to find number for device (%s)' % (dev)) front = { device_path : "%i" % devid, 'device-type' : dev_type } protocol = config.get('protocol') if protocol: front['protocol'] = protocol return (devid, back, front)