use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method getVncUrl.
public String getVncUrl(final Connection conn, final VM vm) {
VM.Record record;
Console c;
try {
record = vm.getRecord(conn);
final Set<Console> consoles = record.consoles;
if (consoles.isEmpty()) {
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
return null;
}
final Iterator<Console> i = consoles.iterator();
while (i.hasNext()) {
c = i.next();
if (c.getProtocol(conn) == Types.ConsoleProtocol.RFB) {
return c.getLocation(conn);
}
}
} catch (final XenAPIException e) {
final String msg = "Unable to get console url due to " + e.toString();
s_logger.warn(msg, e);
return null;
} catch (final XmlRpcException e) {
final String msg = "Unable to get console url due to " + e.getMessage();
s_logger.warn(msg, e);
return null;
}
return null;
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method removeSR.
public void removeSR(final Connection conn, final SR sr) {
if (sr == null) {
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "Removing SR"));
}
for (int i = 0; i < 2; i++) {
try {
final Set<VDI> vdis = sr.getVDIs(conn);
for (final VDI vdi : vdis) {
vdi.forget(conn);
}
Set<PBD> pbds = sr.getPBDs(conn);
for (final PBD pbd : pbds) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(pbd, "Unplugging pbd"));
}
// if (pbd.getCurrentlyAttached(conn)) {
pbd.unplug(conn);
// }
pbd.destroy(conn);
}
pbds = sr.getPBDs(conn);
if (pbds.size() == 0) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "Forgetting"));
}
sr.forget(conn);
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "There is still one or more PBDs attached."));
if (s_logger.isTraceEnabled()) {
for (final PBD pbd : pbds) {
s_logger.trace(logX(pbd, " Still attached"));
}
}
}
} catch (final XenAPIException e) {
s_logger.debug(logX(sr, "Catch XenAPIException: " + e.toString()));
} catch (final XmlRpcException e) {
s_logger.debug(logX(sr, "Catch Exception: " + e.getMessage()));
}
}
s_logger.warn(logX(sr, "Unable to remove SR"));
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixPvlanSetupCommandWrapper method execute.
@Override
public Answer execute(final PvlanSetupCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final String primaryPvlan = command.getPrimary();
final String isolatedPvlan = command.getIsolated();
final String op = command.getOp();
final String dhcpName = command.getDhcpName();
final String dhcpMac = command.getDhcpMac();
final String dhcpIp = command.getDhcpIp();
final String vmMac = command.getVmMac();
final String networkTag = command.getNetworkTag();
String nwNameLabel = null;
try {
final XsLocalNetwork nw = citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag);
if (nw == null) {
s_logger.error("Network is not configured on the backend for pvlan " + primaryPvlan);
throw new CloudRuntimeException("Network for the backend is not configured correctly for pvlan primary: " + primaryPvlan);
}
nwNameLabel = nw.getNetwork().getNameLabel(conn);
} catch (final XenAPIException e) {
s_logger.warn("Fail to get network", e);
return new Answer(command, false, e.toString());
} catch (final XmlRpcException e) {
s_logger.warn("Fail to get network", e);
return new Answer(command, false, e.toString());
}
String result = null;
if (command.getType() == PvlanSetupCommand.Type.DHCP) {
result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac);
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
return new Answer(command, false, result);
} else {
s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
}
} else if (command.getType() == PvlanSetupCommand.Type.VM) {
result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac);
if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
return new Answer(command, false, result);
} else {
s_logger.info("Programmed pvlan for vm with mac " + vmMac);
}
}
return new Answer(command, true, result);
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixReadyCommandWrapper method execute.
@Override
public Answer execute(final ReadyCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final Long dcId = command.getDataCenterId();
// Ignore the result of the callHostPlugin. Even if unmounting the
// snapshots dir fails, let Ready command
// succeed.
citrixResourceBase.umountSnapshotDir(conn, dcId);
citrixResourceBase.setupLinkLocalNetwork(conn);
// try to destroy CD-ROM device for all system VMs on this host
try {
final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
final Set<VM> vms = host.getResidentVMs(conn);
for (final VM vm : vms) {
citrixResourceBase.destroyPatchVbd(conn, vm.getNameLabel(conn));
}
} catch (final Exception e) {
}
try {
final boolean result = citrixResourceBase.cleanupHaltedVms(conn);
if (!result) {
return new ReadyAnswer(command, "Unable to cleanup halted vms");
}
} catch (final XenAPIException e) {
s_logger.warn("Unable to cleanup halted vms", e);
return new ReadyAnswer(command, "Unable to cleanup halted vms");
} catch (final XmlRpcException e) {
s_logger.warn("Unable to cleanup halted vms", e);
return new ReadyAnswer(command, "Unable to cleanup halted vms");
}
return new ReadyAnswer(command);
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class NotAValidCommand method testPvlanSetupCommandDhcpFailure.
@Test
public void testPvlanSetupCommandDhcpFailure() {
final String label = "net";
final Connection conn = Mockito.mock(Connection.class);
final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
final Network network2 = Mockito.mock(Network.class);
final PvlanSetupCommand lanSetup = PvlanSetupCommand.createDhcpSetup("add", URI.create("http://127.0.0.1"), "tag", "dhcp", "0:0:0:0:0:0", "127.0.0.1");
final String primaryPvlan = lanSetup.getPrimary();
final String isolatedPvlan = lanSetup.getIsolated();
final String op = lanSetup.getOp();
final String dhcpName = lanSetup.getDhcpName();
final String dhcpMac = lanSetup.getDhcpMac();
final String dhcpIp = lanSetup.getDhcpIp();
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
try {
when(citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, "tag")).thenReturn(network);
when(network.getNetwork()).thenReturn(network2);
when(network2.getNameLabel(conn)).thenReturn(label);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
when(citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac)).thenReturn("false");
final Answer answer = wrapper.execute(lanSetup, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations