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