use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixModifyStoragePoolCommandWrapper method execute.
@Override
public Answer execute(final ModifyStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final StorageFilerTO pool = command.getPool();
final boolean add = command.getAdd();
if (add) {
try {
final String srName = command.getStoragePath() != null ? command.getStoragePath() : pool.getUuid();
final SR sr = citrixResourceBase.getStorageRepository(conn, srName);
citrixResourceBase.setupHeartbeatSr(conn, sr, false);
final long capacity = sr.getPhysicalSize(conn);
final long available = capacity - sr.getPhysicalUtilisation(conn);
if (capacity == -1) {
final String msg = "Pool capacity is -1! pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg);
return new Answer(command, false, msg);
}
final Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, capacity, available, tInfo);
return answer;
} catch (final XenAPIException e) {
final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
} catch (final Exception e) {
final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
} else {
try {
final SR sr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
final String srUuid = sr.getUuid(conn);
final String result = citrixResourceBase.callHostPluginPremium(conn, "setup_heartbeat_file", "host", citrixResourceBase.getHost().getUuid(), "sr", srUuid, "add", "false");
if (result == null || !result.split("#")[1].equals("0")) {
throw new CloudRuntimeException("Unable to remove heartbeat file entry for SR " + srUuid + " due to " + result);
}
return new Answer(command, true, "success");
} catch (final XenAPIException e) {
final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
} catch (final Exception e) {
final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
}
}
use of com.xensource.xenapi.Types.XenAPIException 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.Types.XenAPIException in project cloudstack by apache.
the class CitrixCheckNetworkCommandWrapper method execute.
@Override
public Answer execute(final CheckNetworkCommand command, final CitrixResourceBase citrixResourceBase) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking if network name setup is done on the resource");
}
final List<PhysicalNetworkSetupInfo> infoList = command.getPhysicalNetworkInfoList();
try {
boolean errorout = false;
String msg = "";
for (final PhysicalNetworkSetupInfo info : infoList) {
if (!citrixResourceBase.isNetworkSetupByName(info.getGuestNetworkName())) {
msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Guest Network is not configured on the backend by name " + info.getGuestNetworkName();
errorout = true;
break;
}
if (!citrixResourceBase.isNetworkSetupByName(info.getPrivateNetworkName())) {
msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Private Network is not configured on the backend by name " + info.getPrivateNetworkName();
errorout = true;
break;
}
if (!citrixResourceBase.isNetworkSetupByName(info.getPublicNetworkName())) {
msg = "For Physical Network id:" + info.getPhysicalNetworkId() + ", Public Network is not configured on the backend by name " + info.getPublicNetworkName();
errorout = true;
break;
}
/*if(!isNetworkSetupByName(info.getStorageNetworkName())){
msg = "For Physical Network id:"+ info.getPhysicalNetworkId() + ", Storage Network is not configured on the backend by name " + info.getStorageNetworkName();
errorout = true;
break;
}*/
}
if (errorout) {
s_logger.error(msg);
return new CheckNetworkAnswer(command, false, msg);
} else {
return new CheckNetworkAnswer(command, true, "Network Setup check by names is done");
}
} catch (final XenAPIException e) {
final String msg = "CheckNetworkCommand failed with XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg, e);
return new CheckNetworkAnswer(command, false, msg);
} catch (final Exception e) {
final String msg = "CheckNetworkCommand failed with Exception:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg, e);
return new CheckNetworkAnswer(command, false, msg);
}
}
use of com.xensource.xenapi.Types.XenAPIException 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.Types.XenAPIException 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());
}
}
Aggregations