use of com.xensource.xenapi.Network in project cloudstack by apache.
the class CitrixOvsSetTagAndFlowCommandWrapper method execute.
@Override
public Answer execute(final OvsSetTagAndFlowCommand 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);
/*
* If VM is domainRouter, this will try to set flow and tag on its
* none guest network nic. don't worry, it will fail silently at
* host plugin side
*/
final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_set_tag_and_flow", "bridge", bridge, "vmName", command.getVmName(), "tag", command.getTag(), "vlans", command.getVlans(), "seqno", command.getSeqNo());
s_logger.debug("set flow for " + command.getVmName() + " " + result);
if (result != null && result.equalsIgnoreCase("SUCCESS")) {
return new OvsSetTagAndFlowAnswer(command, true, result);
} else {
return new OvsSetTagAndFlowAnswer(command, false, result);
}
} catch (final BadServerResponse e) {
s_logger.error("Failed to set tag and flow", e);
} catch (final XenAPIException e) {
s_logger.error("Failed to set tag and flow", e);
} catch (final XmlRpcException e) {
s_logger.error("Failed to set tag and flow", e);
}
return new OvsSetTagAndFlowAnswer(command, false, "EXCEPTION");
}
use of com.xensource.xenapi.Network in project cloudstack by apache.
the class CitrixOvsVpcPhysicalTopologyConfigCommandWrapper method execute.
@Override
public Answer execute(final OvsVpcPhysicalTopologyConfigCommand 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_network_topology", "bridge", bridgeName, "config", command.getVpcConfigInJson(), "host-id", ((Long) command.getHostId()).toString(), "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 VPC topology", e);
return new Answer(command, false, e.getMessage());
}
}
use of com.xensource.xenapi.Network in project cloudstack by apache.
the class CitrixOvsDestroyTunnelCommandWrapper method execute.
@Override
public Answer execute(final OvsDestroyTunnelCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName());
if (nw == null) {
s_logger.warn("Unable to find tunnel network for GRE key:" + command.getBridgeName());
return new Answer(command, false, "No network found");
}
final String bridge = nw.getBridge(conn);
final String result = citrixResourceBase.callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", command.getInPortName());
if (result.equalsIgnoreCase("SUCCESS")) {
return new Answer(command, true, result);
} else {
return new Answer(command, false, result);
}
} catch (final Exception e) {
s_logger.warn("caught execption when destroy ovs tunnel", e);
return new Answer(command, false, e.getMessage());
}
}
use of com.xensource.xenapi.Network in project cloudstack by apache.
the class CitrixResourceBase method configureTunnelNetwork.
/**
* This method creates a XenServer network and configures it for being used
* as a L2-in-L3 tunneled network
*/
public synchronized Network configureTunnelNetwork(final Connection conn, final Long networkId, final long hostId, final String bridgeName) {
try {
final Network nw = findOrCreateTunnelNetwork(conn, bridgeName);
// Invoke plugin to setup the bridge which will be used by this
// network
final String bridge = nw.getBridge(conn);
final Map<String, String> nwOtherConfig = nw.getOtherConfig(conn);
final String configuredHosts = nwOtherConfig.get("ovs-host-setup");
boolean configured = false;
if (configuredHosts != null) {
final String[] hostIdsStr = configuredHosts.split(",");
for (final String hostIdStr : hostIdsStr) {
if (hostIdStr.equals(((Long) hostId).toString())) {
configured = true;
break;
}
}
}
if (!configured) {
String result;
if (bridgeName.startsWith("OVS-DR-VPC-Bridge")) {
result = callHostPlugin(conn, "ovstunnel", "setup_ovs_bridge_for_distributed_routing", "bridge", bridge, "key", bridgeName, "xs_nw_uuid", nw.getUuid(conn), "cs_host_id", ((Long) hostId).toString());
} else {
result = callHostPlugin(conn, "ovstunnel", "setup_ovs_bridge", "bridge", bridge, "key", bridgeName, "xs_nw_uuid", nw.getUuid(conn), "cs_host_id", ((Long) hostId).toString());
}
// Note down the fact that the ovs bridge has been setup
final String[] res = result.split(":");
if (res.length != 2 || !res[0].equalsIgnoreCase("SUCCESS")) {
// TODO: Should make this error not fatal?
throw new CloudRuntimeException("Unable to pre-configure OVS bridge " + bridge);
}
}
return nw;
} catch (final Exception e) {
s_logger.warn("createandConfigureTunnelNetwork failed", e);
return null;
}
}
use of com.xensource.xenapi.Network in project cloudstack by apache.
the class XenServer56Resource method disableVlanNetwork.
@Override
public void disableVlanNetwork(final Connection conn, final Network network) {
try {
final Network.Record networkr = network.getRecord(conn);
if (!networkr.nameLabel.startsWith("VLAN")) {
return;
}
final String bridge = networkr.bridge.trim();
for (final PIF pif : networkr.PIFs) {
final PIF.Record pifr = pif.getRecord(conn);
if (!pifr.host.getUuid(conn).equalsIgnoreCase(_host.getUuid())) {
continue;
}
final VLAN vlan = pifr.VLANMasterOf;
if (vlan != null) {
final String vlannum = pifr.VLAN.toString();
final String device = pifr.device.trim();
if (vlannum.equals("-1")) {
return;
}
try {
vlan.destroy(conn);
final Host host = Host.getByUuid(conn, _host.getUuid());
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
} catch (final XenAPIException e) {
s_logger.trace("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString());
}
}
return;
}
} catch (final XenAPIException e) {
final String msg = "Unable to disable VLAN network due to " + e.toString();
s_logger.warn(msg, e);
} catch (final Exception e) {
final String msg = "Unable to disable VLAN network due to " + e.getMessage();
s_logger.warn(msg, e);
}
}
Aggregations