Search in sources :

Example 71 with ReservationContext

use of com.cloud.vm.ReservationContext in project cloudstack by apache.

the class KubernetesClusterDestroyWorker method destroyKubernetesClusterNetwork.

private void destroyKubernetesClusterNetwork() throws ManagementServerException {
    NetworkVO network = networkDao.findById(kubernetesCluster.getNetworkId());
    if (network != null && network.getRemoved() == null) {
        Account owner = accountManager.getAccount(network.getAccountId());
        User callerUser = accountManager.getActiveUser(CallContext.current().getCallingUserId());
        ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
        boolean networkDestroyed = networkMgr.destroyNetwork(kubernetesCluster.getNetworkId(), context, true);
        if (!networkDestroyed) {
            String msg = String.format("Failed to destroy network : %s as part of Kubernetes cluster : %s cleanup", network.getName(), kubernetesCluster.getName());
            LOGGER.warn(msg);
            throw new ManagementServerException(msg);
        }
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info(String.format("Destroyed network : %s as part of Kubernetes cluster : %s cleanup", network.getName(), kubernetesCluster.getName()));
        }
    }
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) ManagementServerException(com.cloud.exception.ManagementServerException) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext)

Example 72 with ReservationContext

use of com.cloud.vm.ReservationContext 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

ReservationContext (com.cloud.vm.ReservationContext)72 Account (com.cloud.user.Account)45 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)42 DeployDestination (com.cloud.deploy.DeployDestination)41 NetworkVO (com.cloud.network.dao.NetworkVO)41 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)38 Test (org.junit.Test)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 NetworkOffering (com.cloud.offering.NetworkOffering)27 Network (com.cloud.network.Network)24 Domain (com.cloud.domain.Domain)23 HostVO (com.cloud.host.HostVO)22 DataCenter (com.cloud.dc.DataCenter)21 URI (java.net.URI)19 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 NicProfile (com.cloud.vm.NicProfile)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)14 User (com.cloud.user.User)14 NicVO (com.cloud.vm.NicVO)14