Search in sources :

Example 71 with Connection

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

the class CitrixOvsCreateTunnelCommandWrapper method execute.

@Override
public Answer execute(final OvsCreateTunnelCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    String bridge = "unknown";
    try {
        final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getNetworkName());
        if (nw == null) {
            s_logger.debug("Error during bridge setup");
            return new OvsCreateTunnelAnswer(command, false, "Cannot create network", bridge);
        }
        citrixResourceBase.configureTunnelNetwork(conn, command.getNetworkId(), command.getFrom(), command.getNetworkName());
        bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", command.getRemoteIp(), "key", command.getKey().toString(), "from", command.getFrom().toString(), "to", command.getTo().toString(), "cloudstack-network-id", command.getNetworkUuid());
        final String[] res = result.split(":");
        if (res.length == 2 && res[0].equalsIgnoreCase("SUCCESS")) {
            return new OvsCreateTunnelAnswer(command, true, result, res[1], bridge);
        } else {
            return new OvsCreateTunnelAnswer(command, false, result, bridge);
        }
    } catch (final Exception e) {
        s_logger.debug("Error during tunnel setup");
        s_logger.warn("Caught execption when creating ovs tunnel", e);
        return new OvsCreateTunnelAnswer(command, false, e.getMessage(), bridge);
    }
}
Also used : Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer)

Example 72 with Connection

use of com.xensource.xenapi.Connection 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 73 with Connection

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

the class CitrixOvsDestroyBridgeCommandWrapper method execute.

@Override
public Answer execute(final OvsDestroyBridgeCommand command, final CitrixResourceBase citrixResourceBase) {
    try {
        final Connection conn = citrixResourceBase.getConnection();
        final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName());
        citrixResourceBase.cleanUpTmpDomVif(conn, nw);
        citrixResourceBase.destroyTunnelNetwork(conn, nw, command.getHostId());
        s_logger.debug("OVS Bridge destroyed");
        return new Answer(command, true, null);
    } catch (final Exception e) {
        s_logger.warn("caught execption when destroying ovs bridge", e);
        return new Answer(command, false, e.getMessage());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection)

Example 74 with Connection

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

Example 75 with Connection

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

the class XenServer620SP1GetGPUStatsCommandWrapper method execute.

@Override
public Answer execute(final GetGPUStatsCommand command, final XenServer620SP1Resource xenServer620SP1Resource) {
    final Connection conn = xenServer620SP1Resource.getConnection();
    HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
    try {
        groupDetails = xenServer620SP1Resource.getGPUGroupDetails(conn);
    } catch (final Exception e) {
        final String msg = "Unable to get GPU stats" + e.toString();
        s_logger.warn(msg, e);
        return new GetGPUStatsAnswer(command, false, msg);
    }
    return new GetGPUStatsAnswer(command, groupDetails);
}
Also used : GetGPUStatsAnswer(com.cloud.agent.api.GetGPUStatsAnswer) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VgpuTypesInfo(com.cloud.agent.api.VgpuTypesInfo)

Aggregations

Connection (com.xensource.xenapi.Connection)165 XenAPIException (com.xensource.xenapi.Types.XenAPIException)88 XmlRpcException (org.apache.xmlrpc.XmlRpcException)86 Answer (com.cloud.agent.api.Answer)79 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)58 Test (org.junit.Test)53 VDI (com.xensource.xenapi.VDI)47 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)46 SR (com.xensource.xenapi.SR)42 InternalErrorException (com.cloud.exception.InternalErrorException)39 RebootAnswer (com.cloud.agent.api.RebootAnswer)38 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)38 Network (com.xensource.xenapi.Network)35 VM (com.xensource.xenapi.VM)32 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)23 HashMap (java.util.HashMap)23 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)23 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)20 Host (com.xensource.xenapi.Host)19 URI (java.net.URI)19