Search in sources :

Example 11 with VirtualMachineDiskInfoBuilder

use of com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder in project cloudstack by apache.

the class VmwareResource method createAnswerForCmd.

Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObjectToList, Command cmd, Map<Integer, Long> volumeDeviceKey) throws Exception {
    List<VolumeObjectTO> volumeToList = new ArrayList<>();
    VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
    VirtualDisk[] disks = vmMo.getAllDiskDevice();
    Answer answer;
    if (s_logger.isTraceEnabled()) {
        s_logger.trace(String.format("creating answer for %s", cmd.getClass().getSimpleName()));
    }
    if (cmd instanceof MigrateVolumeCommand) {
        if (disks.length == 1) {
            String volumePath = vmMo.getVmdkFileBaseName(disks[0]);
            return new MigrateVolumeAnswer(cmd, true, null, volumePath);
        }
        throw new CloudRuntimeException("not expecting more then  one disk after migrate volume command");
    } else if (cmd instanceof MigrateVmToPoolCommand) {
        volumeToList = volumeObjectToList;
        return new MigrateVmToPoolAnswer((MigrateVmToPoolCommand) cmd, volumeToList);
    }
    return new Answer(cmd, false, null);
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) ArrayList(java.util.ArrayList) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) VirtualDisk(com.vmware.vim25.VirtualDisk) SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 12 with VirtualMachineDiskInfoBuilder

use of com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder in project cloudstack by apache.

the class VmwareStorageProcessor method getMatchingExistingDisk.

