Search in sources :

Example 56 with DeployDestination

use of com.cloud.deploy.DeployDestination in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method startRouter.

@Override
public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // verify parameters
    DomainRouterVO router = _routerDao.findById(routerId);
    //clean up the update_state feild
    if (router.getUpdateState() == VirtualRouter.UpdateState.UPDATE_FAILED) {
        router.setUpdateState(null);
        _routerDao.update(router.getId(), router);
    }
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    final Account owner = _accountMgr.getAccount(router.getAccountId());
    // Check if all networks are implemented for the domR; if not -
    // implement them
    final DataCenter dc = _dcDao.findById(router.getDataCenterId());
    HostPodVO pod = null;
    if (router.getPodIdToDeployIn() != null) {
        pod = _podDao.findById(router.getPodIdToDeployIn());
    }
    final DeployDestination dest = new DeployDestination(dc, pod, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
    final List<NicVO> nics = _nicDao.listByVmId(routerId);
    for (final NicVO nic : nics) {
        if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
            s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
            throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
        }
    }
    // After start network, check if it's already running
    router = _routerDao.findById(routerId);
    if (router.getState() == VirtualMachine.State.Running) {
        return router;
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    final Map<Param, Object> params = new HashMap<Param, Object>();
    if (reprogramNetwork) {
        params.put(Param.ReProgramGuestNetworks, true);
    } else {
        params.put(Param.ReProgramGuestNetworks, false);
    }
    final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
    if (virtualRouter == null) {
        throw new CloudRuntimeException("Failed to start router with id " + routerId);
    }
    return virtualRouter;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) HashMap(java.util.HashMap) HostPodVO(com.cloud.dc.HostPodVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Param(com.cloud.vm.VirtualMachineProfile.Param) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DeployDestination (com.cloud.deploy.DeployDestination)56 DataCenter (com.cloud.dc.DataCenter)27 Account (com.cloud.user.Account)27 Test (org.junit.Test)27 ReservationContext (com.cloud.vm.ReservationContext)26 HostVO (com.cloud.host.HostVO)19 Network (com.cloud.network.Network)18 NetworkVO (com.cloud.network.dao.NetworkVO)18 NetworkOffering (com.cloud.offering.NetworkOffering)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Domain (com.cloud.domain.Domain)17 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)15 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)15 URI (java.net.URI)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 ArrayList (java.util.ArrayList)11 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 Host (com.cloud.host.Host)8 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)8