Search in sources :

Example 16 with Network

use of com.xensource.xenapi.Network 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 17 with Network

use of com.xensource.xenapi.Network 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 18 with Network

use of com.xensource.xenapi.Network 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 19 with Network

use of com.xensource.xenapi.Network 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 20 with Network

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

the class CitrixOvsVpcRoutingPolicyConfigCommandWrapper method execute.

@Override
public Answer execute(final OvsVpcRoutingPolicyConfigCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName());
        final String bridgeName = nw.getBridge(conn);
        final long sequenceNo = command.getSequenceNumber();
        final String result = citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_routing_policies", "bridge", bridgeName, "host-id", ((Long) command.getHostId()).toString(), "config", command.getVpcConfigInJson(), "seq-no", Long.toString(sequenceNo));
        if (result.startsWith("SUCCESS")) {
            return new Answer(command, true, result);
        } else {
            return new Answer(command, false, result);
        }
    } catch (final Exception e) {
        s_logger.warn("caught exception while updating host with latest routing policies", 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)

Aggregations

Network (com.xensource.xenapi.Network)46 Connection (com.xensource.xenapi.Connection)35 XenAPIException (com.xensource.xenapi.Types.XenAPIException)32 XmlRpcException (org.apache.xmlrpc.XmlRpcException)30 Answer (com.cloud.agent.api.Answer)24 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Test (org.junit.Test)19 RebootAnswer (com.cloud.agent.api.RebootAnswer)16 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)16 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)16 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 NicTO (com.cloud.agent.api.to.NicTO)10 VIF (com.xensource.xenapi.VIF)10 VM (com.xensource.xenapi.VM)8 HashMap (java.util.HashMap)8 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)7 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)6 Host (com.xensource.xenapi.Host)6 PIF (com.xensource.xenapi.PIF)6