Search in sources :

Example 11 with PBD

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

the class CitrixResizeVolumeCommandWrapper method resizeSr.

private void resizeSr(Connection conn, ResizeVolumeCommand command) {
    // If this is managed storage, re-size the SR, too.
    // The logical unit/volume has already been re-sized, so the SR needs to fill up the new space.
    String iScsiName = command.get_iScsiName();
    try {
        Set<SR> srs = SR.getByNameLabel(conn, iScsiName);
        Set<PBD> allPbds = new HashSet<>();
        for (SR sr : srs) {
            if (!(CitrixResourceBase.SRType.LVMOISCSI.equals(sr.getType(conn)))) {
                continue;
            }
            Set<PBD> pbds = sr.getPBDs(conn);
            if (pbds.size() <= 0) {
                s_logger.debug("No PBDs found for the following SR: " + sr.getNameLabel(conn));
            }
            allPbds.addAll(pbds);
        }
        for (PBD pbd : allPbds) {
            PBD.Record pbdr = pbd.getRecord(conn);
            if (pbdr.currentlyAttached) {
                pbd.unplug(conn);
                pbd.plug(conn);
            }
        }
    } catch (Throwable ex) {
        throw new CloudRuntimeException("Unable to resize volume: " + ex.getMessage());
    }
}
Also used : PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR) HashSet(java.util.HashSet)

Example 12 with PBD

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

the class XenServerStorageProcessor method getNfsSR.

protected SR getNfsSR(final Connection conn, final StorageFilerTO pool) {
    final Map<String, String> deviceConfig = new HashMap<String, String>();
    try {
        final String server = pool.getHost();
        String serverpath = pool.getPath();
        serverpath = serverpath.replace("//", "/");
        final Set<SR> srs = SR.getAll(conn);
        for (final SR sr : srs) {
            if (!SRType.NFS.equals(sr.getType(conn))) {
                continue;
            }
            final Set<PBD> pbds = sr.getPBDs(conn);
            if (pbds.isEmpty()) {
                continue;
            }
            final PBD pbd = pbds.iterator().next();
            final Map<String, String> dc = pbd.getDeviceConfig(conn);
            if (dc == null) {
                continue;
            }
            if (dc.get("server") == null) {
                continue;
            }
            if (dc.get("serverpath") == null) {
                continue;
            }
            if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
                throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + hypervisorResource.getHost().getUuid());
            }
        }
        deviceConfig.put("server", server);
        deviceConfig.put("serverpath", serverpath);
        final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
        final Map<String, String> smConfig = new HashMap<String, String>();
        smConfig.put("nosubdir", "true");
        final SR sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), Long.toString(pool.getId()), SRType.NFS.toString(), "user", true, smConfig);
        sr.scan(conn);
        return sr;
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
    }
}
Also used : PBD(com.xensource.xenapi.PBD) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 13 with PBD

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

the class XenServerStorageProcessor method directDownloadHttpTemplate.

