protected void createVbds(OvmVm.Details vm, VirtualMachineTO spec) throws URISyntaxException { for (DiskTO volume : spec.getDisks()) { if (volume.getType() == Volume.Type.ROOT) { VolumeObjectTO vol = (VolumeObjectTO)volume.getData(); OvmDisk.Details root = new OvmDisk.Details(); root.path = vol.getPath(); root.isIso = false; vm.rootDisk = root; } else if (volume.getType() == Volume.Type.ISO) { DataTO isoTO = volume.getData(); if (isoTO.getPath() != null) { TemplateObjectTO template = (TemplateObjectTO)isoTO; vm.disks.add(iso); } else if (volume.getType() == Volume.Type.DATADISK) { data.path = volume.getData().getPath(); data.type = OvmDisk.SHAREDWRITE; data.isIso = false; vm.disks.add(data); } else { throw new CloudRuntimeException("Unknow volume type: " + volume.getType());
@Override public AttachAnswer attachVolume(final AttachCommand cmd) { final DiskTO disk = cmd.getDisk(); final DataTO data = disk.getData(); try { final String vmName = cmd.getVmName(); final Map<String, String> details = disk.getDetails(); final boolean isManaged = Boolean.parseBoolean(details.get(DiskTO.MANAGED)); final DiskTO newDisk = new DiskTO(disk.getData(), disk.getDiskSeq(), vdi.getUuid(conn), disk.getType()); vbdr.userdevice = "autodetect"; final Long deviceId = disk.getDiskSeq(); final DiskTO newDisk = new DiskTO(disk.getData(), Long.parseLong(vbd.getUserdevice(conn)), vdi.getUuid(conn), disk.getType());
public VDI prepareManagedDisk(final Connection conn, final DiskTO disk, final long vmId, final String vmName) throws Exception { final Map<String, String> details = disk.getDetails(); if (details == null) { return null; } final boolean isManaged = new Boolean(details.get(DiskTO.MANAGED)).booleanValue(); if (!isManaged) { return null; } final String iqn = details.get(DiskTO.IQN); final Set<SR> srNameLabels = SR.getByNameLabel(conn, iqn); if (srNameLabels.size() != 0) { return null; } final String vdiNameLabel = Volume.Type.ROOT.equals(disk.getType()) ? ("ROOT-" + vmId) : (vmName + "-DATA"); return prepareManagedStorage(conn, details, null, vdiNameLabel); }
private void handlePath(final DiskTO[] disks, final HypervisorType hypervisorType) { if (hypervisorType != HypervisorType.KVM) { return; } if (disks != null) { for (final DiskTO disk : disks) { final Map<String, String> details = disk.getDetails(); final boolean isManaged = details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED)); if (isManaged && disk.getPath() == null) { final Long volumeId = disk.getData().getId(); final VolumeVO volume = _volsDao.findById(volumeId); disk.setPath(volume.get_iScsiName()); if (disk.getData() instanceof VolumeObjectTO) { final VolumeObjectTO volTo = (VolumeObjectTO)disk.getData(); volTo.setPath(volume.get_iScsiName()); } volume.setPath(volume.get_iScsiName()); _volsDao.update(volumeId, volume); } } } }
if (volumeTo.getType() != Volume.Type.ISO) { final VolumeObjectTO vol = (VolumeObjectTO)volumeTo.getData(); final Long deviceId = volumeTo.getDiskSeq(); final VDI vdi = deviceIdToVdiMap.get(deviceId.toString()); final VolumeObjectTO newVol = new VolumeObjectTO();
public boolean connectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { boolean result = false; final String vmName = vmSpec.getName(); List<DiskTO> disks = Arrays.asList(vmSpec.getDisks()); for (DiskTO disk : disks) { if (disk.getType() == Volume.Type.ISO) { result = true; continue; } VolumeObjectTO vol = (VolumeObjectTO)disk.getData(); PrimaryDataStoreTO store = (PrimaryDataStoreTO)vol.getDataStore(); if (!store.isManaged() && VirtualMachine.State.Migrating.equals(vmSpec.getState())) { result = true; continue; } KVMStoragePool pool = getStoragePool(store.getPoolType(), store.getUuid()); StorageAdaptor adaptor = getStorageAdaptor(pool.getType()); result = adaptor.connectPhysicalDisk(vol.getPath(), pool, disk.getDetails()); if (!result) { s_logger.error("Failed to connect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); return result; } } return result; }
/** * Iso specific path return. * @param disk * @return * @throws Ovm3ResourceException */ private String getIsoPath(DiskTO disk) throws Ovm3ResourceException { TemplateObjectTO isoTO = (TemplateObjectTO) disk.getData(); DataStoreTO store = isoTO.getDataStore(); NfsTO nfsStore = (NfsTO) store; String secPoolUuid = pool.setupSecondaryStorage(nfsStore.getUrl()); return config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + isoTO.getPath(); }
protected Answer execute(AttachCommand cmd) { DiskTO disk = cmd.getDisk(); if (disk.getType() == Volume.Type.ISO) { return processor.attachIso(cmd); } else { return processor.attachVolume(cmd); } }
@Override public Answer attachVolume(final AttachCommand cmd) { final DiskTO disk = cmd.getDisk(); final VolumeObjectTO vol = (VolumeObjectTO)disk.getData(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)vol.getDataStore(); final String vmName = cmd.getVmName(); final String serial = resource.diskUuidToSerial(vol.getUuid()); try { final Connect conn = LibvirtConnection.getConnectionByVmName(vmName); storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath(), disk.getDetails()); final KVMPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue(), serial, vol.getBytesReadRate(), vol.getBytesWriteRate(), vol.getIopsReadRate(), vol.getIopsWriteRate()); return new AttachAnswer(disk); } catch (final LibvirtException e) { s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); return new AttachAnswer(e.toString()); } catch (final InternalErrorException e) { s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); return new AttachAnswer(e.toString()); } }
public VBD createVbd(final Connection conn, final DiskTO volume, final String vmName, final VM vm, final BootloaderType bootLoaderType, VDI vdi) throws XmlRpcException, XenAPIException { final Volume.Type type = volume.getType(); if (volume.getType() == Volume.Type.ISO) { vbdr.mode = Types.VbdMode.RO; vbdr.type = Types.VbdType.CD; vbdr.mode = Types.VbdMode.RW; vbdr.type = Types.VbdType.DISK; vbdr.unpluggable = (volume.getType() == Volume.Type.ROOT) ? false : true; vbdr.userdevice = "autodetect"; final Long deviceId = volume.getDiskSeq(); if (deviceId != null && (!isDeviceUsed(conn, vm, deviceId) || deviceId > 3)) { vbdr.userdevice = deviceId.toString();
disk.setDetails(details); DiskTO disk = answer.getDisk(); _volsDao.attachVolume(volumeToAttach.getId(), vm.getId(), disk.getDiskSeq()); volumeToAttach.setPath(answer.getDisk().getPath());
private void handlePath(final DiskTO[] disks, final Map<String, Map<String, String>> iqnToData) { if (disks != null && iqnToData != null) { for (final DiskTO disk : disks) { final Map<String, String> details = disk.getDetails(); final boolean isManaged = details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED)); if (isManaged) { final Long volumeId = disk.getData().getId(); final VolumeVO volume = _volsDao.findById(volumeId); final String iScsiName = volume.get_iScsiName(); boolean update = false; final Map<String, String> data = iqnToData.get(iScsiName); if (data != null) { final String path = data.get(StartAnswer.PATH); if (path != null) { volume.setPath(path); update = true; } final String imageFormat = data.get(StartAnswer.IMAGE_FORMAT); if (imageFormat != null) { volume.setFormat(ImageFormat.valueOf(imageFormat)); update = true; } if (update) { _volsDao.update(volumeId, volume); } } } } } }
@Override public Answer dettachVolume(final DettachCommand cmd) { final DiskTO disk = cmd.getDisk(); final VolumeObjectTO vol = (VolumeObjectTO)disk.getData(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)vol.getDataStore(); final String vmName = cmd.getVmName(); final String serial = resource.diskUuidToSerial(vol.getUuid()); try { final Connect conn = LibvirtConnection.getConnectionByVmName(vmName); final KVMPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue(), serial, vol.getBytesReadRate(), vol.getBytesWriteRate(), vol.getIopsReadRate(), vol.getIopsWriteRate()); storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); return new DettachAnswer(disk); } catch (final LibvirtException e) { s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } catch (final InternalErrorException e) { s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } }
private void addConfigDriveDisk(final VirtualMachineProfile profile, final DataStore dataStore) { boolean isoAvailable = false; final String isoPath = ConfigDrive.createConfigDrivePath(profile.getInstanceName()); for (DiskTO dataTo : profile.getDisks()) { if (dataTo.getPath().equals(isoPath)) { isoAvailable = true; break; } } if (!isoAvailable) { TemplateObjectTO dataTO = new TemplateObjectTO(); dataTO.setDataStore(dataStore.getTO()); dataTO.setUuid(profile.getUuid()); dataTO.setPath(isoPath); dataTO.setFormat(Storage.ImageFormat.ISO); profile.addDisk(new DiskTO(dataTO, CONFIGDRIVEDISKSEQ.longValue(), isoPath, Volume.Type.ISO)); } else { LOG.warn("Config drive iso already is in VM profile."); } }
@Override public DiskTO getDiskWithThrottling(final DataTO volTO, final Volume.Type volumeType, final long deviceId, final String path, final long offeringId, final long diskOfferingId) { DiskTO disk = null; if (volTO != null && volTO instanceof VolumeObjectTO) { VolumeObjectTO volumeTO = (VolumeObjectTO)volTO; ServiceOffering offering = _entityMgr.findById(ServiceOffering.class, offeringId); DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId); if (volumeType == Volume.Type.ROOT) { setVolumeObjectTOThrottling(volumeTO, offering, diskOffering); } else { setVolumeObjectTOThrottling(volumeTO, null, diskOffering); } disk = new DiskTO(volumeTO, deviceId, path, volumeType); } else { disk = new DiskTO(volTO, deviceId, path, volumeType); } return disk; }
public String getVirtualDiskPath(DiskTO disk, String storeUuid) throws Ovm3ResourceException { return getVirtualDiskPath(disk.getPath(), storeUuid); }
@Override public int compare(final DiskTO arg0, final DiskTO arg1) { return arg0.getDiskSeq() > arg1.getDiskSeq() ? 1 : -1; } });
@Override public void prepareForMigration(VirtualMachineProfile vm, DeployDestination dest) { List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Preparing " + vols.size() + " volumes for " + vm); } for (VolumeVO vol : vols) { VolumeInfo volumeInfo = volFactory.getVolume(vol.getId()); DataTO volTO = volumeInfo.getTO(); DiskTO disk = storageMgr.getDiskWithThrottling(volTO, vol.getVolumeType(), vol.getDeviceId(), vol.getPath(), vm.getServiceOfferingId(), vol.getDiskOfferingId()); DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary); disk.setDetails(getDetails(volumeInfo, dataStore)); vm.addDisk(disk); } //if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) { if (vm.getType() == VirtualMachine.Type.User) { _tmpltMgr.prepareIsoForVmProfile(vm, dest); //DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO(); //DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO); //vm.addDisk(iso); } }
KVMPhysicalDisk physicalDisk = null; KVMStoragePool pool = null; final DataTO data = volume.getData(); if (volume.getType() == Volume.Type.ISO && data.getPath() != null) { DataStoreTO dataStore = data.getDataStore(); String dataStoreUrl = null; final KVMStoragePool secondaryStorage = _storagePoolMgr.getStoragePoolByURI(volDir); physicalDisk = secondaryStorage.getPhysicalDisk(volName); } else if (volume.getType() != Volume.Type.ISO) { final PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore(); physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath()); int devId = volume.getDiskSeq().intValue(); if (volume.getType() == Volume.Type.ISO) { if (volPath == null) { disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusType); } else { if (volume.getType() == Volume.Type.DATADISK) { disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData, DiskDef.DiskFmtType.QCOW2); } else { final DataTO data = volume.getData(); final PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore(); if (volume.getType() == Volume.Type.ROOT) { final KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath()); final FilesystemDef rootFs = new FilesystemDef(physicalDisk.getPath(), "/"); vm.getDevices().addDevice(rootFs);