use of com.xensource.xenapi.Host in project cloudstack by apache.
the class NotAValidCommand method testScaleVmCommand.
@Test
public void testScaleVmCommand() {
final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
final VirtualMachineTO machineTO = Mockito.mock(VirtualMachineTO.class);
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final Host host = Mockito.mock(Host.class);
final ScaleVmCommand scaleVm = new ScaleVmCommand(machineTO);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
try {
when(citrixResourceBase.isDmcEnabled(conn, host)).thenReturn(true);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(scaleVm, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class XenServer620SP1Resource method getGPUGroupDetails.
@Override
public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final Connection conn) throws XenAPIException, XmlRpcException {
final HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>();
final Host host = Host.getByUuid(conn, _host.getUuid());
final Set<PGPU> pgpus = host.getPGPUs(conn);
final Iterator<PGPU> iter = pgpus.iterator();
while (iter.hasNext()) {
final PGPU pgpu = iter.next();
final GPUGroup gpuGroup = pgpu.getGPUGroup(conn);
final Set<VGPUType> enabledVGPUTypes = gpuGroup.getEnabledVGPUTypes(conn);
final String groupName = gpuGroup.getNameLabel(conn);
HashMap<String, VgpuTypesInfo> gpuCapacity = new HashMap<String, VgpuTypesInfo>();
if (groupDetails.get(groupName) != null) {
gpuCapacity = groupDetails.get(groupName);
}
// Get remaining capacity of all the enabled VGPU in a PGPU
if (enabledVGPUTypes != null) {
final Iterator<VGPUType> it = enabledVGPUTypes.iterator();
while (it.hasNext()) {
final VGPUType type = it.next();
final Record record = type.getRecord(conn);
Long remainingCapacity = pgpu.getRemainingCapacity(conn, type);
Long maxCapacity = pgpu.getSupportedVGPUMaxCapacities(conn).get(type);
VgpuTypesInfo entry;
if ((entry = gpuCapacity.get(record.modelName)) != null) {
remainingCapacity += entry.getRemainingCapacity();
maxCapacity += entry.getMaxCapacity();
entry.setRemainingCapacity(remainingCapacity);
entry.setMaxVmCapacity(maxCapacity);
gpuCapacity.put(record.modelName, entry);
} else {
final VgpuTypesInfo vgpuTypeRecord = new VgpuTypesInfo(null, record.modelName, record.framebufferSize, record.maxHeads, record.maxResolutionX, record.maxResolutionY, maxCapacity, remainingCapacity, maxCapacity);
gpuCapacity.put(record.modelName, vgpuTypeRecord);
}
}
}
groupDetails.put(groupName, gpuCapacity);
}
return groupDetails;
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class XenServerConnectionPool method connect.
public Connection connect(String hostUuid, String poolUuid, String ipAddress, String username, Queue<String> password, int wait) {
XenServerConnection mConn = null;
if (hostUuid == null || poolUuid == null || ipAddress == null || username == null || password == null) {
String msg = "Connect some parameter are null hostUuid:" + hostUuid + " ,poolUuid:" + poolUuid + " ,ipAddress:" + ipAddress;
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
synchronized (poolUuid.intern()) {
mConn = getConnect(poolUuid);
if (mConn != null) {
try {
Host host = Host.getByUuid(mConn, hostUuid);
if (!host.getEnabled(mConn)) {
String msg = "Cannot connect this host " + ipAddress + " due to the host is not enabled";
s_logger.debug(msg);
if (mConn.getIp().equalsIgnoreCase(ipAddress)) {
removeConnect(poolUuid);
mConn = null;
}
throw new CloudRuntimeException(msg);
}
return mConn;
} catch (CloudRuntimeException e) {
throw e;
} catch (Exception e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("connect through IP(" + mConn.getIp() + " for pool(" + poolUuid + ") is broken due to " + e.toString());
}
removeConnect(poolUuid);
mConn = null;
}
}
if (mConn == null) {
try {
Connection conn = new Connection(getURL(ipAddress), 5, _connWait);
Session sess = loginWithPassword(conn, username, password, APIVersion.latest().toString());
Host host = sess.getThisHost(conn);
Boolean hostenabled = host.getEnabled(conn);
if (sess != null) {
try {
Session.logout(conn);
} catch (Exception e) {
s_logger.debug("Caught exception during logout", e);
}
conn.dispose();
}
if (!hostenabled) {
String msg = "Unable to create master connection, due to master Host " + ipAddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait, _connWait);
loginWithPassword(mConn, username, password, APIVersion.latest().toString());
} catch (Types.HostIsSlave e) {
String maddress = e.masterIPAddress;
mConn = new XenServerConnection(getURL(maddress), maddress, username, password, _retries, _interval, wait, _connWait);
try {
Session session = loginWithPassword(mConn, username, password, APIVersion.latest().toString());
Host host = session.getThisHost(mConn);
if (!host.getEnabled(mConn)) {
String msg = "Unable to create master connection, due to master Host " + maddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
} catch (Exception e1) {
String msg = "Unable to create master connection to host(" + maddress + ") , due to " + e1.toString();
s_logger.debug(msg);
throw new CloudRuntimeException(msg, e1);
}
} catch (CloudRuntimeException e) {
throw e;
} catch (Exception e) {
String msg = "Unable to create master connection to host(" + ipAddress + ") , due to " + e.toString();
s_logger.debug(msg);
throw new CloudRuntimeException(msg, e);
}
addConnect(poolUuid, mConn);
}
}
return mConn;
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class CitrixResourceBase method setupHeartbeatSr.
public String setupHeartbeatSr(final Connection conn, final SR sr, final boolean force) throws XenAPIException, XmlRpcException {
final SR.Record srRec = sr.getRecord(conn);
final String srUuid = srRec.uuid;
if (!srRec.shared || !SRType.LVMOHBA.equals(srRec.type) && !SRType.LVMOISCSI.equals(srRec.type) && !SRType.NFS.equals(srRec.type)) {
return srUuid;
}
String result = null;
final Host host = Host.getByUuid(conn, _host.getUuid());
final Set<String> tags = host.getTags(conn);
if (force || !tags.contains("cloud-heartbeat-" + srUuid)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up the heartbeat sr for host " + _host.getIp() + " and sr " + srUuid);
}
final Set<PBD> pbds = sr.getPBDs(conn);
for (final PBD pbd : pbds) {
final PBD.Record pbdr = pbd.getRecord(conn);
if (!pbdr.currentlyAttached && pbdr.host.getUuid(conn).equals(_host.getUuid())) {
pbd.plug(conn);
break;
}
}
result = callHostPluginThroughMaster(conn, "vmopspremium", "setup_heartbeat_sr", "host", _host.getUuid(), "sr", srUuid);
if (result == null || !result.split("#")[1].equals("0")) {
throw new CloudRuntimeException("Unable to setup heartbeat sr on SR " + srUuid + " due to " + result);
}
if (!tags.contains("cloud-heartbeat-" + srUuid)) {
tags.add("cloud-heartbeat-" + srUuid);
host.setTags(conn, tags);
}
}
result = callHostPluginPremium(conn, "setup_heartbeat_file", "host", _host.getUuid(), "sr", srUuid, "add", "true");
if (result == null || !result.split("#")[1].equals("0")) {
throw new CloudRuntimeException("Unable to setup heartbeat file entry on SR " + srUuid + " due to " + result);
}
return srUuid;
}
use of com.xensource.xenapi.Host in project cloudstack by apache.
the class XenServer620Resource method hostHasHotFix.
protected boolean hostHasHotFix(final Connection conn, final String hotFixUuid) {
try {
final Host host = Host.getByUuid(conn, _host.getUuid());
final Host.Record re = host.getRecord(conn);
final Set<HostPatch> patches = re.patches;
final PoolPatch poolPatch = PoolPatch.getByUuid(conn, hotFixUuid);
for (final HostPatch patch : patches) {
final PoolPatch pp = patch.getPoolPatch(conn);
if (pp.equals(poolPatch) && patch.getApplied(conn)) {
return true;
}
}
} catch (final Exception e) {
s_logger.debug("can't get patches information for hotFix: " + hotFixUuid);
}
return false;
}
Aggregations