Пример #1
0
 def _prepareVolumePathFromPayload(self, vmId, device, payload):
     """
     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', ...}}
     """
     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'))
Пример #2
0
    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)

                volPath = res['path']
                # The order of imgVolumesInfo is not guaranteed
                drive['volumeChain'] = res['imgVolumesInfo']
                drive['volumeInfo'] = res['info']

            # 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']

            # UUID drive format
            elif "UUID" in drive:
                volPath = self._getUUIDSpecPath(drive["UUID"])

            # 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
Пример #3
0
 def _getUUIDSpecPath(self, uuid):
     try:
         return blkid.getDeviceByUuid(uuid)
     except blkid.BlockIdException:
         self.log.info('Error finding path for device', exc_info=True)
         raise vm.VolumeError(uuid)