Search in sources :

Example 1 with OvsCreateTunnelAnswer

use of com.cloud.agent.api.OvsCreateTunnelAnswer 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 2 with OvsCreateTunnelAnswer

use of com.cloud.agent.api.OvsCreateTunnelAnswer in project cloudstack by apache.

the class LibvirtOvsCreateTunnelCommandWrapper method execute.

@Override
public Answer execute(final OvsCreateTunnelCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String bridge = command.getNetworkName();
    try {
        if (!libvirtComputingResource.findOrCreateTunnelNetwork(bridge)) {
            s_logger.debug("Error during bridge setup");
            return new OvsCreateTunnelAnswer(command, false, "Cannot create network", bridge);
        }
        libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName());
        final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger);
        scriptCommand.add("create_tunnel");
        scriptCommand.add("--bridge", bridge);
        scriptCommand.add("--remote_ip", command.getRemoteIp());
        scriptCommand.add("--key", command.getKey().toString());
        scriptCommand.add("--src_host", command.getFrom().toString());
        scriptCommand.add("--dst_host", command.getTo().toString());
        final String result = scriptCommand.execute();
        if (result != null) {
            return new OvsCreateTunnelAnswer(command, true, result, null, bridge);
        } else {
            return new OvsCreateTunnelAnswer(command, false, result, bridge);
        }
    } catch (final Exception e) {
        s_logger.warn("Caught execption when creating ovs tunnel", e);
        return new OvsCreateTunnelAnswer(command, false, e.getMessage(), bridge);
    }
}
Also used : Script(com.cloud.utils.script.Script) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer)

Example 3 with OvsCreateTunnelAnswer

use of com.cloud.agent.api.OvsCreateTunnelAnswer in project cloudstack by apache.

the class OvsTunnelManagerImpl method handleCreateTunnelAnswer.

private void handleCreateTunnelAnswer(Answer[] answers) {
    OvsCreateTunnelAnswer r = (OvsCreateTunnelAnswer) answers[0];
    String s = String.format("(hostIP:%1$s, remoteIP:%2$s, bridge:%3$s," + "greKey:%4$s, portName:%5$s)", r.getFromIp(), r.getToIp(), r.getBridge(), r.getKey(), r.getInPortName());
    Long from = r.getFrom();
    Long to = r.getTo();
    long networkId = r.getNetworkId();
    OvsTunnelNetworkVO tunnel = _tunnelNetworkDao.getByFromToNetwork(from, to, networkId);
    if (tunnel == null) {
        throw new CloudRuntimeException(String.format("Unable find tunnelNetwork record" + "(from=%1$s,to=%2$s, account=%3$s", from, to, networkId));
    }
    if (!r.getResult()) {
        tunnel.setState(OvsTunnel.State.Failed.name());
        s_logger.warn("Create GRE tunnel from " + from + " to " + to + " failed due to " + r.getDetails() + s);
    } else {
        tunnel.setState(OvsTunnel.State.Established.name());
        tunnel.setPortName(r.getInPortName());
        s_logger.info("Create GRE tunnel from " + from + " to " + to + " succeeded." + r.getDetails() + s);
    }
    _tunnelNetworkDao.update(tunnel.getId(), tunnel);
}
Also used : OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer)

Aggregations

OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)3 OvsTunnelNetworkVO (com.cloud.network.ovs.dao.OvsTunnelNetworkVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 Script (com.cloud.utils.script.Script)1 Connection (com.xensource.xenapi.Connection)1 Network (com.xensource.xenapi.Network)1