Search in sources :

Example 81 with SR

use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method getLocalLVMSR.

protected SR getLocalLVMSR(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.LVM.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 LVMSR in host:" + _host.getUuid() + e.toString();
        s_logger.warn(msg);
    } catch (final XmlRpcException e) {
        final String msg = "Unable to get local LVMSR 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 82 with SR

use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method createAndAttachConfigDriveIsoForVM.

public boolean createAndAttachConfigDriveIsoForVM(final Connection conn, final VM vm, final List<String[]> vmDataList, final String configDriveLabel) throws XenAPIException, XmlRpcException {
    final String vmName = vm.getNameLabel(conn);
    // create SR
    final SR sr = createLocalIsoSR(conn, _configDriveSRName + _host.getIp());
    if (sr == null) {
        s_logger.debug("Failed to create local SR for the config drive");
        return false;
    }
    s_logger.debug("Creating vm data files in config drive for vm " + vmName);
    // 1. create vm data files
    if (!createVmdataFiles(vmName, vmDataList, configDriveLabel)) {
        s_logger.debug("Failed to create vm data files in config drive for vm " + vmName);
        return false;
    }
    // 2. copy config drive iso to host
    if (!copyConfigDriveIsoToHost(conn, sr, vmName)) {
        return false;
    }
    // 3. attachIsoToVM
    if (!attachConfigDriveIsoToVm(conn, vm)) {
        return false;
    }
    return true;
}
Also used : SR(com.xensource.xenapi.SR)

Example 83 with SR

use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method getSRByNameLabel.

protected SR getSRByNameLabel(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) {
        final Set<PBD> pbds;
        pbds = sr.getPBDs(conn);
        for (final PBD pbd : pbds) {
            final 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 84 with SR

use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method createIsoSRbyURI.

protected SR createIsoSRbyURI(final Connection conn, final URI uri, final String vmName, final boolean shared) {
    try {
        final Map<String, String> deviceConfig = new HashMap<>();
        String path = uri.getPath();
        path = path.replace("//", "/");
        deviceConfig.put("location", uri.getHost() + ":" + path);
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final SR sr = SR.create(conn, host, deviceConfig, new Long(0), uri.getHost() + path, "iso", "iso", "iso", shared, new HashMap<>());
        sr.setNameLabel(conn, vmName + "-ISO");
        sr.setNameDescription(conn, deviceConfig.get("location"));
        sr.scan(conn);
        return sr;
    } catch (final XenAPIException e) {
        final String msg = "createIsoSRbyURI failed! mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    } catch (final Exception e) {
        final String msg = "createIsoSRbyURI failed! mountpoint: " + uri.getHost() + uri.getPath() + " 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) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SR(com.xensource.xenapi.SR)

Example 85 with SR

use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method prepareManagedStorage.

protected VDI prepareManagedStorage(final Connection conn, final Map<String, String> details, final String path, final String vdiNameLabel) throws Exception {
    final SR sr = prepareManagedSr(conn, details);
    VDI vdi = getVDIbyUuid(conn, path, false);
    final Long volumeSize = Long.parseLong(details.get(DiskTO.VOLUME_SIZE));
    if (vdi == null) {
        vdi = createVdi(sr, vdiNameLabel, volumeSize);
    } else {
        // if VDI is not null, it must have already been created, so check
        // whether a resize of the volume was performed
        // if true, resize the VDI to the volume size
        s_logger.info("checking for the resize of the datadisk");
        final long vdiVirtualSize = vdi.getVirtualSize(conn);
        if (vdiVirtualSize != volumeSize) {
            s_logger.info("resizing the data disk (vdi) from vdiVirtualsize: " + vdiVirtualSize + " to volumeSize: " + volumeSize);
            try {
                vdi.resize(conn, volumeSize);
            } catch (final Exception e) {
                s_logger.warn("Unable to resize volume", e);
            }
        }
    }
    return vdi;
}
Also used : 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) 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