Search in sources :

Example 71 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method getLowestAvailableVIFDeviceNum.

public String getLowestAvailableVIFDeviceNum(final Connection conn, final VM vm) {
    String vmName = "";
    try {
        vmName = vm.getNameLabel(conn);
        final List<Integer> usedDeviceNums = new ArrayList<Integer>();
        final Set<VIF> vifs = vm.getVIFs(conn);
        final Iterator<VIF> vifIter = vifs.iterator();
        while (vifIter.hasNext()) {
            final VIF vif = vifIter.next();
            try {
                final String deviceId = vif.getDevice(conn);
                if (vm.getIsControlDomain(conn) || vif.getCurrentlyAttached(conn)) {
                    usedDeviceNums.add(Integer.valueOf(deviceId));
                } else {
                    s_logger.debug("Found unplugged VIF " + deviceId + " in VM " + vmName + " destroy it");
                    vif.destroy(conn);
                }
            } catch (final NumberFormatException e) {
                final String msg = "Obtained an invalid value for an allocated VIF device number for VM: " + vmName;
                s_logger.debug(msg, e);
                throw new CloudRuntimeException(msg);
            }
        }
        for (Integer i = 0; i < _maxNics; i++) {
            if (!usedDeviceNums.contains(i)) {
                s_logger.debug("Lowest available Vif device number: " + i + " for VM: " + vmName);
                return i.toString();
            }
        }
    } catch (final XmlRpcException e) {
        final String msg = "Caught XmlRpcException: " + e.getMessage();
        s_logger.warn(msg, e);
    } catch (final XenAPIException e) {
        final String msg = "Caught XenAPIException: " + e.toString();
        s_logger.warn(msg, e);
    }
    throw new CloudRuntimeException("Could not find available VIF slot in VM with name: " + vmName);
}
Also used : VIF(com.xensource.xenapi.VIF) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 72 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException 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)

Example 73 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class XenServerConnectionPool method loginWithPassword.

protected Session loginWithPassword(Connection conn, String username, Queue<String> password, String version) throws BadServerResponse, XenAPIException, XmlRpcException {
    Session s = null;
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
            }
        }
    }
    return s;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

Example 74 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class XenServerConnectionPool method slaveLocalLoginWithPassword.

protected Session slaveLocalLoginWithPassword(Connection conn, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
    Session s = null;
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
                break;
            }
        }
    }
    return s;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

Example 75 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method callHostPluginThroughMaster.

protected String callHostPluginThroughMaster(final Connection conn, final String plugin, final String cmd, final String... params) {
    final Map<String, String> args = new HashMap<String, String>();
    try {
        final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
        if (poolRecs.size() != 1) {
            throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + _host.getUuid());
        }
        final Host master = poolRecs.values().iterator().next().master;
        for (int i = 0; i < params.length; i += 2) {
            args.put(params[i], params[i + 1]);
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
        }
        final String result = master.callPlugin(conn, plugin, cmd, args);
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin Result: " + result);
        }
        return result.replace("\n", "");
    } catch (final Types.HandleInvalid e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle);
    } catch (final XenAPIException e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e);
    } catch (final XmlRpcException e) {
        s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e);
    }
    return null;
}
Also used : Types(com.xensource.xenapi.Types) HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Pool(com.xensource.xenapi.Pool) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

XenAPIException (com.xensource.xenapi.Types.XenAPIException)101 XmlRpcException (org.apache.xmlrpc.XmlRpcException)93 Connection (com.xensource.xenapi.Connection)56 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)53 Answer (com.cloud.agent.api.Answer)33 InternalErrorException (com.cloud.exception.InternalErrorException)31 SR (com.xensource.xenapi.SR)30 Host (com.xensource.xenapi.Host)29 Network (com.xensource.xenapi.Network)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 VDI (com.xensource.xenapi.VDI)25 IOException (java.io.IOException)25 HashMap (java.util.HashMap)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)25 Test (org.junit.Test)25 ConfigurationException (javax.naming.ConfigurationException)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 MalformedURLException (java.net.MalformedURLException)21 URISyntaxException (java.net.URISyntaxException)21 TimeoutException (java.util.concurrent.TimeoutException)21