protected Answer directDownloadHttpTemplate(final CopyCommand cmd, final DecodedDataObject srcObj, final DecodedDataObject destObj) {
    final Connection conn = hypervisorResource.getConnection();
    SR poolsr = null;
    VDI vdi = null;
    boolean result = false;
    try {
        if (destObj.getPath() == null) {
        //need to create volume at first
        }
        vdi = VDI.getByUuid(conn, destObj.getPath());
        if (vdi == null) {
            throw new CloudRuntimeException("can't find volume: " + destObj.getPath());
        }
        final String destStoreUuid = destObj.getStore().getUuid();
        final Set<SR> srs = SR.getByNameLabel(conn, destStoreUuid);
        if (srs.size() != 1) {
            throw new CloudRuntimeException("storage uuid: " + destStoreUuid + " is not unique");
        }
        poolsr = srs.iterator().next();
        final VDI.Record vdir = vdi.getRecord(conn);
        final String vdiLocation = vdir.location;
        String pbdLocation = null;
        if (destObj.getStore().getScheme().equalsIgnoreCase(DataStoreProtocol.NFS.toString())) {
            pbdLocation = "/run/sr-mount/" + poolsr.getUuid(conn);
        } else {
            final Set<PBD> pbds = poolsr.getPBDs(conn);
            if (pbds.size() != 1) {
                throw new CloudRuntimeException("Don't how to handle multiple pbds:" + pbds.size() + " for sr: " + poolsr.getUuid(conn));
            }
            final PBD pbd = pbds.iterator().next();
            final Map<String, String> deviceCfg = pbd.getDeviceConfig(conn);
            pbdLocation = deviceCfg.get("location");
        }
        if (pbdLocation == null) {
            throw new CloudRuntimeException("Can't get pbd location");
        }
        final String vdiPath = pbdLocation + "/" + vdiLocation + ".vhd";
        //download a url into vdipath
        //downloadHttpToLocalFile(vdiPath, template.getPath());
        hypervisorResource.callHostPlugin(conn, "storagePlugin", "downloadTemplateFromUrl", "destPath", vdiPath, "srcUrl", srcObj.getPath());
        result = true;
    //return new CopyCmdAnswer(cmd, vdi.getUuid(conn));
    } catch (final BadServerResponse e) {
        s_logger.debug("Failed to download template", e);
    } catch (final XenAPIException e) {
        s_logger.debug("Failed to download template", e);
    } catch (final XmlRpcException e) {
        s_logger.debug("Failed to download template", e);
    } catch (final Exception e) {
        s_logger.debug("Failed to download template", e);
    } finally {
        if (!result && vdi != null) {
            try {
                vdi.destroy(conn);
            } catch (final BadServerResponse e) {
                s_logger.debug("Failed to cleanup newly created vdi");
            } catch (final XenAPIException e) {
                s_logger.debug("Failed to cleanup newly created vdi");
            } catch (final XmlRpcException e) {
                s_logger.debug("Failed to cleanup newly created vdi");
            }
        }
    }
    return new Answer(cmd, false, "Failed to download template");
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) 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) PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 14 with PBD

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

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 15 with PBD

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

the class CitrixResourceBase method introduceAndPlugIscsiSr.

private SR introduceAndPlugIscsiSr(Connection conn, String pooluuid, String srNameLabel, String type, Map<String, String> smConfig, Map<String, String> deviceConfig, boolean ignoreIntroduceException) throws XmlRpcException, XenAPIException {
    SR sr = null;
    try {
        sr = SR.introduce(conn, pooluuid, srNameLabel, srNameLabel, type, "user", true, smConfig);
    } catch (final XenAPIException ex) {
        if (ignoreIntroduceException) {
            return sr;
        }
        throw ex;
    }
    final Set<Host> setHosts = Host.getAll(conn);
    if (setHosts == null) {
        final String msg = "Unable to create iSCSI SR " + deviceConfig + " due to hosts not available.";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    for (final Host currentHost : setHosts) {
        final PBD.Record rec = new PBD.Record();
        rec.deviceConfig = deviceConfig;
        rec.host = currentHost;
        rec.SR = sr;
        final PBD pbd = PBD.create(conn, rec);
        pbd.plug(conn);
    }
    return sr;
}
Also used : PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) SR(com.xensource.xenapi.SR)

Aggregations

PBD (com.xensource.xenapi.PBD)16 SR (com.xensource.xenapi.SR)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 Host (com.xensource.xenapi.Host)10 XenAPIException (com.xensource.xenapi.Types.XenAPIException)10 XmlRpcException (org.apache.xmlrpc.XmlRpcException)9 HashMap (java.util.HashMap)5 InternalErrorException (com.cloud.exception.InternalErrorException)4 VDI (com.xensource.xenapi.VDI)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Map (java.util.Map)2 TimeoutException (java.util.concurrent.TimeoutException)2 ConfigurationException (javax.naming.ConfigurationException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 Answer (com.cloud.agent.api.Answer)1 Connection (com.xensource.xenapi.Connection)1 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)1