use of com.xensource.xenapi.Types.XenAPIException 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.XenAPIException in project cloudstack by apache.
the class NotAValidCommand method testOvsCreateTunnelCommandSuccess.
@Test
public void testOvsCreateTunnelCommandSuccess() {
final String bridge = "tunnel";
final Connection conn = Mockito.mock(Connection.class);
final Network network = Mockito.mock(Network.class);
final OvsCreateTunnelCommand createTunnel = new OvsCreateTunnelCommand("127.0.0.1", 1, 1l, 2l, 1l, "127.0.1.1", "net01", "cd84c713-f448-48c9-ba25-e6740d4a9003");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
try {
when(citrixResourceBase.findOrCreateTunnelNetwork(conn, createTunnel.getNetworkName())).thenReturn(network);
when(network.getBridge(conn)).thenReturn(bridge);
when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", createTunnel.getRemoteIp(), "key", createTunnel.getKey().toString(), "from", createTunnel.getFrom().toString(), "to", createTunnel.getTo().toString(), "cloudstack-network-id", createTunnel.getNetworkUuid())).thenReturn("SUCCESS:0");
} 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(createTunnel, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
verify(citrixResourceBase, times(1)).configureTunnelNetwork(conn, createTunnel.getNetworkId(), createTunnel.getFrom(), createTunnel.getNetworkName());
assertTrue(answer.getResult());
}
use of com.xensource.xenapi.Types.XenAPIException 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.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method getHostVmStateReport.
protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
// TODO : new VM sync model does not require a cluster-scope report, we
// need to optimize
// the report accordingly
final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
Map<VM, VM.Record> vm_map = null;
for (int i = 0; i < 2; i++) {
try {
// USE THIS TO GET ALL VMS FROM
vm_map = VM.getAllRecords(conn);
// A CLUSTER
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.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method attachConfigDriveIsoToVm.
public boolean attachConfigDriveIsoToVm(final Connection conn, final VM vm) throws XenAPIException, XmlRpcException {
final String vmName = vm.getNameLabel(conn);
final String isoURL = _configDriveIsopath + vmName + ".iso";
VDI srVdi;
try {
final Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + ".iso");
if (vdis.isEmpty()) {
throw new CloudRuntimeException("Could not find ISO with URL: " + isoURL);
}
srVdi = vdis.iterator().next();
} catch (final XenAPIException e) {
s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString());
return false;
} catch (final Exception e) {
s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString());
return false;
}
VBD isoVBD = null;
// Find the VM's CD-ROM VBD
final Set<VBD> vbds = vm.getVBDs(conn);
for (final VBD vbd : vbds) {
final Types.VbdType type = vbd.getType(conn);
final VBD.Record vbdr = vbd.getRecord(conn);
// if the device exists then attach it
if (!vbdr.userdevice.equals(_attachIsoDeviceNum) && type == Types.VbdType.CD) {
isoVBD = vbd;
break;
}
}
if (isoVBD == null) {
//create vbd
final 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;
final VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
isoVBD = cfgDriveVBD;
s_logger.debug("Created CD-ROM VBD for VM: " + vm);
}
if (isoVBD != null) {
// If an ISO is already inserted, eject it
if (isoVBD.getEmpty(conn) == false) {
isoVBD.eject(conn);
}
try {
// Insert the new ISO
isoVBD.insert(conn, srVdi);
s_logger.debug("Attached config drive iso to vm " + vmName);
} catch (final XmlRpcException ex) {
s_logger.debug("Failed to attach config drive iso to vm " + vmName);
return false;
}
}
return true;
}
Aggregations