use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class CitrixResourceBase method setupvSwitchNetwork.
public synchronized Network setupvSwitchNetwork(final Connection conn) {
try {
if (_host.getVswitchNetwork() == null) {
Network vswitchNw = null;
final Network.Record rec = new Network.Record();
final String nwName = Networks.BroadcastScheme.VSwitch.toString();
final Set<Network> networks = Network.getByNameLabel(conn, nwName);
if (networks.size() == 0) {
rec.nameDescription = "vswitch network for " + nwName;
rec.nameLabel = nwName;
vswitchNw = Network.create(conn, rec);
} else {
vswitchNw = networks.iterator().next();
}
_host.setVswitchNetwork(vswitchNw);
}
return _host.getVswitchNetwork();
} catch (final BadServerResponse e) {
s_logger.error("Failed to setup vswitch network", e);
} catch (final XenAPIException e) {
s_logger.error("Failed to setup vswitch network", e);
} catch (final XmlRpcException e) {
s_logger.error("Failed to setup vswitch network", e);
}
return null;
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class CitrixResourceBase method getHostVmStateReport.
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
Map<VM, VM.Record> vm_map = null;
for (int i = 0; i < 2; i++) {
try {
vm_map = VM.getAllRecords(conn);
break;
} catch (final Throwable e) {
s_logger.warn("Unable to get vms", e);
}
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
}
}
if (vm_map == null) {
return vmStates;
}
for (final VM.Record record : vm_map.values()) {
if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
// Skip DOM0
continue;
}
final VmPowerState ps = record.powerState;
final Host host = record.residentOn;
String host_uuid = null;
if (!isRefNull(host)) {
try {
host_uuid = host.getUuid(conn);
} catch (final BadServerResponse e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
} catch (final XenAPIException e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
} catch (final XmlRpcException e) {
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
}
if (host_uuid.equalsIgnoreCase(_host.getUuid())) {
vmStates.put(record.nameLabel, new HostVmStateReportEntry(convertToPowerState(ps), host_uuid));
}
}
}
return vmStates;
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class CitrixResourceBase method attachConfigDriveToMigratedVm.
public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, String ipAddr) {
try {
s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr);
Set<VM> vms = VM.getByNameLabel(conn, vmName);
SR sr = getSRByNameLabel(conn, vmName + VM_NAME_ISO_SUFFIX);
// Here you will find only two vdis with the <vmname>.iso.
// one is from source host and second from dest host
Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + VM_FILE_ISO_SUFFIX);
if (vdis.isEmpty()) {
s_logger.debug("Could not find config drive ISO: " + vmName);
return false;
}
VDI configdriveVdi = null;
for (VDI vdi : vdis) {
SR vdiSr = vdi.getSR(conn);
if (vdiSr.getUuid(conn).equals(sr.getUuid(conn))) {
// get this vdi to attach to vbd
configdriveVdi = vdi;
s_logger.debug("VDI for the config drive ISO " + vdi);
} else {
// delete the vdi in source host so that the <vmname>.iso file is get removed
s_logger.debug("Removing the source host VDI for the config drive ISO " + vdi);
vdi.destroy(conn);
}
}
if (configdriveVdi == null) {
s_logger.debug("Config drive ISO VDI is not found ");
return false;
}
for (VM vm : vms) {
// create vbd
VBD.Record cfgDriveVbdr = new VBD.Record();
cfgDriveVbdr.VM = vm;
cfgDriveVbdr.empty = true;
cfgDriveVbdr.bootable = false;
cfgDriveVbdr.userdevice = "autodetect";
cfgDriveVbdr.mode = Types.VbdMode.RO;
cfgDriveVbdr.type = Types.VbdType.CD;
VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
s_logger.debug("Inserting vbd " + configdriveVdi);
cfgDriveVBD.insert(conn, configdriveVdi);
break;
}
return true;
} catch (BadServerResponse e) {
s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a bad server response.", e);
return false;
} catch (XenAPIException e) {
s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a xapi problem.", e);
return false;
} catch (XmlRpcException e) {
s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a problem in a remote call.", e);
return false;
}
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class NotAValidCommand method testOvsDestroyTunnelCommandSuccess.
@Test
public void testOvsDestroyTunnelCommandSuccess() {
final String bridge = "tunnel";
final Connection conn = Mockito.mock(Connection.class);
final Network network = Mockito.mock(Network.class);
final OvsDestroyTunnelCommand destroyTunnel = new OvsDestroyTunnelCommand(1l, "net01", "port11");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
try {
when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyTunnel.getBridgeName())).thenReturn(network);
when(network.getBridge(conn)).thenReturn(bridge);
when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", destroyTunnel.getInPortName())).thenReturn("SUCCESS");
} catch (final BadServerResponse e) {
fail(e.getMessage());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(destroyTunnel, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertTrue(answer.getResult());
}
use of com.xensource.xenapi.Types.BadServerResponse in project cloudstack by apache.
the class NotAValidCommand method testOvsVpcPhysicalTopologyConfigCommand.
@Test
public void testOvsVpcPhysicalTopologyConfigCommand() {
final String bridge = "gre";
final Connection conn = Mockito.mock(Connection.class);
final Network network = Mockito.mock(Network.class);
final OvsVpcPhysicalTopologyConfigCommand.Host[] hosts = new OvsVpcPhysicalTopologyConfigCommand.Host[0];
final OvsVpcPhysicalTopologyConfigCommand.Tier[] tiers = new OvsVpcPhysicalTopologyConfigCommand.Tier[0];
final OvsVpcPhysicalTopologyConfigCommand.Vm[] vms = new OvsVpcPhysicalTopologyConfigCommand.Vm[0];
final OvsVpcPhysicalTopologyConfigCommand physicalTopology = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, "10.0.0.1/24");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
try {
when(citrixResourceBase.findOrCreateTunnelNetwork(conn, physicalTopology.getBridgeName())).thenReturn(network);
when(network.getBridge(conn)).thenReturn(bridge);
when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge", bridge, "config", physicalTopology.getVpcConfigInJson(), "host-id", ((Long) physicalTopology.getHostId()).toString(), "seq-no", Long.toString(1))).thenReturn("SUCCESS");
} catch (final BadServerResponse e) {
fail(e.getMessage());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(physicalTopology, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations