Search in sources :

Example 41 with XenAPIException

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

the class CitrixModifyStoragePoolCommandWrapper method execute.

@Override
public Answer execute(final ModifyStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final StorageFilerTO pool = command.getPool();
    final boolean add = command.getAdd();
    if (add) {
        try {
            final String srName = command.getStoragePath() != null ? command.getStoragePath() : pool.getUuid();
            final SR sr = citrixResourceBase.getStorageRepository(conn, srName);
            citrixResourceBase.setupHeartbeatSr(conn, sr, false);
            final long capacity = sr.getPhysicalSize(conn);
            final long available = capacity - sr.getPhysicalUtilisation(conn);
            if (capacity == -1) {
                final String msg = "Pool capacity is -1! pool: " + pool.getHost() + pool.getPath();
                s_logger.warn(msg);
                return new Answer(command, false, msg);
            }
            final Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
            final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, capacity, available, tInfo);
            return answer;
        } catch (final XenAPIException e) {
            final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        } catch (final Exception e) {
            final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        }
    } else {
        try {
            final SR sr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
            final String srUuid = sr.getUuid(conn);
            final String result = citrixResourceBase.callHostPluginPremium(conn, "setup_heartbeat_file", "host", citrixResourceBase.getHost().getUuid(), "sr", srUuid, "add", "false");
            if (result == null || !result.split("#")[1].equals("0")) {
                throw new CloudRuntimeException("Unable to remove heartbeat file entry for SR " + srUuid + " due to " + result);
            }
            return new Answer(command, true, "success");
        } catch (final XenAPIException e) {
            final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        } catch (final Exception e) {
            final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        }
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Example 42 with XenAPIException

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

the class CitrixOvsCreateGreTunnelCommandWrapper method execute.

@Override
public Answer execute(final OvsCreateGreTunnelCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    String bridge = "unkonwn";
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_create_gre", "bridge", bridge, "remoteIP", command.getRemoteIp(), "greKey", command.getKey(), "from", Long.toString(command.getFrom()), "to", Long.toString(command.getTo()));
        final String[] res = result.split(":");
        if (res.length != 2 || res.length == 2 && res[1].equalsIgnoreCase("[]")) {
            return new OvsCreateGreTunnelAnswer(command, false, result, citrixResourceBase.getHost().getIp(), bridge);
        } else {
            return new OvsCreateGreTunnelAnswer(command, true, result, citrixResourceBase.getHost().getIp(), bridge, Integer.parseInt(res[1]));
        }
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    }
    return new OvsCreateGreTunnelAnswer(command, false, "EXCEPTION", citrixResourceBase.getHost().getIp(), bridge);
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsCreateGreTunnelAnswer(com.cloud.agent.api.OvsCreateGreTunnelAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 43 with XenAPIException

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

the class CitrixCheckNetworkCommandWrapper method execute.

@Override
public Answer execute(final CheckNetworkCommand command, final CitrixResourceBase citrixResourceBase) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking if network name setup is done on the resource");
    }
    final List<PhysicalNetworkSetupInfo> infoList = command.getPhysicalNetworkInfoList();
    try {
        boolean errorout = false;
        String msg = "";
        for (final PhysicalNetworkSetupInfo info : infoList) {
            if (!citrixResourceBase.isNetworkSetupByName(info.getGuestNetworkName())) {
                msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Guest Network is not configured on the backend by name " + info.getGuestNetworkName();
                errorout = true;
                break;
            }
            if (!citrixResourceBase.isNetworkSetupByName(info.getPrivateNetworkName())) {
                msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Private Network is not configured on the backend by name " + info.getPrivateNetworkName();
                errorout = true;
                break;
            }
            if (!citrixResourceBase.isNetworkSetupByName(info.getPublicNetworkName())) {
                msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Public Network is not configured on the backend by name " + info.getPublicNetworkName();
                errorout = true;
                break;
            }
        /*if(!isNetworkSetupByName(info.getStorageNetworkName())){
                    msg = "For Physical Network id:"+ info.getPhysicalNetworkId() + ", Storage Network is not configured on the backend by name " + info.getStorageNetworkName();
                    errorout = true;
                    break;
                }*/
        }
        if (errorout) {
            s_logger.error(msg);
            return new CheckNetworkAnswer(command, false, msg);
        } else {
            return new CheckNetworkAnswer(command, true, "Network Setup check by names is done");
        }
    } catch (final XenAPIException e) {
        final String msg = "CheckNetworkCommand failed with XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid();
        s_logger.warn(msg, e);
        return new CheckNetworkAnswer(command, false, msg);
    } catch (final Exception e) {
        final String msg = "CheckNetworkCommand failed with Exception:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid();
        s_logger.warn(msg, e);
        return new CheckNetworkAnswer(command, false, msg);
    }
}
Also used : CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Example 44 with XenAPIException

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

the class CitrixOvsDeleteFlowCommandWrapper method execute.

@Override
public Answer execute(final OvsDeleteFlowCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        final String bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_delete_flow", "bridge", bridge, "vmName", command.getVmName());
        if (result.equalsIgnoreCase("SUCCESS")) {
            return new Answer(command, true, "success to delete flows for " + command.getVmName());
        } else {
            return new Answer(command, false, result);
        }
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to delete flow", e);
    } catch (final XenAPIException e) {
        s_logger.error("Failed to delete flow", e);
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to delete flow", e);
    }
    return new Answer(command, false, "failed to delete flow for " + command.getVmName());
}
Also used : Answer(com.cloud.agent.api.Answer) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 45 with XenAPIException

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

the class CitrixOvsFetchInterfaceCommandWrapper method execute.

@Override
public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResourceBase citrixResourceBase) {
    String label = command.getLabel();
    //FIXME: this is a tricky to pass the network checking in XCP. I temporary get default label from Host.
    if (citrixResourceBase.isXcp()) {
        label = citrixResourceBase.getLabel();
    }
    s_logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp());
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final XsLocalNetwork nw = citrixResourceBase.getNetworkByName(conn, label);
        if (nw == null) {
            throw new CloudRuntimeException("Unable to locate the network with name-label: " + label + " on host: " + citrixResourceBase.getHost().getIp());
        }
        s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn));
        final PIF pif = nw.getPif(conn);
        final PIF.Record pifRec = pif.getRecord(conn);
        s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")");
        return new OvsFetchInterfaceAnswer(command, true, "Interface " + pifRec.device + " retrieved successfully", pifRec.IP, pifRec.netmask, pifRec.MAC);
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    }
}
Also used : XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) PIF(com.xensource.xenapi.PIF) 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