def _prepareVolumePathFromPayload(self, vmId, device, payload, path): """ :param vmId: VM UUID or None :param device: either 'floppy' or 'cdrom' :param payload: a dict formed like this: {'volId': 'volume id', # volId is optional 'file': {'filename': 'content', ...}} :param path: payload path as a string; if not given, it will be generated """ funcs = {'cdrom': 'mkIsoFs', 'floppy': 'mkFloppyFs'} if device not in funcs: raise vm.VolumeError("Unsupported 'device': %s" % device) func = getattr(supervdsm.getProxy(), funcs[device]) return func(vmId, payload['file'], payload.get('volId'), path=path)
def prepareVolumePath(self, drive, vmId=None): if type(drive) is dict: device = drive['device'] # PDIV drive format # Since version 4.2 cdrom may use a PDIV format if device in ("cdrom", "disk") and isVdsmImage(drive): res = self.irs.prepareImage(drive['domainID'], drive['poolID'], drive['imageID'], drive['volumeID']) if res['status']['code']: raise vm.VolumeError(drive) # The order of imgVolumesInfo is not guaranteed drive['volumeChain'] = res['imgVolumesInfo'] drive['volumeInfo'] = res['info'] if drive.get('diskType') == DISK_TYPE.NETWORK: if device == "cdrom": raise exception.UnsupportedOperation( "A cdrom device is not supported as network disk", drive=drive) # Not applicable for Ceph network disk as # Ceph disks are not vdsm images volPath = self._prepare_network_drive(drive, res) else: if 'diskType' not in drive: if res['info']['type'] == DISK_TYPE.BLOCK: drive['diskType'] = DISK_TYPE.BLOCK else: # Volume type may be 'network', but if engine did # not speicfy the type, we must use 'file'. drive['diskType'] = DISK_TYPE.FILE volPath = res['path'] # GUID drive format elif "GUID" in drive: res = self.irs.getDevicesVisibility([drive["GUID"]]) if not res["visible"][drive["GUID"]]: raise vm.VolumeError("Drive %r not visible" % drive["GUID"]) res = self.irs.appropriateDevice(drive["GUID"], vmId, 'mpath') if res['status']['code']: raise vm.VolumeError("Cannot appropriate drive %r" % drive["GUID"]) # Update size for LUN volume drive["truesize"] = res['truesize'] drive["apparentsize"] = res['apparentsize'] if 'diskType' not in drive: drive['diskType'] = DISK_TYPE.BLOCK volPath = res['path'] elif "RBD" in drive: res = self.irs.appropriateDevice(drive["RBD"], vmId, 'rbd') volPath = res['path'] # cdrom and floppy drives elif (device in ('cdrom', 'floppy') and 'specParams' in drive): params = drive['specParams'] if 'vmPayload' in params: volPath = self._prepareVolumePathFromPayload( vmId, device, params['vmPayload']) # next line can be removed in future, when < 3.3 engine # is not supported elif (params.get('path', '') == '' and drive.get('path', '') == ''): volPath = '' else: volPath = drive.get('path', '') elif "path" in drive: volPath = drive['path'] else: raise vm.VolumeError(drive) # Noramalize the missing diskType when cluster version < 4.2. if 'diskType' not in drive: drive['diskType'] = DISK_TYPE.FILE # For BC sake: None as argument elif not drive: volPath = drive # For BC sake: path as a string. elif os.path.exists(drive): volPath = drive else: raise vm.VolumeError(drive) self.log.info("prepared volume path: %s", volPath) return volPath
def prepareVolumePath(self, drive, vmId=None): if type(drive) is dict: device = drive['device'] # PDIV drive format if device == 'disk' and isVdsmImage(drive): res = self.irs.prepareImage(drive['domainID'], drive['poolID'], drive['imageID'], drive['volumeID']) if res['status']['code']: raise vm.VolumeError(drive) # The order of imgVolumesInfo is not guaranteed drive['volumeChain'] = res['imgVolumesInfo'] drive['volumeInfo'] = res['info'] # Not applicable for Ceph network disk as # Ceph disks are not vdsm images if drive.get('diskType') == DISK_TYPE.NETWORK: volPath = self._prepare_network_drive(drive, res) else: volPath = res['path'] # GUID drive format elif "GUID" in drive: res = self.irs.getDevicesVisibility([drive["GUID"]]) if not res["visible"][drive["GUID"]]: raise vm.VolumeError(drive) res = self.irs.appropriateDevice(drive["GUID"], vmId) if res['status']['code']: raise vm.VolumeError(drive) # Update size for LUN volume drive["truesize"] = res['truesize'] drive["apparentsize"] = res['apparentsize'] volPath = res['path'] # cdrom and floppy drives elif (device in ('cdrom', 'floppy') and 'specParams' in drive): params = drive['specParams'] if 'vmPayload' in params: volPath = self._prepareVolumePathFromPayload( vmId, device, params['vmPayload']) # next line can be removed in future, when < 3.3 engine # is not supported elif (params.get('path', '') == '' and drive.get('path', '') == ''): volPath = '' else: volPath = drive.get('path', '') elif "path" in drive: volPath = drive['path'] else: raise vm.VolumeError(drive) # For BC sake: None as argument elif not drive: volPath = drive # For BC sake: path as a string. elif os.path.exists(drive): volPath = drive else: raise vm.VolumeError(drive) self.log.info("prepared volume path: %s", volPath) return volPath