Search in sources :

Example 11 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class Xenserver625StorageProcessor method copyVolumeFromPrimaryToSecondary.

@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    final int wait = cmd.getWait();
    final DataStoreTO destStore = destVolume.getDataStore();
    if (destStore instanceof NfsTO) {
        SR secondaryStorage = null;
        Task task = null;
        try {
            final NfsTO nfsStore = (NfsTO) destStore;
            final String nfsVersion = nfsStore.getNfsVersion();
            final URI uri = new URI(nfsStore.getUrl());
            // Create the volume folder
            if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath(), nfsVersion)) {
                throw new InternalErrorException("Failed to create the volume folder.");
            }
            // Create a SR for the volume UUID folder
            secondaryStorage = createFileSr(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath(), nfsVersion);
            // Look up the volume on the source primary storage pool
            final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
            // Copy the volume to secondary storage
            task = srcVdi.copyAsync(conn, secondaryStorage, null, null);
            // poll every 1 seconds ,
            hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
            hypervisorResource.checkForSuccess(conn, task);
            final VDI destVdi = Types.toVDI(task, conn);
            final String destVolumeUUID = destVdi.getUuid(conn);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(destVolume.getPath() + File.separator + destVolumeUUID + ".vhd");
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            s_logger.debug("Failed to copy volume to secondary: " + e.toString());
            return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
        } finally {
            if (task != null) {
                try {
                    task.destroy(conn);
                } catch (final Exception e) {
                    s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString());
                }
            }
            hypervisorResource.removeSR(conn, secondaryStorage);
        }
    }
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Task(com.xensource.xenapi.Task) Connection(com.xensource.xenapi.Connection) InternalErrorException(com.cloud.exception.InternalErrorException) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Example 12 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class XenServerStorageProcessor method copyVolumeFromImageCacheToPrimary.

@Override
public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final int wait = cmd.getWait();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) srcData;
    final VolumeObjectTO destVolume = (VolumeObjectTO) destData;
    final DataStoreTO srcStore = srcVolume.getDataStore();
    if (srcStore instanceof NfsTO) {
        final NfsTO nfsStore = (NfsTO) srcStore;
        try {
            final PrimaryDataStoreTO destStore = (PrimaryDataStoreTO) destVolume.getDataStore();
            final SR primaryStoragePool = hypervisorResource.getStorageRepository(conn, CitrixHelper.getSRNameLabel(destStore.getUuid(), destStore.getPoolType(), destStore.getPath()));
            final String srUuid = primaryStoragePool.getUuid(conn);
            final URI uri = new URI(nfsStore.getUrl());
            final String volumePath = uri.getHost() + ":" + uri.getPath() + nfsStore.getPathSeparator() + srcVolume.getPath();
            final String uuid = copy_vhd_from_secondarystorage(conn, volumePath, srUuid, wait);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(uuid);
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
            s_logger.warn(msg, e);
            return new CopyCmdAnswer(e.toString());
        }
    }
    s_logger.debug("unsupported protocol");
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 13 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class XenServerStorageProcessor method createManagedVolumeFromManagedSnapshot.

Answer createManagedVolumeFromManagedSnapshot(final CopyCommand cmd) {
    try {
        final Connection conn = hypervisorResource.getConnection();
        final Map<String, String> srcOptions = cmd.getOptions();
        final String src_iScsiName = srcOptions.get(DiskTO.IQN);
        final String srcStorageHost = srcOptions.get(DiskTO.STORAGE_HOST);
        final String srcChapInitiatorUsername = srcOptions.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String srcChapInitiatorSecret = srcOptions.get(DiskTO.CHAP_INITIATOR_SECRET);
        final SR srcSr = hypervisorResource.getIscsiSR(conn, src_iScsiName, srcStorageHost, src_iScsiName, srcChapInitiatorUsername, srcChapInitiatorSecret, false);
        final Map<String, String> destOptions = cmd.getOptions2();
        final String dest_iScsiName = destOptions.get(DiskTO.IQN);
        final String destStorageHost = destOptions.get(DiskTO.STORAGE_HOST);
        final String destChapInitiatorUsername = destOptions.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String destChapInitiatorSecret = destOptions.get(DiskTO.CHAP_INITIATOR_SECRET);
        final SR destSr = hypervisorResource.getIscsiSR(conn, dest_iScsiName, destStorageHost, dest_iScsiName, destChapInitiatorUsername, destChapInitiatorSecret, false);
        // there should only be one VDI in this SR
        final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
        final VDI vdiCopy = srcVdi.copy(conn, destSr);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setSize(vdiCopy.getVirtualSize(conn));
        newVol.setPath(vdiCopy.getUuid(conn));
        newVol.setFormat(ImageFormat.VHD);
        hypervisorResource.removeSR(conn, srcSr);
        hypervisorResource.removeSR(conn, destSr);
        return new CopyCmdAnswer(newVol);
    } catch (final Exception ex) {
        s_logger.warn("Failed to copy snapshot to volume: " + ex.toString(), ex);
        return new CopyCmdAnswer(ex.getMessage());
    }
}
Also used : Connection(com.xensource.xenapi.Connection) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 14 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class XenServerStorageProcessor method introduceObject.

