use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixGetStorageStatsCommandWrapper method execute.
@Override
public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final Set<SR> srs = SR.getByNameLabel(conn, command.getStorageId());
if (srs.size() != 1) {
final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
}
final SR sr = srs.iterator().next();
sr.scan(conn);
final long capacity = sr.getPhysicalSize(conn);
final long used = sr.getPhysicalUtilisation(conn);
return new GetStorageStatsAnswer(command, capacity, used);
} catch (final XenAPIException e) {
final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
} catch (final XmlRpcException e) {
final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
} catch (final Exception e) {
final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
}
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixMaintainCommandWrapper method execute.
@Override
public Answer execute(final MaintainCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final XsHost xsHost = citrixResourceBase.getHost();
final String uuid = xsHost.getUuid();
final Host host = Host.getByUuid(conn, uuid);
// remove all tags cloud stack
final Host.Record hr = host.getRecord(conn);
// Adding this check because could not get the mock to work. Will push the code and fix it afterwards.
if (hr == null) {
s_logger.warn("Host.Record is null.");
return new MaintainAnswer(command, false, "Host.Record is null");
}
final Iterator<String> it = hr.tags.iterator();
while (it.hasNext()) {
final String tag = it.next();
if (tag.contains("cloud")) {
it.remove();
}
}
host.setTags(conn, hr.tags);
return new MaintainAnswer(command);
} catch (final XenAPIException e) {
s_logger.warn("Unable to put server in maintainence mode", e);
return new MaintainAnswer(command, false, e.getMessage());
} catch (final XmlRpcException e) {
s_logger.warn("Unable to put server in maintainence mode", e);
return new MaintainAnswer(command, false, e.getMessage());
}
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixRebootCommandWrapper method execute.
@Override
public Answer execute(final RebootCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
s_logger.debug("7. The VM " + command.getVmName() + " is in Starting state");
try {
Set<VM> vms = null;
try {
vms = VM.getByNameLabel(conn, command.getVmName());
} catch (final XenAPIException e0) {
s_logger.debug("getByNameLabel failed " + e0.toString());
return new RebootAnswer(command, "getByNameLabel failed " + e0.toString(), false);
} catch (final Exception e0) {
s_logger.debug("getByNameLabel failed " + e0.getMessage());
return new RebootAnswer(command, "getByNameLabel failed", false);
}
for (final VM vm : vms) {
try {
citrixResourceBase.rebootVM(conn, vm, vm.getNameLabel(conn));
} catch (final Exception e) {
final String msg = e.toString();
s_logger.warn(msg, e);
return new RebootAnswer(command, msg, false);
}
}
return new RebootAnswer(command, "reboot succeeded", true);
} finally {
s_logger.debug("8. The VM " + command.getVmName() + " is in Running state");
}
}
use of com.xensource.xenapi.Types.XenAPIException 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.Types.XenAPIException in project cloudstack by apache.
the class XenServerResourceNewBase method initialize.
@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
final StartupCommand[] cmds = super.initialize();
final Connection conn = getConnection();
Pool pool;
try {
pool = Pool.getByUuid(conn, _host.getPool());
final Pool.Record poolr = pool.getRecord(conn);
final Host.Record masterRecord = poolr.master.getRecord(conn);
if (_host.getUuid().equals(masterRecord.uuid)) {
_listener = new VmEventListener(true);
//
// TODO disable event listener for now. Wait until everything else is ready
//
// _listener.start();
} else {
_listener = new VmEventListener(false);
}
} catch (final XenAPIException e) {
throw new CloudRuntimeException("Unable to determine who is the master", e);
} catch (final XmlRpcException e) {
throw new CloudRuntimeException("Unable to determine who is the master", e);
}
return cmds;
}
Aggregations