use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ManagementServerImpl method upgradeSystemVM.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_UPGRADE, eventDescription = "Upgrading system VM", async = true)
public VirtualMachine upgradeSystemVM(final ScaleSystemVMCmd cmd) throws ResourceUnavailableException, ManagementServerException, VirtualMachineMigrationException, ConcurrentOperationException {
final VMInstanceVO vmInstance = _vmInstanceDao.findById(cmd.getId());
if (vmInstance.getHypervisorType() == HypervisorType.XenServer && vmInstance.getState().equals(State.Running)) {
throw new InvalidParameterValueException("Dynamic Scaling operation is not permitted for this hypervisor on system vm");
}
final boolean result = _userVmMgr.upgradeVirtualMachine(cmd.getId(), cmd.getServiceOfferingId(), cmd.getDetails());
if (result) {
final VirtualMachine vm = _vmInstanceDao.findById(cmd.getId());
return vm;
} else {
throw new CloudRuntimeException("Failed to upgrade System VM");
}
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ConsoleProxyServlet method handleAuthRequest.
private void handleAuthRequest(final HttpServletRequest req, final HttpServletResponse resp, final long vmId) {
// TODO authentication channel between console proxy VM and management server needs to be secured,
// the data is now being sent through private network, but this is apparently not enough
final VirtualMachine vm = _vmMgr.findById(vmId);
if (vm == null) {
s_logger.warn("VM " + vmId + " does not exist, sending failed response for authentication request from console proxy");
sendResponse(resp, "failed");
return;
}
if (vm.getHostId() == null) {
s_logger.warn("VM " + vmId + " lost host info, failed response for authentication request from console proxy");
sendResponse(resp, "failed");
return;
}
final HostVO host = _ms.getHostBy(vm.getHostId());
if (host == null) {
s_logger.warn("VM " + vmId + "'s host does not exist, sending failed response for authentication request from console proxy");
sendResponse(resp, "failed");
return;
}
final String sid = req.getParameter("sid");
if (sid == null || !sid.equals(vm.getVncPassword())) {
s_logger.warn("sid " + sid + " in url does not match stored sid.");
sendResponse(resp, "failed");
return;
}
sendResponse(resp, "success");
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ConsoleProxyServlet method handleThumbnailRequest.
private void handleThumbnailRequest(final HttpServletRequest req, final HttpServletResponse resp, final long vmId) {
final VirtualMachine vm = _vmMgr.findById(vmId);
if (vm == null) {
s_logger.warn("VM " + vmId + " does not exist, sending blank response for thumbnail request");
sendResponse(resp, "");
return;
}
if (vm.getHostId() == null) {
s_logger.warn("VM " + vmId + " lost host info, sending blank response for thumbnail request");
sendResponse(resp, "");
return;
}
final HostVO host = _ms.getHostBy(vm.getHostId());
if (host == null) {
s_logger.warn("VM " + vmId + "'s host does not exist, sending blank response for thumbnail request");
sendResponse(resp, "");
return;
}
final String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
if (rootUrl == null) {
sendResponse(resp, "");
return;
}
int w = DEFAULT_THUMBNAIL_WIDTH;
int h = DEFAULT_THUMBNAIL_HEIGHT;
String value = req.getParameter("w");
try {
w = Integer.parseInt(value);
} catch (final NumberFormatException e) {
s_logger.info("[ignored] not a number: " + value);
}
value = req.getParameter("h");
try {
h = Integer.parseInt(value);
} catch (final NumberFormatException e) {
s_logger.info("[ignored] not a number: " + value);
}
try {
addSecurityHeaders(resp);
resp.sendRedirect(composeThumbnailUrl(rootUrl, vm, host, w, h));
} catch (final IOException e) {
s_logger.info("Client may already close the connection", e);
}
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ConsoleProxyServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
if (_accountMgr == null || _vmMgr == null || _ms == null) {
sendResponse(resp, "Service is not ready");
return;
}
if (_keysMgr.getHashKey() == null) {
s_logger.debug("Console/thumbnail access denied. Ticket service is not ready yet");
sendResponse(resp, "Service is not ready");
return;
}
String userId = null;
String account = null;
Account accountObj = null;
addSecurityHeaders(resp);
final Map<String, Object[]> params = new HashMap<>();
params.putAll(req.getParameterMap());
final HttpSession session = req.getSession(false);
if (session == null) {
if (verifyRequest(params)) {
userId = (String) params.get("userid")[0];
account = (String) params.get("account")[0];
accountObj = (Account) params.get("accountobj")[0];
} else {
s_logger.debug("Invalid web session or API key in request, reject console/thumbnail access");
sendResponse(resp, "Access denied. Invalid web session or API key in request");
return;
}
} else {
// adjust to latest API refactoring changes
if (session.getAttribute("userid") != null) {
userId = ((Long) session.getAttribute("userid")).toString();
}
accountObj = (Account) session.getAttribute("accountobj");
if (accountObj != null) {
account = "" + accountObj.getId();
}
}
// Do a sanity check here to make sure the user hasn't already been deleted
if ((userId == null) || (account == null) || (accountObj == null) || !verifyUser(Long.valueOf(userId))) {
s_logger.debug("Invalid user/account, reject console/thumbnail access");
sendResponse(resp, "Access denied. Invalid or inconsistent account is found");
return;
}
final String cmd = req.getParameter("cmd");
if (cmd == null || !isValidCmd(cmd)) {
s_logger.debug("invalid console servlet command: " + cmd);
sendResponse(resp, "");
return;
}
final String vmIdString = req.getParameter("vm");
final VirtualMachine vm = _entityMgr.findByUuid(VirtualMachine.class, vmIdString);
if (vm == null) {
s_logger.info("invalid console servlet command parameter: " + vmIdString);
sendResponse(resp, "");
return;
}
final Long vmId = vm.getId();
if (!checkSessionPermision(req, vmId, accountObj)) {
sendResponse(resp, "Permission denied");
return;
}
if (cmd.equalsIgnoreCase("thumbnail")) {
handleThumbnailRequest(req, resp, vmId);
} else if (cmd.equalsIgnoreCase("access")) {
handleAccessRequest(req, resp, vmId);
} else {
handleAuthRequest(req, resp, vmId);
}
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testFenceCommand.
@Test
public void testFenceCommand() {
final VirtualMachine vm = Mockito.mock(VirtualMachine.class);
final Host host = Mockito.mock(Host.class);
final FenceCommand command = new FenceCommand(vm, host);
final KvmHaMonitor monitor = Mockito.mock(KvmHaMonitor.class);
final NfsStoragePool storagePool = Mockito.mock(NfsStoragePool.class);
final List<NfsStoragePool> pools = new ArrayList<>();
pools.add(storagePool);
when(this.libvirtComputingResource.getMonitor()).thenReturn(monitor);
when(monitor.getStoragePools()).thenReturn(pools);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getMonitor();
verify(monitor, times(1)).getStoragePools();
}
Aggregations