Search in sources :

Example 51 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO 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 52 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO 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 53 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class Ovm3StorageProcessorTest method deleteCommandTest.

/**
     * Delete an object
     *
     * @throws ConfigurationException
     */
@Test
public void deleteCommandTest() throws ConfigurationException {
    con = prepare();
    VolumeObjectTO vol = volume(ovmObject.newUuid(), ovmObject.newUuid(), linux.getRepoId(), linux.getVirtualDisksDir());
    DeleteCommand delete = new DeleteCommand(vol);
    Answer ra = hypervisor.executeRequest(delete);
    results.basicBooleanTest(ra.getResult());
    TemplateObjectTO template = template(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    delete = new DeleteCommand(template);
    ra = hypervisor.executeRequest(delete);
    results.basicBooleanTest(ra.getResult(), false);
    SnapshotObjectTO snap = snapshot(ovmObject.newUuid(), ovmObject.newUuid(), ovmObject.newUuid(linux.getRemote()), linux.getRemote());
    delete = new DeleteCommand(snap);
    ra = hypervisor.executeRequest(delete);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) LinuxTest(com.cloud.hypervisor.ovm3.objects.LinuxTest) Test(org.junit.Test) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) StoragePluginTest(com.cloud.hypervisor.ovm3.objects.StoragePluginTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 54 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO 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 55 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class Ovm3StorageProcessorTest method volume.

private VolumeObjectTO volume(final String uuid, final String dsuuid, final String storeUrl, final String path) {
    VolumeObjectTO volume = new VolumeObjectTO();
    NfsTO nfsDataStore = new NfsTO();
    nfsDataStore.setUuid(dsuuid);
    nfsDataStore.setUrl(storeUrl);
    volume.setDataStore(nfsDataStore);
    volume.setPath(path);
    volume.setUuid(uuid);
    return volume;
}
Also used : VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO)

Aggregations

VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)108 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)59 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)45 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)36 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)36 DataTO (com.cloud.agent.api.to.DataTO)31 NfsTO (com.cloud.agent.api.to.NfsTO)31 InternalErrorException (com.cloud.exception.InternalErrorException)27 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)20 Connection (com.xensource.xenapi.Connection)19 VDI (com.xensource.xenapi.VDI)17 IOException (java.io.IOException)17 Answer (com.cloud.agent.api.Answer)16 DiskTO (com.cloud.agent.api.to.DiskTO)16 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)16 RemoteException (java.rmi.RemoteException)16 ArrayList (java.util.ArrayList)16 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)16 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14