Search in sources :

Example 31 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final UserdataToRouterRules userdata) throws ResourceUnavailableException {
    final VirtualRouter router = userdata.getRouter();
    final Commands commands = new Commands(Command.OnError.Stop);
    final VMOverviewTO vmOverview = _commandSetupHelper.createVmOverviewFromRouter(router);
    final UpdateVmOverviewCommand updateVmOverviewCommand = _commandSetupHelper.createUpdateVmOverviewCommand(router, vmOverview);
    commands.addCommand(updateVmOverviewCommand);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : VMOverviewTO(com.cloud.legacymodel.to.VMOverviewTO) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) UpdateVmOverviewCommand(com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand)

Example 32 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method savePassword.

@Override
public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
    if (!canHandle(network, null)) {
        return false;
    }
    final List<DomainRouterVO> routers = this._routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Can't find virtual router element in network " + network.getId());
        return true;
    }
    final VirtualMachineProfile uservm = vm;
    final Zone zone = this.zoneRepository.findById(network.getDataCenterId()).orElse(null);
    final NetworkTopology networkTopology = this.networkTopologyContext.retrieveNetworkTopology(zone);
    // save the password in DB
    for (final VirtualRouter router : routers) {
        if (router.getState() == State.Running) {
            return networkTopology.savePasswordToRouter(network, nic, uservm, router);
        }
    }
    final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
    final String password_encrypted = DBEncryptionUtil.encrypt(password);
    final UserVmVO userVmVO = this._userVmDao.findById(vm.getId());
    this._userVmDao.loadDetails(userVmVO);
    userVmVO.setDetail("password", password_encrypted);
    this._userVmDao.saveDetails(userVmVO);
    userVmVO.setUpdateParameters(true);
    this._userVmDao.update(userVmVO.getId(), userVmVO);
    return true;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 33 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method shutdown.

@Override
public boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
    final Long vpcId = network.getVpcId();
    if (vpcId == null) {
        s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part");
        return true;
    }
    boolean success = true;
    final List<? extends VirtualRouter> routers = _routerDao.listByVpcId(vpcId);
    for (final VirtualRouter router : routers) {
        // 1) Check if router is already a part of the network
        if (!_networkMdl.isVmPartOfNetwork(router.getId(), network.getId())) {
            s_logger.debug("Router " + router + " is not a part the network " + network);
            continue;
        }
        // 2) Call unplugNics in the network service
        success = success && _vpcRouterMgr.removeVpcRouterFromGuestNetwork(router, network);
        if (!success) {
            s_logger.warn("Failed to unplug nic in network " + network + " for virtual router " + router);
        } else {
            s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router " + router);
        }
    }
    return success;
}
Also used : VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 34 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class NetworkHelperImplTest method testSendCommandsToRouterWithNoAnswers.

/**
 * If the number of answers is different to the number of commands the result is false
 *
 * @throws AgentUnavailableException
 * @throws OperationTimedoutException
 */
@Test
public void testSendCommandsToRouterWithNoAnswers() throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException {
    // Prepare
    final NetworkHelperImpl nwHelperUT = spy(this.nwHelper);
    final VirtualRouter vr = mock(VirtualRouter.class);
    when(vr.getHostId()).thenReturn(HOST_ID);
    doReturn(true).when(nwHelperUT).checkRouterVersion(vr);
    final Commands commands = mock(Commands.class);
    when(commands.size()).thenReturn(3);
    final Answer answer1 = mock(Answer.class);
    final Answer answer2 = mock(Answer.class);
    // In the second iteration it should match and return, without invoking the third
    final Answer[] answers = { answer1, answer2 };
    when(this.agentManager.send(HOST_ID, commands)).thenReturn(answers);
    // Execute
    final boolean result = nwHelperUT.sendCommandsToRouter(vr, commands);
    // Assert
    verify(this.agentManager, times(1)).send(HOST_ID, commands);
    verify(answer1, times(0)).getResult();
    assertFalse(result);
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) Test(org.junit.Test)

Example 35 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class NetworkHelperImplTest method testSendCommandsToRouter.

@Test
public void testSendCommandsToRouter() throws AgentUnavailableException, OperationTimedoutException, ResourceUnavailableException {
    // Prepare
    final NetworkHelperImpl nwHelperUT = spy(this.nwHelper);
    final VirtualRouter vr = mock(VirtualRouter.class);
    when(vr.getHostId()).thenReturn(HOST_ID);
    doReturn(true).when(nwHelperUT).checkRouterVersion(vr);
    final Commands commands = mock(Commands.class);
    when(commands.size()).thenReturn(3);
    final Answer answer1 = mock(Answer.class);
    final Answer answer2 = mock(Answer.class);
    final Answer answer3 = mock(Answer.class);
    // In the second iteration it should match and return, without invoking the third
    final Answer[] answers = { answer1, answer2, answer3 };
    when(answer1.getResult()).thenReturn(true);
    when(answer2.getResult()).thenReturn(false);
    when(answer3.getResult()).thenReturn(false);
    when(this.agentManager.send(HOST_ID, commands)).thenReturn(answers);
    // Execute
    final boolean result = nwHelperUT.sendCommandsToRouter(vr, commands);
    // Assert
    verify(this.agentManager, times(1)).send(HOST_ID, commands);
    verify(answer1, times(1)).getResult();
    verify(answer2, times(1)).getResult();
    verify(answer3, times(0)).getResult();
    assertFalse(result);
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) Test(org.junit.Test)

Aggregations

VirtualRouter (com.cloud.legacymodel.network.VirtualRouter)36 Commands (com.cloud.agent.manager.Commands)21 UpdateVmOverviewCommand (com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand)8 VMOverviewTO (com.cloud.legacymodel.to.VMOverviewTO)8 NicVO (com.cloud.vm.NicVO)8 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)8 UpdateNetworkOverviewCommand (com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand)7 NetworkOverviewTO (com.cloud.legacymodel.to.NetworkOverviewTO)7 DomainRouterVO (com.cloud.vm.DomainRouterVO)7 ServerApiException (com.cloud.api.ServerApiException)5 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)5 Zone (com.cloud.db.model.Zone)5 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)5 Ip (com.cloud.legacymodel.network.Ip)5 UserVmVO (com.cloud.vm.UserVmVO)5 ArrayList (java.util.ArrayList)5 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)4 Network (com.cloud.legacymodel.network.Network)4 Config (com.cloud.configuration.Config)3 ZoneRepository (com.cloud.db.repository.ZoneRepository)3