Search in sources :

Example 21 with DiskTO

use of com.cloud.agent.api.to.DiskTO in project cloudstack by apache.

the class KVMStoragePoolManager method disconnectPhysicalDisksViaVmSpec.

public boolean disconnectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) {
    if (vmSpec == null) {
        /* CloudStack often tries to stop VMs that shouldn't be running, to ensure a known state,
               for example if we lose communication with the agent and the VM is brought up elsewhere.
               We may not know about these yet. This might mean that we can't use the vmspec map, because
               when we restart the agent we lose all of the info about running VMs. */
        s_logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map");
        return true;
    }
    boolean result = true;
    final String vmName = vmSpec.getName();
    List<DiskTO> disks = Arrays.asList(vmSpec.getDisks());
    for (DiskTO disk : disks) {
        if (disk.getType() != Volume.Type.ISO) {
            s_logger.debug("Disconnecting disk " + disk.getPath());
            VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
            PrimaryDataStoreTO store = (PrimaryDataStoreTO) vol.getDataStore();
            KVMStoragePool pool = getStoragePool(store.getPoolType(), store.getUuid());
            if (pool == null) {
                s_logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic");
                continue;
            }
            StorageAdaptor adaptor = getStorageAdaptor(pool.getType());
            // if a disk fails to disconnect, still try to disconnect remaining
            boolean subResult = adaptor.disconnectPhysicalDisk(vol.getPath(), pool);
            if (!subResult) {
                s_logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString());
                result = false;
            }
        }
    }
    return result;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 22 with DiskTO

use of com.cloud.agent.api.to.DiskTO in project cloudstack by apache.

the class Ovm3VmSupport method createVbds.

/*
     * Add rootdisk, datadisk and iso's
     */
public Boolean createVbds(Xen.Vm vm, VirtualMachineTO spec) {
    if (spec.getDisks() == null) {
        LOGGER.info("No disks defined for " + vm.getVmName());
        return false;
    }
    for (DiskTO disk : spec.getDisks()) {
        try {
            if (disk.getType() == Volume.Type.ROOT) {
                VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
                String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid());
                vm.addRootDisk(diskFile);
                vm.setPrimaryPoolUuid(vol.getDataStore().getUuid());
                LOGGER.debug("Adding root disk: " + diskFile);
            } else if (disk.getType() == Volume.Type.ISO) {
                DataTO isoTO = disk.getData();
                if (isoTO.getPath() != null) {
                    TemplateObjectTO template = (TemplateObjectTO) isoTO;
                    DataStoreTO store = template.getDataStore();
                    if (!(store instanceof NfsTO)) {
                        throw new CloudRuntimeException("unsupported protocol");
                    }
                    NfsTO nfsStore = (NfsTO) store;
                    String secPoolUuid = pool.setupSecondaryStorage(nfsStore.getUrl());
                    String isoPath = config.getAgentSecStoragePath() + "/" + secPoolUuid + "/" + template.getPath();
                    vm.addIso(isoPath);
                    /* check if secondary storage is mounted */
                    LOGGER.debug("Adding ISO: " + isoPath);
                }
            } else if (disk.getType() == Volume.Type.DATADISK) {
                VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
                String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid());
                vm.addDataDisk(diskFile);
                LOGGER.debug("Adding data disk: " + diskFile);
            } else {
                throw new CloudRuntimeException("Unknown disk type: " + disk.getType());
            }
        } catch (Exception e) {
            LOGGER.debug("CreateVbds failed", e);
            throw new CloudRuntimeException("Exception" + e.getMessage(), e);
        }
    }
    return true;
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 23 with DiskTO

use of com.cloud.agent.api.to.DiskTO in project cloudstack by apache.

the class Ovm3HypervisorResourceTest method addDiskToSpec.

public void addDiskToSpec(VirtualMachineTO vmspec, String uuid, String dsuuid, String path) {
    ArrayList<DiskTO> disks;
    if (vmspec.getDisks() != null) {
        disks = new ArrayList<DiskTO>(Arrays.asList(vmspec.getDisks()));
    } else {
        disks = new ArrayList<DiskTO>();
    }
    DiskTO disk = new DiskTO();
    VolumeObjectTO volume = new VolumeObjectTO();
    NfsTO nfsDataStore = new NfsTO();
    nfsDataStore.setUuid(dsuuid);
    volume.setDataStore(nfsDataStore);
    volume.setPath(path);
    volume.setUuid(uuid);
    disk.setData(volume);
    disk.setType(Volume.Type.ROOT);
    disks.add(disk);
    vmspec.setDisks(disks.toArray(new DiskTO[disks.size()]));
}
Also used : VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 24 with DiskTO

use of com.cloud.agent.api.to.DiskTO in project cloudstack by apache.

the class VmwareResource method postDiskConfigBeforeStart.

