Search in sources :

Example 1 with SR

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

the class CitrixResourceBase method getLocalEXTSR.

protected SR getLocalEXTSR(final Connection conn) {
    try {
        final Map<SR, SR.Record> map = SR.getAllRecords(conn);
        if (map != null && !map.isEmpty()) {
            for (final Map.Entry<SR, SR.Record> entry : map.entrySet()) {
                final SR.Record srRec = entry.getValue();
                if (SRType.FILE.equals(srRec.type) || SRType.EXT.equals(srRec.type)) {
                    final Set<PBD> pbds = srRec.PBDs;
                    if (pbds == null) {
                        continue;
                    }
                    for (final PBD pbd : pbds) {
                        final Host host = pbd.getHost(conn);
                        if (!isRefNull(host) && host.getUuid(conn).equals(_host.getUuid())) {
                            if (!pbd.getCurrentlyAttached(conn)) {
                                pbd.plug(conn);
                            }
                            final SR sr = entry.getKey();
                            sr.scan(conn);
                            return sr;
                        }
                    }
                }
            }
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to get local EXTSR in host:" + _host.getUuid() + e.toString();
        s_logger.warn(msg);
    } catch (final XmlRpcException e) {
        final String msg = "Unable to get local EXTSR in host:" + _host.getUuid() + e.getCause();
        s_logger.warn(msg);
    }
    return null;
}
Also used : PBD(com.xensource.xenapi.PBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) Map(java.util.Map) HashMap(java.util.HashMap) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 2 with SR

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

the class CitrixResourceBase method probeScisiId.

private String probeScisiId(Connection conn, Host host, Map<String, String> deviceConfig, String type, String srNameLabel, String lunid, Map<String, String> smConfig) throws XenAPIException, XmlRpcException {
    SR sr = null;
    String scsiid = null;
    try {
        sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, type, "user", true, smConfig);
    } catch (final XenAPIException e) {
        final String errmsg = e.toString();
        if (errmsg.contains("SR_BACKEND_FAILURE_107")) {
            final String[] lun = errmsg.split("<LUN>");
            boolean found = false;
            for (int i = 1; i < lun.length; i++) {
                final int blunindex = lun[i].indexOf("<LUNid>") + 7;
                final int elunindex = lun[i].indexOf("</LUNid>");
                String ilun = lun[i].substring(blunindex, elunindex);
                ilun = ilun.trim();
                if (ilun.equals(lunid)) {
                    final int bscsiindex = lun[i].indexOf("<SCSIid>") + 8;
                    final int escsiindex = lun[i].indexOf("</SCSIid>");
                    scsiid = lun[i].substring(bscsiindex, escsiindex);
                    scsiid = scsiid.trim();
                    found = true;
                    break;
                }
            }
            if (!found) {
                final String msg = "can not find LUN " + lunid + " in " + errmsg;
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
        } else {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " due to  " + e.toString();
            s_logger.warn(msg, e);
            throw new CloudRuntimeException(msg, e);
        }
    }
    return scsiid;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Example 3 with SR

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

the class XenServerStorageProcessor method execute.

protected Answer execute(final AttachPrimaryDataStoreCmd cmd) {
    final String dataStoreUri = cmd.getDataStore();
    final Connection conn = hypervisorResource.getConnection();
    try {
        final DecodedDataObject obj = Decoder.decode(dataStoreUri);
        final DecodedDataStore store = obj.getStore();
        final SR sr = hypervisorResource.getStorageRepository(conn, store.getUuid());
        hypervisorResource.setupHeartbeatSr(conn, sr, false);
        final long capacity = sr.getPhysicalSize(conn);
        final long available = capacity - sr.getPhysicalUtilisation(conn);
        if (capacity == -1) {
            final String msg = "Pool capacity is -1! pool: ";
            s_logger.warn(msg);
            return new Answer(cmd, false, msg);
        }
        final AttachPrimaryDataStoreAnswer answer = new AttachPrimaryDataStoreAnswer(cmd);
        answer.setCapacity(capacity);
        answer.setUuid(sr.getUuid(conn));
        answer.setAvailable(available);
        return answer;
    } catch (final XenAPIException e) {
        final String msg = "AttachPrimaryDataStoreCmd add XenAPIException:" + e.toString();
        s_logger.warn(msg, e);
        return new Answer(cmd, false, msg);
    } catch (final Exception e) {
        final String msg = "AttachPrimaryDataStoreCmd failed:" + e.getMessage();
        s_logger.warn(msg, e);
        return new Answer(cmd, false, msg);
    }
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) AttachPrimaryDataStoreAnswer(org.apache.cloudstack.storage.command.AttachPrimaryDataStoreAnswer) 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) AttachPrimaryDataStoreAnswer(org.apache.cloudstack.storage.command.AttachPrimaryDataStoreAnswer) DecodedDataStore(com.cloud.utils.storage.encoding.DecodedDataStore) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) DecodedDataObject(com.cloud.utils.storage.encoding.DecodedDataObject) 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 4 with SR

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

the class XenServerStorageProcessor method getSRByNameLabel.

protected SR getSRByNameLabel(final Connection conn, final String nameLabel) throws BadServerResponse, XenAPIException, XmlRpcException {
    final Set<SR> srs = SR.getByNameLabel(conn, nameLabel);
    if (srs.size() != 1) {
        throw new CloudRuntimeException("storage uuid: " + nameLabel + " is not unique");
    }
    final SR poolsr = srs.iterator().next();
    return poolsr;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 5 with SR

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

the class XenServerStorageProcessor method createVolumeFromSnapshot2.

protected Answer createVolumeFromSnapshot2(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)

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