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);
}
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);
}
}
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());
}
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());
}
}
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());
}
}
Aggregations