Search in sources :

Example 16 with VirtualRouterProvider

use of com.cloud.network.VirtualRouterProvider in project cloudstack by apache.

the class CreateVirtualRouterElementCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Virtual router element Id: " + getEntityId());
    VirtualRouterProvider result = _service.get(0).getCreatedElement(getEntityId());
    if (result != null) {
        VirtualRouterProviderResponse response = _responseGenerator.createVirtualRouterProviderResponse(result);
        if (response != null) {
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        }
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Virtual Router entity to physical network");
    }
}
Also used : VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider)

Example 17 with VirtualRouterProvider

use of com.cloud.network.VirtualRouterProvider in project cloudstack by apache.

the class ListVirtualRouterElementsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    List<? extends VirtualRouterProvider> providers = _service.get(0).searchForVirtualRouterElement(this);
    ListResponse<VirtualRouterProviderResponse> response = new ListResponse<VirtualRouterProviderResponse>();
    List<VirtualRouterProviderResponse> providerResponses = new ArrayList<VirtualRouterProviderResponse>();
    for (VirtualRouterProvider provider : providers) {
        VirtualRouterProviderResponse providerResponse = _responseGenerator.createVirtualRouterProviderResponse(provider);
        providerResponses.add(providerResponse);
    }
    response.setResponses(providerResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) ArrayList(java.util.ArrayList)

Example 18 with VirtualRouterProvider

use of com.cloud.network.VirtualRouterProvider in project cloudstack by apache.

the class LoadBalanceRuleHandler method deployELBVm.

private DomainRouterVO deployELBVm(Network guestNetwork, final DeployDestination dest, Account owner, final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException {
    final long dcId = dest.getDataCenter().getId();
    // lock guest network
    final Long guestNetworkId = guestNetwork.getId();
    guestNetwork = _networkDao.acquireInLockTable(guestNetworkId);
    if (guestNetwork == null) {
        throw new ConcurrentOperationException("Unable to acquire network lock: " + guestNetworkId);
    }
    try {
        if (_networkModel.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) {
            owner = _accountService.getSystemAccount();
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest);
        }
        assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
        DataCenterDeployment plan = null;
        DomainRouterVO elbVm = null;
        plan = new DataCenterDeployment(dcId, dest.getPod().getId(), null, null, null, null);
        if (elbVm == null) {
            final long id = _routerDao.getNextInSequence(Long.class, "id");
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Creating the ELB vm " + id);
            }
            final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
            final NetworkOffering controlOffering = offerings.get(0);
            final Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
            final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(2);
            final NicProfile guestNic = new NicProfile();
            guestNic.setDefaultNic(true);
            networks.put(controlConfig, new ArrayList<NicProfile>());
            networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
            final VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
            final String typeString = "ElasticLoadBalancerVm";
            final Long physicalNetworkId = _networkModel.getPhysicalNetworkId(guestNetwork);
            final PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, typeString);
            if (provider == null) {
                throw new CloudRuntimeException("Cannot find service provider " + typeString + " in physical network " + physicalNetworkId);
            }
            final VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), Type.ElasticLoadBalancerVm);
            if (vrProvider == null) {
                throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
            }
            long userId = CallContext.current().getCallingUserId();
            if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
                List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
                if (!userVOs.isEmpty()) {
                    userId = userVOs.get(0).getId();
                }
            }
            ServiceOfferingVO elasticLbVmOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.elbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
            elbVm = new DomainRouterVO(id, elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, elasticLbVmOffering.getOfferHA(), false, null);
            elbVm.setRole(Role.LB);
            elbVm = _routerDao.persist(elbVm);
            _itMgr.allocate(elbVm.getInstanceName(), template, elasticLbVmOffering, networks, plan, null);
            elbVm = _routerDao.findById(elbVm.getId());
        //TODO: create usage stats
        }
        final State state = elbVm.getState();
        if (state != State.Running) {
            elbVm = start(elbVm, params);
        }
        return elbVm;
    } finally {
        _networkDao.releaseFromLockTable(guestNetworkId);
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) UserVO(com.cloud.user.UserVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) State(com.cloud.vm.VirtualMachine.State) RedundantState(com.cloud.network.router.VirtualRouter.RedundantState) Network(com.cloud.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 19 with VirtualRouterProvider

use of com.cloud.network.VirtualRouterProvider in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method sendNetworkRulesToRouter.

protected boolean sendNetworkRulesToRouter(final long routerId, final long networkId) throws ResourceUnavailableException {
    final DomainRouterVO router = _routerDao.findById(routerId);
    final Commands cmds = new Commands(OnError.Continue);
    final VirtualRouterProvider vrProvider = _vrProviderDao.findById(router.getElementId());
    if (vrProvider == null) {
        throw new CloudRuntimeException("Cannot find related virtual router provider of router: " + router.getHostName());
    }
    final Provider provider = Network.Provider.getProvider(vrProvider.getType().toString());
    if (provider == null) {
        throw new CloudRuntimeException("Cannot find related provider of virtual router provider: " + vrProvider.getType().toString());
    }
    finalizeNetworkRulesForNetwork(cmds, router, provider, networkId);
    return _nwHelper.sendCommandsToRouter(router, cmds);
}
Also used : VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Commands(com.cloud.agent.manager.Commands) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider)

Aggregations

VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)19 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 ServerApiException (org.apache.cloudstack.api.ServerApiException)6 DomainRouterVO (com.cloud.vm.DomainRouterVO)5 ArrayList (java.util.ArrayList)5 Provider (com.cloud.network.Network.Provider)4 NicProfile (com.cloud.vm.NicProfile)4 VirtualRouterProviderResponse (com.cloud.api.response.VirtualRouterProviderResponse)3 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)3 InternalLoadBalancerElementResponse (org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse)3 VirtualRouterProviderResponse (org.apache.cloudstack.api.response.VirtualRouterProviderResponse)3 AggregationControlCommand (com.cloud.agent.api.routing.AggregationControlCommand)2 ServerApiException (com.cloud.api.ServerApiException)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 Network (com.cloud.network.Network)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 Test (org.junit.Test)2 Command (com.cloud.agent.api.Command)1 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)1