@Override
public Answer introduceObject(final IntroduceObjectCmd cmd) {
    try {
        final Connection conn = hypervisorResource.getConnection();
        final DataStoreTO store = cmd.getDataTO().getDataStore();
        final SR poolSr = hypervisorResource.getStorageRepository(conn, store.getUuid());
        poolSr.scan(conn);
        return new IntroduceObjectAnswer(cmd.getDataTO());
    } catch (final Exception e) {
        s_logger.debug("Failed to introduce object", e);
        return new Answer(cmd, false, e.toString());
    }
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) DettachAnswer(org.apache.cloudstack.storage.command.DettachAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) Connection(com.xensource.xenapi.Connection) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 15 with SR

use of com.xensource.xenapi.SR in project cloudstack by apache.

the class XenServerStorageProcessor method copyVolumeFromPrimaryToSecondary.

@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    final int wait = cmd.getWait();
    final DataStoreTO destStore = destVolume.getDataStore();
    if (destStore instanceof NfsTO) {
        SR secondaryStorage = null;
        try {
            final NfsTO nfsStore = (NfsTO) destStore;
            final URI uri = new URI(nfsStore.getUrl());
            final String nfsVersion = nfsStore.getNfsVersion();
            // Create the volume folder
            if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath(), nfsVersion)) {
                throw new InternalErrorException("Failed to create the volume folder.");
            }
            // Create a SR for the volume UUID folder
            secondaryStorage = hypervisorResource.createNfsSRbyURI(conn, new URI(nfsStore.getUrl() + nfsStore.getPathSeparator() + destVolume.getPath()), false);
            // Look up the volume on the source primary storage pool
            final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
            // Copy the volume to secondary storage
            final VDI destVdi = hypervisorResource.cloudVDIcopy(conn, srcVdi, secondaryStorage, wait);
            final String destVolumeUUID = destVdi.getUuid(conn);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(destVolume.getPath() + nfsStore.getPathSeparator() + destVolumeUUID + ".vhd");
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            s_logger.debug("Failed to copy volume to secondary: " + e.toString());
            return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
        } finally {
            hypervisorResource.removeSR(conn, secondaryStorage);
        }
    }
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) InternalErrorException(com.cloud.exception.InternalErrorException) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Aggregations

SR (com.xensource.xenapi.SR)165 XenAPIException (com.xensource.xenapi.Types.XenAPIException)105 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)102 XmlRpcException (org.apache.xmlrpc.XmlRpcException)97 Connection (com.xensource.xenapi.Connection)92 VDI (com.xensource.xenapi.VDI)81 InternalErrorException (com.cloud.exception.InternalErrorException)64 HashMap (java.util.HashMap)45 Host (com.xensource.xenapi.Host)40 PBD (com.xensource.xenapi.PBD)37 URI (java.net.URI)36 NfsTO (com.cloud.agent.api.to.NfsTO)34 Test (org.junit.Test)27 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)26 Task (com.xensource.xenapi.Task)26 DataTO (com.cloud.agent.api.to.DataTO)25 Answer (com.cloud.agent.api.Answer)22 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)21 IOException (java.io.IOException)20 MalformedURLException (java.net.MalformedURLException)20