Search in sources :

Example 21 with SR

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

the class CitrixResourceBase method getSRByNameLabel.

protected SR getSRByNameLabel(Connection conn, String name) throws BadServerResponse, XenAPIException, XmlRpcException {
    Set<SR> srs = SR.getByNameLabel(conn, name);
    SR ressr = null;
    for (SR sr : srs) {
        Set<PBD> pbds;
        pbds = sr.getPBDs(conn);
        for (PBD pbd : pbds) {
            PBD.Record pbdr = pbd.getRecord(conn);
            if (pbdr.host != null) {
                ressr = sr;
                break;
            }
        }
    }
    return ressr;
}
Also used : PBD(com.xensource.xenapi.PBD) SR(com.xensource.xenapi.SR)

Example 22 with SR

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

the class CitrixResourceBase method startvmfailhandle.

protected void startvmfailhandle(final Connection conn, final VM vm, final List<Ternary<SR, VDI, VolumeVO>> mounts) {
    if (vm != null) {
        try {
            if (vm.getPowerState(conn) == VmPowerState.RUNNING) {
                try {
                    vm.hardShutdown(conn);
                } catch (final Exception e) {
                    final String msg = "VM hardshutdown failed due to " + e.toString();
                    s_logger.warn(msg, e);
                }
            }
            if (vm.getPowerState(conn) == VmPowerState.HALTED) {
                try {
                    vm.destroy(conn);
                } catch (final Exception e) {
                    final String msg = "VM destroy failed due to " + e.toString();
                    s_logger.warn(msg, e);
                }
            }
        } catch (final Exception e) {
            final String msg = "VM getPowerState failed due to " + e.toString();
            s_logger.warn(msg, e);
        }
    }
    if (mounts != null) {
        for (final Ternary<SR, VDI, VolumeVO> mount : mounts) {
            final VDI vdi = mount.second();
            Set<VBD> vbds = null;
            try {
                vbds = vdi.getVBDs(conn);
            } catch (final Exception e) {
                final String msg = "VDI getVBDS failed due to " + e.toString();
                s_logger.warn(msg, e);
                continue;
            }
            for (final VBD vbd : vbds) {
                try {
                    vbd.unplug(conn);
                    vbd.destroy(conn);
                } catch (final Exception e) {
                    final String msg = "VBD destroy failed due to " + e.toString();
                    s_logger.warn(msg, e);
                }
            }
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VBD(com.xensource.xenapi.VBD) VDI(com.xensource.xenapi.VDI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SR(com.xensource.xenapi.SR)

Example 23 with SR

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

the class CitrixResourceBase method getSRByNameLabelandHost.

protected SR getSRByNameLabelandHost(final Connection conn, final String name) throws BadServerResponse, XenAPIException, XmlRpcException {
    final Set<SR> srs = SR.getByNameLabel(conn, name);
    SR ressr = null;
    for (final SR sr : srs) {
        Set<PBD> pbds;
        pbds = sr.getPBDs(conn);
        for (final PBD pbd : pbds) {
            final PBD.Record pbdr = pbd.getRecord(conn);
            if (pbdr.host != null && pbdr.host.getUuid(conn).equals(_host.getUuid())) {
                if (!pbdr.currentlyAttached) {
                    pbd.plug(conn);
                }
                ressr = sr;
                break;
            }
        }
    }
    return ressr;
}
Also used : PBD(com.xensource.xenapi.PBD) SR(com.xensource.xenapi.SR)

Example 24 with SR

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

the class XenServer610MigrateWithStorageReceiveCommandWrapper method execute.

@Override
public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) {
    final Connection connection = xenServer610Resource.getConnection();
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final List<Pair<VolumeTO, String>> volumeToStorageUuid = command.getVolumeToStorageUuid();
    try {
        // In a cluster management server setup, the migrate with storage receive and send
        // commands and answers may have to be forwarded to another management server. This
        // happens when the host/resource on which the command has to be executed is owned
        // by the second management server. The serialization/deserialization of the command
        // and answers fails as the xapi SR and Network class type isn't understand by the
        // agent attache. Seriliaze the SR and Network objects here to a string and pass in
        // the answer object. It'll be deserialzed and object created in migrate with
        // storage send command execution.
        // Get a map of all the SRs to which the vdis will be migrated.
        final List<Pair<VolumeTO, Object>> volumeToSr = new ArrayList<>();
        for (final Pair<VolumeTO, String> entry : volumeToStorageUuid) {
            final String storageUuid = entry.second();
            final SR sr = xenServer610Resource.getStorageRepository(connection, storageUuid);
            volumeToSr.add(new Pair<VolumeTO, Object>(entry.first(), sr));
        }
        // Get the list of networks to which the vifs will attach.
        final List<Pair<NicTO, Object>> nicToNetwork = new ArrayList<Pair<NicTO, Object>>();
        for (final NicTO nicTo : vmSpec.getNics()) {
            final Network network = xenServer610Resource.getNetwork(connection, nicTo);
            nicToNetwork.add(new Pair<NicTO, Object>(nicTo, network));
        }
        final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null);
        final Network network = nativeNetworkForTraffic.getNetwork();
        final XsHost xsHost = xenServer610Resource.getHost();
        final String uuid = xsHost.getUuid();
        final Map<String, String> other = new HashMap<String, String>();
        other.put("live", "true");
        final Host host = Host.getByUuid(connection, uuid);
        final Map<String, String> token = host.migrateReceive(connection, network, other);
        return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token);
    } catch (final CloudRuntimeException e) {
        s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageReceiveAnswer(command, e);
    } catch (final Exception e) {
        s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageReceiveAnswer(command, e);
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeTO(com.cloud.agent.api.to.VolumeTO) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) Pair(com.cloud.utils.Pair) SR(com.xensource.xenapi.SR) NicTO(com.cloud.agent.api.to.NicTO)

Example 25 with SR

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

the class CitrixResourceBase method getIscsiSR.

public SR getIscsiSR(final Connection conn, final String srNameLabel, final String target, String path, final String chapInitiatorUsername, final String chapInitiatorPassword, final boolean resignature, final String srType, final boolean ignoreIntroduceException) {
    synchronized (srNameLabel.intern()) {
        final Map<String, String> deviceConfig = new HashMap<String, String>();
        try {
            if (path.endsWith("/")) {
                path = path.substring(0, path.length() - 1);
            }
            final String[] tmp = path.split("/");
            if (tmp.length != 3) {
                final String msg = "Wrong iscsi path " + path + " it should be /targetIQN/LUN";
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
            final String targetiqn = tmp[1].trim();
            final String lunid = tmp[2].trim();
            String scsiid = "";
            // Throws an exception if SR already exists and is attached
            checkIfIscsiSrExisits(conn, srNameLabel, target, targetiqn, lunid);
            // We now know the SR is not attached to the XenServer. We probe the
            // LUN to see if an SR was already exists on it, if so, we just
            // attach it or else we create a brand new SR
            deviceConfig.put("target", target);
            deviceConfig.put("targetIQN", targetiqn);
            if (StringUtils.isNoneBlank(chapInitiatorUsername, chapInitiatorPassword)) {
                deviceConfig.put("chapuser", chapInitiatorUsername);
                deviceConfig.put("chappassword", chapInitiatorPassword);
            }
            final Host host = Host.getByUuid(conn, _host.getUuid());
            final Map<String, String> smConfig = new HashMap<String, String>();
            SR sr = null;
            String pooluuid = null;
            if (SRType.LVMOISCSI.equals(srType)) {
                scsiid = probeScisiId(conn, host, deviceConfig, srType, srNameLabel, lunid, smConfig);
                deviceConfig.put("SCSIid", scsiid);
                String result = SR.probe(conn, host, deviceConfig, srType, smConfig);
                if (result.indexOf("<UUID>") != -1) {
                    pooluuid = result.substring(result.indexOf("<UUID>") + 6, result.indexOf("</UUID>")).trim();
                }
            }
            if (pooluuid == null || pooluuid.length() != 36) {
                sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, srType, "user", true, smConfig);
            } else {
                if (resignature) {
                    // We resignature the SR for managed storage if needed. At the end of this
                    // we have an SR which is ready to be attached. For VHDoISCSI SR,
                    // we don't need to resignature
                    pooluuid = resignatureIscsiSr(conn, host, deviceConfig, srNameLabel, smConfig);
                }
                sr = introduceAndPlugIscsiSr(conn, pooluuid, srNameLabel, srType, smConfig, deviceConfig, ignoreIntroduceException);
            }
            sr.scan(conn);
            return sr;
        } catch (final XenAPIException e) {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " due to  " + e.toString();
            s_logger.warn(msg, e);
            throw new CloudRuntimeException(msg, e);
        } catch (final Exception e) {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " due to  " + e.getMessage();
            s_logger.warn(msg, e);
            throw new CloudRuntimeException(msg, e);
        }
    }
}
Also used : HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) 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