private VirtualMachineDiskInfo getMatchingExistingDisk(VmwareHypervisorHost hyperHost, VmwareContext context, VirtualMachineMO vmMo, DiskTO vol) throws Exception {
    VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
    if (diskInfoBuilder != null) {
        VolumeObjectTO volume = (VolumeObjectTO) vol.getData();
        ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, volume.getDataStore().getUuid());
        DatastoreMO dsMo = new DatastoreMO(context, morDs);
        String dsName = dsMo.getName();
        String diskBackingFileBaseName = volume.getPath();
        VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(diskBackingFileBaseName, dsName);
        if (diskInfo != null) {
            s_logger.info("Found existing disk info from volume path: " + volume.getPath());
            return diskInfo;
        } else {
            String chainInfo = volume.getChainInfo();
            if (chainInfo != null) {
                VirtualMachineDiskInfo infoInChain = _gson.fromJson(chainInfo, VirtualMachineDiskInfo.class);
                if (infoInChain != null) {
                    String[] disks = infoInChain.getDiskChain();
                    if (disks.length > 0) {
                        for (String diskPath : disks) {
                            DatastoreFile file = new DatastoreFile(diskPath);
                            diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName);
                            if (diskInfo != null) {
                                s_logger.info("Found existing disk from chain info: " + diskPath);
                                return diskInfo;
                            }
                        }
                    }
                    if (diskInfo == null) {
                        diskInfo = diskInfoBuilder.getDiskInfoByDeviceBusName(infoInChain.getDiskDeviceBusName());
                        if (diskInfo != null) {
                            s_logger.info("Found existing disk from from chain device bus information: " + infoInChain.getDiskDeviceBusName());
                            return diskInfo;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 13 with VirtualMachineDiskInfoBuilder

use of com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder in project cloudstack by apache.

the class VmwareStorageProcessor method syncVolumePath.

@Override
public Answer syncVolumePath(SyncVolumePathCommand cmd) {
    DiskTO disk = cmd.getDisk();
    VolumeObjectTO volumeTO = (VolumeObjectTO) disk.getData();
    DataStoreTO primaryStore = volumeTO.getDataStore();
    String volumePath = volumeTO.getPath();
    String vmName = volumeTO.getVmName();
    boolean datastoreChangeObserved = false;
    boolean volumePathChangeObserved = false;
    String chainInfo = null;
    try {
        VmwareContext context = hostService.getServiceContext(null);
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
        if (vmMo == null) {
            vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
            if (vmMo == null) {
                String msg = "Unable to find the VM to execute SyncVolumePathCommand, vmName: " + vmName;
                s_logger.error(msg);
                throw new Exception(msg);
            }
        }
        String datastoreUUID = primaryStore.getUuid();
        if (disk.getDetails().get(DiskTO.PROTOCOL_TYPE) != null && disk.getDetails().get(DiskTO.PROTOCOL_TYPE).equalsIgnoreCase("DatastoreCluster")) {
            VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk(hyperHost, context, vmMo, disk);
            VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
            if (diskInfoBuilder != null && matchingExistingDisk != null) {
                String[] diskChain = matchingExistingDisk.getDiskChain();
                assert (diskChain.length > 0);
                DatastoreFile file = new DatastoreFile(diskChain[0]);
                if (!file.getFileBaseName().equalsIgnoreCase(volumePath)) {
                    if (s_logger.isInfoEnabled())
                        s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumePath + " -> " + file.getFileBaseName());
                    volumePathChangeObserved = true;
                    volumePath = file.getFileBaseName();
                    volumeTO.setPath(volumePath);
                    chainInfo = _gson.toJson(matchingExistingDisk);
                }
                DatastoreMO diskDatastoreMofromVM = getDiskDatastoreMofromVM(hyperHost, context, vmMo, disk, diskInfoBuilder);
                if (diskDatastoreMofromVM != null) {
                    String actualPoolUuid = diskDatastoreMofromVM.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
                    if (!actualPoolUuid.equalsIgnoreCase(primaryStore.getUuid())) {
                        s_logger.warn(String.format("Volume %s found to be in a different storage pool %s", volumePath, actualPoolUuid));
                        datastoreChangeObserved = true;
                        datastoreUUID = actualPoolUuid;
                        chainInfo = _gson.toJson(matchingExistingDisk);
                    }
                }
            }
        }
        SyncVolumePathAnswer answer = new SyncVolumePathAnswer(disk);
        if (datastoreChangeObserved) {
            answer.setContextParam("datastoreName", datastoreUUID);
        }
        if (volumePathChangeObserved) {
            answer.setContextParam("volumePath", volumePath);
        }
        if (chainInfo != null && !chainInfo.isEmpty()) {
            answer.setContextParam("chainInfo", chainInfo);
        }
        return answer;
    } catch (Throwable e) {
        return new SyncVolumePathAnswer(hostService.createLogMessageException(e, cmd));
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) SyncVolumePathAnswer(org.apache.cloudstack.storage.command.SyncVolumePathAnswer) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 14 with VirtualMachineDiskInfoBuilder

use of com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder in project cloudstack by apache.

the class ResultWrapper method getVolumeFromVirtualDisk.

private VolumeVO getVolumeFromVirtualDisk(VMInstanceVO vmInstance, long storagePoolId, List<VirtualDevice> allDevices, VirtualDisk disk) throws Exception {
    List<VolumeVO> volumes = volumeDao.findByInstance(vmInstance.getId());
    if (volumes == null || volumes.size() == 0) {
        String errMsg = "Error: The VMware virtual disk '" + disk + "' could not be mapped to a CloudStack volume. " + "There were no volumes for the VM with the following ID: " + vmInstance.getId() + ".";
        throw new Exception(errMsg);
    }
    VirtualMachineDiskInfoBuilder diskInfoBuilder = VMwareUtil.getDiskInfoBuilder(allDevices);
    for (VolumeVO volume : volumes) {
        Long poolId = volume.getPoolId();
        if (poolId != null && poolId == storagePoolId) {
            StoragePoolVO storagePool = storagePoolDao.findById(poolId);
            String path = storagePool.getPath();
            String charToSearchFor = "/";
            int index = path.lastIndexOf(charToSearchFor) + charToSearchFor.length();
            String datastoreName = path.substring(index);
            VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(volume.getPath(), datastoreName);
            if (diskInfo != null) {
                String deviceBusName = VMwareUtil.getDeviceBusName(allDevices, disk);
                if (deviceBusName.equals(diskInfo.getDiskDeviceBusName())) {
                    return volume;
                }
            }
        }
    }
    return null;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder)

Aggregations

VirtualMachineDiskInfoBuilder (com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder)14 VirtualMachineDiskInfo (org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo)11 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)7 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)7 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)5 Pair (com.cloud.utils.Pair)5 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 RemoteException (java.rmi.RemoteException)5 DiskTO (com.cloud.agent.api.to.DiskTO)4 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)4 VirtualDisk (com.vmware.vim25.VirtualDisk)4 ArrayList (java.util.ArrayList)4 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)3 CloudException (com.cloud.exception.CloudException)3 InternalErrorException (com.cloud.exception.InternalErrorException)3