private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec, DiskTO[] sortedDisks, int ideControllerKey, int scsiControllerKey, Map<String, String> iqnToPath, VmwareHypervisorHost hyperHost, VmwareContext context) throws Exception {
    VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
    for (DiskTO vol : sortedDisks) {
        if (vol.getType() == Volume.Type.ISO)
            continue;
        VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
        VirtualMachineDiskInfo diskInfo = getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
        assert (diskInfo != null);
        String[] diskChain = diskInfo.getDiskChain();
        assert (diskChain.length > 0);
        Map<String, String> details = vol.getDetails();
        boolean managed = false;
        if (details != null) {
            managed = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
        }
        DatastoreFile file = new DatastoreFile(diskChain[0]);
        if (managed) {
            DatastoreFile originalFile = new DatastoreFile(volumeTO.getPath());
            if (!file.getFileBaseName().equalsIgnoreCase(originalFile.getFileBaseName())) {
                if (s_logger.isInfoEnabled())
                    s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + diskChain[0]);
            }
        } else {
            if (!file.getFileBaseName().equalsIgnoreCase(volumeTO.getPath())) {
                if (s_logger.isInfoEnabled())
                    s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + file.getFileBaseName());
            }
        }
        VolumeObjectTO volInSpec = getVolumeInSpec(vmSpec, volumeTO);
        if (volInSpec != null) {
            if (managed) {
                String datastoreVolumePath = diskChain[0];
                iqnToPath.put(details.get(DiskTO.IQN), datastoreVolumePath);
                vol.setPath(datastoreVolumePath);
                volumeTO.setPath(datastoreVolumePath);
                volInSpec.setPath(datastoreVolumePath);
            } else {
                volInSpec.setPath(file.getFileBaseName());
            }
            volInSpec.setChainInfo(_gson.toJson(diskInfo));
        }
    }
}
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) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 25 with DiskTO

use of com.cloud.agent.api.to.DiskTO in project cloudstack by apache.

the class VmwareResource method inferDatastoreDetailsFromDiskInfo.

private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastoreDetailsFromDiskInfo(VmwareHypervisorHost hyperHost, VmwareContext context, DiskTO[] disks, Command cmd) throws Exception {
    HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> mapIdToMors = new HashMap<String, Pair<ManagedObjectReference, DatastoreMO>>();
    assert (hyperHost != null) && (context != null);
    for (DiskTO vol : disks) {
        if (vol.getType() != Volume.Type.ISO) {
            VolumeObjectTO volumeTO = (VolumeObjectTO) vol.getData();
            DataStoreTO primaryStore = volumeTO.getDataStore();
            String poolUuid = primaryStore.getUuid();
            if (mapIdToMors.get(poolUuid) == null) {
                boolean isManaged = false;
                Map<String, String> details = vol.getDetails();
                if (details != null) {
                    isManaged = Boolean.parseBoolean(details.get(DiskTO.MANAGED));
                }
                if (isManaged) {
                    // details should not be null for managed storage (it may or may not be null for non-managed storage)
                    String iScsiName = details.get(DiskTO.IQN);
                    String datastoreName = VmwareResource.getDatastoreName(iScsiName);
                    ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, datastoreName);
                    // create the datastore, and create a VMDK file in the datastore
                    if (morDatastore == null) {
                        morDatastore = _storageProcessor.prepareManagedStorage(context, hyperHost, null, iScsiName, details.get(DiskTO.STORAGE_HOST), Integer.parseInt(details.get(DiskTO.STORAGE_PORT)), volumeTO.getVolumeType() == Volume.Type.ROOT ? volumeTO.getName() : null, details.get(DiskTO.CHAP_INITIATOR_USERNAME), details.get(DiskTO.CHAP_INITIATOR_SECRET), details.get(DiskTO.CHAP_TARGET_USERNAME), details.get(DiskTO.CHAP_TARGET_SECRET), Long.parseLong(details.get(DiskTO.VOLUME_SIZE)), cmd);
                        DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDatastore);
                        String datastoreVolumePath = dsMo.getDatastorePath((volumeTO.getVolumeType() == Volume.Type.ROOT ? volumeTO.getName() : dsMo.getName()) + ".vmdk");
                        volumeTO.setPath(datastoreVolumePath);
                        vol.setPath(datastoreVolumePath);
                    }
                    mapIdToMors.put(datastoreName, new Pair<ManagedObjectReference, DatastoreMO>(morDatastore, new DatastoreMO(context, morDatastore)));
                } else {
                    ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolUuid);
                    if (morDatastore == null) {
                        String msg = "Failed to get the mounted datastore for the volume's pool " + poolUuid;
                        s_logger.error(msg);
                        throw new Exception(msg);
                    }
                    mapIdToMors.put(poolUuid, new Pair<ManagedObjectReference, DatastoreMO>(morDatastore, new DatastoreMO(context, morDatastore)));
                }
            }
        }
    }
    return mapIdToMors;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) HashMap(java.util.HashMap) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair) DiskTO(com.cloud.agent.api.to.DiskTO)

Aggregations

DiskTO (com.cloud.agent.api.to.DiskTO)52 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)16 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)16 Answer (com.cloud.agent.api.Answer)13 DataTO (com.cloud.agent.api.to.DataTO)13 InternalErrorException (com.cloud.exception.InternalErrorException)13 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)13 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)13 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)12 NfsTO (com.cloud.agent.api.to.NfsTO)11 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)9 Connect (org.libvirt.Connect)9 LibvirtException (org.libvirt.LibvirtException)9 NicTO (com.cloud.agent.api.to.NicTO)8 HashMap (java.util.HashMap)7 DettachAnswer (org.apache.cloudstack.storage.command.DettachAnswer)7 VolumeVO (com.cloud.storage.VolumeVO)6 XenAPIException (com.xensource.xenapi.Types.XenAPIException)6 VDI (com.xensource.xenapi.VDI)6