Search in sources :

Example 6 with PBD

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

the class CitrixResourceBase method removeSR.

public void removeSR(final Connection conn, final SR sr) {
    if (sr == null) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(logX(sr, "Removing SR"));
    }
    for (int i = 0; i < 2; i++) {
        try {
            final Set<VDI> vdis = sr.getVDIs(conn);
            for (final VDI vdi : vdis) {
                vdi.forget(conn);
            }
            Set<PBD> pbds = sr.getPBDs(conn);
            for (final PBD pbd : pbds) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(logX(pbd, "Unplugging pbd"));
                }
                // if (pbd.getCurrentlyAttached(conn)) {
                pbd.unplug(conn);
                // }
                pbd.destroy(conn);
            }
            pbds = sr.getPBDs(conn);
            if (pbds.size() == 0) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(logX(sr, "Forgetting"));
                }
                sr.forget(conn);
                return;
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(logX(sr, "There is still one or more PBDs attached."));
                if (s_logger.isTraceEnabled()) {
                    for (final PBD pbd : pbds) {
                        s_logger.trace(logX(pbd, " Still attached"));
                    }
                }
            }
        } catch (final XenAPIException e) {
            s_logger.debug(logX(sr, "Catch XenAPIException: " + e.toString()));
        } catch (final XmlRpcException e) {
            s_logger.debug(logX(sr, "Catch Exception: " + e.getMessage()));
        }
    }
    s_logger.warn(logX(sr, "Unable to remove SR"));
}
Also used : PBD(com.xensource.xenapi.PBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 7 with PBD

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

the class CitrixResourceBase method getNfsSR.

public SR getNfsSR(final Connection conn, final String poolid, final String uuid, final String server, String serverpath, final String pooldesc) {
    final Map<String, String> deviceConfig = new HashMap<String, String>();
    try {
        serverpath = serverpath.replace("//", "/");
        final Set<SR> srs = SR.getAll(conn);
        if (srs != null && !srs.isEmpty()) {
            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 " + uuid + " on host:" + _host.getUuid());
                }
            }
        }
        deviceConfig.put("server", server);
        deviceConfig.put("serverpath", serverpath);
        final Host host = Host.getByUuid(conn, _host.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), uuid, poolid, SRType.NFS.toString(), "user", true, smConfig);
        sr.scan(conn);
        return sr;
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pooldesc, e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pooldesc, 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 8 with PBD

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

the class CitrixResourceBase method checkIfIscsiSrExisits.

private void checkIfIscsiSrExisits(Connection conn, String srNameLabel, String target, String targetiqn, String lunid) throws XenAPIException, XmlRpcException {
    final Set<SR> srs = SR.getByNameLabel(conn, srNameLabel);
    for (final SR sr : srs) {
        if (!(SRType.LVMOISCSI.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("target") == null) {
            continue;
        }
        if (dc.get("targetIQN") == null) {
            continue;
        }
        if (dc.get("lunid") == null) {
            continue;
        }
        if (target.equals(dc.get("target")) && targetiqn.equals(dc.get("targetIQN")) && lunid.equals(dc.get("lunid"))) {
            throw new CloudRuntimeException("There is a SR using the same configuration target:" + dc.get("target") + ",  targetIQN:" + dc.get("targetIQN") + ", lunid:" + dc.get("lunid") + " for pool " + srNameLabel + "on host:" + _host.getUuid());
        }
    }
}
Also used : PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 9 with PBD

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

the class CitrixResourceBase method checkSR.

protected boolean checkSR(final Connection conn, final SR sr) {
    try {
        final SR.Record srr = sr.getRecord(conn);
        final Set<PBD> pbds = sr.getPBDs(conn);
        if (pbds.size() == 0) {
            final String msg = "There is no PBDs for this SR: " + srr.nameLabel + " on host:" + _host.getUuid();
            s_logger.warn(msg);
            return false;
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Checking " + srr.nameLabel + " or SR " + srr.uuid + " on " + _host);
        }
        if (srr.shared) {
            if (SRType.NFS.equals(srr.type)) {
                final Map<String, String> smConfig = srr.smConfig;
                if (!smConfig.containsKey("nosubdir")) {
                    smConfig.put("nosubdir", "true");
                    sr.setSmConfig(conn, smConfig);
                }
            }
            final Host host = Host.getByUuid(conn, _host.getUuid());
            boolean found = false;
            for (final PBD pbd : pbds) {
                final PBD.Record pbdr = pbd.getRecord(conn);
                if (host.equals(pbdr.host)) {
                    if (!pbdr.currentlyAttached) {
                        pbdPlug(conn, pbd, pbdr.uuid);
                    }
                    found = true;
                    break;
                }
            }
            if (!found) {
                final PBD.Record pbdr = srr.PBDs.iterator().next().getRecord(conn);
                pbdr.host = host;
                pbdr.uuid = "";
                final PBD pbd = PBD.create(conn, pbdr);
                pbdPlug(conn, pbd, pbd.getUuid(conn));
            }
        } else {
            for (final PBD pbd : pbds) {
                final PBD.Record pbdr = pbd.getRecord(conn);
                if (!pbdr.currentlyAttached) {
                    pbdPlug(conn, pbd, pbdr.uuid);
                }
            }
        }
    } catch (final Exception e) {
        final String msg = "checkSR failed host:" + _host + " due to " + e.toString();
        s_logger.warn(msg, e);
        return false;
    }
    return true;
}
Also used : PBD(com.xensource.xenapi.PBD) 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)

Example 10 with PBD

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

the class CitrixResourceBase method prepareISO.

public void prepareISO(final Connection conn, final String vmName, List<String[]> vmDataList, String configDriveLabel) throws XmlRpcException, XenAPIException {
    final Set<VM> vms = VM.getByNameLabel(conn, vmName);
    if (vms == null || vms.size() != 1) {
        throw new CloudRuntimeException("There are " + (vms == null ? "0" : vms.size()) + " VMs named " + vmName);
    }
    final VM vm = vms.iterator().next();
    if (vmDataList != null) {
        // create SR
        SR sr = createLocalIsoSR(conn, _configDriveSRName + getHost().getIp());
        // 1. create vm data files
        createVmdataFiles(vmName, vmDataList, configDriveLabel);
        // 2. copy config drive iso to host
        copyConfigDriveIsoToHost(conn, sr, vmName);
    }
    final Set<VBD> vbds = vm.getVBDs(conn);
    for (final VBD vbd : vbds) {
        final VBD.Record vbdr = vbd.getRecord(conn);
        if (vbdr.type == Types.VbdType.CD && vbdr.empty == false && vbdr.userdevice.equals(_attachIsoDeviceNum)) {
            final VDI vdi = vbdr.VDI;
            final SR sr = vdi.getSR(conn);
            final Set<PBD> pbds = sr.getPBDs(conn);
            if (pbds == null) {
                throw new CloudRuntimeException("There is no pbd for sr " + sr);
            }
            for (final PBD pbd : pbds) {
                final PBD.Record pbdr = pbd.getRecord(conn);
                if (pbdr.host.getUuid(conn).equals(_host.getUuid())) {
                    return;
                }
            }
            sr.setShared(conn, true);
            final Host host = Host.getByUuid(conn, _host.getUuid());
            final PBD.Record pbdr = pbds.iterator().next().getRecord(conn);
            pbdr.host = host;
            pbdr.uuid = "";
            final PBD pbd = PBD.create(conn, pbdr);
            pbdPlug(conn, pbd, pbd.getUuid(conn));
            break;
        }
    }
}
Also used : PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) VDI(com.xensource.xenapi.VDI) 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