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);
}
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;
}
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;
}
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);
}
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);
}
Aggregations