Search in sources :

Example 1 with VolumeType

use of com.cloud.model.enumeration.VolumeType in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method createVbd.

public VBD createVbd(final Connection conn, final DiskTO volume, final String vmName, final VM vm, final BootloaderType bootLoaderType, VDI vdi) throws XmlRpcException, XenAPIException {
    final VolumeType type = volume.getType();
    if (vdi == null) {
        vdi = mount(conn, vmName, volume);
    }
    if (vdi != null) {
        if ("detached".equals(vdi.getNameLabel(conn))) {
            vdi.setNameLabel(conn, vmName + "-DATA");
        }
        final Map<String, String> smConfig = vdi.getSmConfig(conn);
        for (final String key : smConfig.keySet()) {
            if (key.startsWith("host_")) {
                vdi.removeFromSmConfig(conn, key);
                break;
            }
        }
    }
    final VBD.Record vbdr = new VBD.Record();
    vbdr.VM = vm;
    if (vdi != null) {
        vbdr.VDI = vdi;
    } else {
        vbdr.empty = true;
    }
    if (type == VolumeType.ROOT && bootLoaderType == BootloaderType.PyGrub) {
        vbdr.bootable = true;
    } else if (type == VolumeType.ISO && bootLoaderType == BootloaderType.CD) {
        vbdr.bootable = true;
    }
    if (volume.getType() == VolumeType.ISO) {
        vbdr.mode = Types.VbdMode.RO;
        vbdr.type = Types.VbdType.CD;
        vbdr.userdevice = "3";
    } else {
        vbdr.mode = Types.VbdMode.RW;
        vbdr.type = Types.VbdType.DISK;
        vbdr.unpluggable = volume.getType() == VolumeType.ROOT ? false : true;
        vbdr.userdevice = "autodetect";
        final Long deviceId = volume.getDiskSeq();
        if (deviceId != null && !isDeviceUsed(conn, vm, deviceId) || deviceId > 3) {
            vbdr.userdevice = deviceId.toString();
        }
    }
    final VBD vbd = VBD.create(conn, vbdr);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("VBD " + vbd.getUuid(conn) + " created for " + volume);
    }
    return vbd;
}
Also used : VolumeType(com.cloud.model.enumeration.VolumeType) VBD(com.xensource.xenapi.VBD)

Example 2 with VolumeType

use of com.cloud.model.enumeration.VolumeType in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method mount.

protected VDI mount(final Connection conn, final String vmName, final DiskTO volume) throws XmlRpcException, XenAPIException {
    final DataTO data = volume.getData();
    final VolumeType type = volume.getType();
    if (type == VolumeType.ISO) {
        final TemplateObjectTO iso = (TemplateObjectTO) data;
        final DataStoreTO store = iso.getDataStore();
        if (store == null) {
            // It's a fake iso
            return null;
        }
        // corer case, xenserver pv driver iso
        final String templateName = iso.getName();
        if (templateName.startsWith("xs-tools")) {
            try {
                final Set<VDI> vdis = VDI.getByNameLabel(conn, templateName);
                if (vdis.isEmpty()) {
                    throw new CloudRuntimeException("Could not find ISO with URL: " + templateName);
                }
                return vdis.iterator().next();
            } catch (final XenAPIException e) {
                throw new CloudRuntimeException("Unable to get pv iso: " + templateName + " due to " + e.toString());
            } catch (final Exception e) {
                throw new CloudRuntimeException("Unable to get pv iso: " + templateName + " due to " + e.toString());
            }
        }
        if (!(store instanceof NfsTO)) {
            throw new CloudRuntimeException("only support mount iso on nfs");
        }
        final NfsTO nfsStore = (NfsTO) store;
        final String isoPath = nfsStore.getUrl() + File.separator + iso.getPath();
        final int index = isoPath.lastIndexOf("/");
        final String mountpoint = isoPath.substring(0, index);
        final URI uri;
        try {
            uri = new URI(mountpoint);
        } catch (final URISyntaxException e) {
            throw new CloudRuntimeException("Incorrect uri " + mountpoint, e);
        }
        final SR isoSr = createIsoSRbyURI(conn, uri, vmName, false);
        final String isoname = isoPath.substring(index + 1);
        final VDI isoVdi = getVDIbyLocationandSR(conn, isoname, isoSr);
        if (isoVdi == null) {
            throw new CloudRuntimeException("Unable to find ISO " + isoPath);
        }
        return isoVdi;
    } else {
        final VolumeObjectTO vol = (VolumeObjectTO) data;
        return VDI.getByUuid(conn, vol.getPath());
    }
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) XenAPIException(com.xensource.xenapi.Types.XenAPIException) URISyntaxException(java.net.URISyntaxException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) 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) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DataTO(com.cloud.legacymodel.to.DataTO) VolumeType(com.cloud.model.enumeration.VolumeType) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(com.cloud.legacymodel.to.TemplateObjectTO) SR(com.xensource.xenapi.SR)

Aggregations

VolumeType (com.cloud.model.enumeration.VolumeType)2 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)1 DataTO (com.cloud.legacymodel.to.DataTO)1 NfsTO (com.cloud.legacymodel.to.NfsTO)1 TemplateObjectTO (com.cloud.legacymodel.to.TemplateObjectTO)1 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)1 SR (com.xensource.xenapi.SR)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VBD (com.xensource.xenapi.VBD)1 VDI (com.xensource.xenapi.VDI)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ConfigurationException (javax.naming.ConfigurationException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 SAXException (org.xml.sax.SAXException)1