Search in sources :

Example 6 with VirtualMachine

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");
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) ActionEvent(com.cloud.event.ActionEvent)

Example 7 with VirtualMachine

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");
}
Also used : HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 8 with VirtualMachine

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);
    }
}
Also used : IOException(java.io.IOException) HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 9 with VirtualMachine

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);
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 10 with VirtualMachine

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();
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) FenceCommand(com.cloud.legacymodel.communication.command.FenceCommand) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) ArrayList(java.util.ArrayList) Host(com.cloud.legacymodel.dc.Host) KvmHaMonitor(com.cloud.agent.resource.kvm.ha.KvmHaMonitor) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Test(org.junit.Test)

Aggregations

VirtualMachine (com.cloud.legacymodel.vm.VirtualMachine)73 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)21 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)21 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)18 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)17 ArrayList (java.util.ArrayList)17 HostVO (com.cloud.host.HostVO)15 AsyncJobExecutionContext (com.cloud.framework.jobs.AsyncJobExecutionContext)13 VmWorkJobVO (com.cloud.framework.jobs.impl.VmWorkJobVO)13 List (java.util.List)12 Test (org.junit.Test)10 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 HashMap (java.util.HashMap)9 ServerApiException (com.cloud.api.ServerApiException)8 SystemVmResponse (com.cloud.api.response.SystemVmResponse)8 VirtualMachineMigrationException (com.cloud.legacymodel.exceptions.VirtualMachineMigrationException)8 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)7 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)7 Account (com.cloud.legacymodel.user.Account)7