def supported(): return not (caps.getos() in (caps.OSName.RHEVH, caps.OSName.RHEL) and caps.osversion()['version'].startswith('6'))
def create(self, vmParams): """ Start up a virtual machine. :param vmParams: required and optional VM parameters. :type vmParams: dict """ vmParams['vmId'] = self._UUID try: if vmParams.get('vmId') in self._cif.vmContainer: self.log.warning('vm %s already exists' % vmParams['vmId']) return errCode['exist'] if 'hiberVolHandle' in vmParams: vmParams['restoreState'], paramFilespec = \ self._getHibernationPaths(vmParams.pop('hiberVolHandle')) try: # restore saved vm parameters # NOTE: pickled params override command-line params. this # might cause problems if an upgrade took place since the # parmas were stored. fname = self._cif.prepareVolumePath(paramFilespec) try: with file(fname) as f: pickledMachineParams = pickle.load(f) if type(pickledMachineParams) == dict: self.log.debug('loaded pickledMachineParams ' + str(pickledMachineParams)) self.log.debug('former conf ' + str(vmParams)) vmParams.update(pickledMachineParams) finally: self._cif.teardownVolumePath(paramFilespec) except: self.log.error("Error restoring VM parameters", exc_info=True) requiredParams = ['vmId', 'memSize', 'display'] for param in requiredParams: if param not in vmParams: self.log.error('Missing required parameter %s' % (param)) return {'status': {'code': errCode['MissParam']['status']['code'], 'message': 'Missing required parameter %s' % (param)}} try: storage.misc.validateUUID(vmParams['vmId']) except: return {'status': {'code': errCode['MissParam']['status']['code'], 'message': 'vmId must be a valid UUID'}} if vmParams['memSize'] == 0: return {'status': {'code': errCode['MissParam']['status']['code'], 'message': 'Must specify nonzero memSize'}} if vmParams.get('boot') == 'c' and not 'hda' in vmParams \ and not vmParams.get('drives'): return {'status': {'code': errCode['MissParam']['status']['code'], 'message': 'missing boot disk'}} if 'vmType' not in vmParams: vmParams['vmType'] = 'kvm' elif vmParams['vmType'] == 'kvm': if 'kvmEnable' not in vmParams: vmParams['kvmEnable'] = 'true' if 'sysprepInf' in vmParams: if not vmParams.get('floppy'): vmParams['floppy'] = '%s%s.vfd' % (constants.P_VDSM_RUN, vmParams['vmId']) vmParams['volatileFloppy'] = True if caps.osversion()['name'] == caps.OSName.UNKNOWN: return {'status': {'code': errCode['createErr'] ['status']['code'], 'message': 'Unknown host operating system'}} if 'sysprepInf' in vmParams: if not self._createSysprepFloppyFromInf(vmParams['sysprepInf'], vmParams['floppy']): return {'status': {'code': errCode['createErr'] ['status']['code'], 'message': 'Failed to create ' 'sysprep floppy image. ' 'No space on /tmp?'}} return errCode['createErr'] if vmParams.get('display') not in ('vnc', 'qxl', 'qxlnc', 'local'): return {'status': {'code': errCode['createErr'] ['status']['code'], 'message': 'Unknown display type %s' % vmParams.get('display') }} if 'nicModel' not in vmParams: vmParams['nicModel'] = config.get('vars', 'nic_model') vmParams['displayIp'] = self._getNetworkIp(vmParams.get( 'displayNetwork')) self._cif.vmContainerLock.acquire() self.log.info("vmContainerLock acquired by vm %s", vmParams['vmId']) try: if 'recover' not in vmParams: if vmParams['vmId'] in self._cif.vmContainer: self.log.warning('vm %s already exists' % vmParams['vmId']) return errCode['exist'] vmParams['displayPort'] = '-1' # selected by libvirt vmParams['displaySecurePort'] = '-1' VmClass = libvirtvm.LibvirtVm self._cif.vmContainer[vmParams['vmId']] = VmClass(self._cif, vmParams) finally: self._cif.vmContainerLock.release() self._cif.vmContainer[vmParams['vmId']].run() self.log.debug("Total desktops after creation of %s is %d" % (vmParams['vmId'], len(self._cif.vmContainer))) return {'status': doneCode, 'vmList': self._cif.vmContainer[vmParams['vmId']].status()} except OSError, e: self.log.debug("OS Error creating VM", exc_info=True) return {'status': {'code': errCode['createErr']['status']['code'], 'message': 'Failed to create VM. ' 'No space on /tmp? ' + e.message}}