Search in sources :

Example 11 with PhysicalNetworkServiceProvider

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

the class ManagementServerMock method locatePhysicalNetwork.

private void locatePhysicalNetwork() {
    // mandatory: name, zone-id
    try {
        long id = _networkService.findPhysicalNetworkId(_zone.getId(), "znet", TrafficType.Guest);
        _znet = _networkService.getPhysicalNetwork(id);
        List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
        if (nets == null || nets.isEmpty()) {
            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), "vlan", null, null, null, null, null, null, null);
        }
    } catch (InvalidParameterValueException e) {
        List<String> isolationMethods = new ArrayList<String>();
        isolationMethods.add("L3VPN");
        _znet = _networkService.createPhysicalNetwork(_zone.getId(), null, null, isolationMethods, BroadcastDomainRange.ZONE.toString(), _zone.getDomainId(), null, "znet");
        List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
        if (nets == null || nets.isEmpty()) {
            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), "vlan", null, null, null, null, null, null, null);
        }
    }
    if (_znet.getState() != PhysicalNetwork.State.Enabled) {
        _znet = _networkService.updatePhysicalNetwork(_znet.getId(), null, null, null, PhysicalNetwork.State.Enabled.toString());
    }
    // Ensure that the physical network supports Guest traffic.
    Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(_znet.getId());
    boolean found = false;
    for (PhysicalNetworkTrafficType ttype : trafficTypes.first()) {
        if (ttype.getTrafficType() == TrafficType.Guest) {
            found = true;
        }
    }
    if (!found) {
        _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Guest.toString(), "vlan", null, null, null, null, null, null, null);
    }
    Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> providers = _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null, null);
    if (providers.second() == 0) {
        s_logger.debug("Add " + Provider.JuniperContrailRouter.getName() + " to network " + _znet.getName());
        PhysicalNetworkServiceProvider provider = _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null);
        _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
    } else {
        PhysicalNetworkServiceProvider provider = providers.first().get(0);
        if (provider.getState() != PhysicalNetworkServiceProvider.State.Enabled) {
            _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
        }
    }
    providers = _networkService.listNetworkServiceProviders(_znet.getId(), null, PhysicalNetworkServiceProvider.State.Enabled.toString(), null, null);
    s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled providers");
    for (PhysicalNetworkServiceProvider provider : providers.first()) {
        if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName())) {
            continue;
        }
        s_logger.debug("Disabling " + provider.getProviderName());
        _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Disabled.toString(), null);
    }
}
Also used : PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) List(java.util.List) ArrayList(java.util.ArrayList) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 12 with PhysicalNetworkServiceProvider

use of com.cloud.network.PhysicalNetworkServiceProvider 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 13 with PhysicalNetworkServiceProvider

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

the class ApiDBUtils method findJobInstanceUuid.

public static String findJobInstanceUuid(AsyncJob job) {
    if (job == null) {
        return null;
    }
    String jobInstanceId = null;
    ApiCommandJobType jobInstanceType = EnumUtils.fromString(ApiCommandJobType.class, job.getInstanceType(), ApiCommandJobType.None);
    if (job.getInstanceId() == null) {
        // when assert is hit, implement 'getInstanceId' of BaseAsyncCmd and return appropriate instance id
        assert (false);
        return null;
    }
    if (jobInstanceType == ApiCommandJobType.Volume) {
        VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
        if (volume != null) {
            jobInstanceId = volume.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
        VMTemplateVO template = ApiDBUtils.findTemplateById(job.getInstanceId());
        if (template != null) {
            jobInstanceId = template.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.VirtualMachine || jobInstanceType == ApiCommandJobType.ConsoleProxy || jobInstanceType == ApiCommandJobType.SystemVm || jobInstanceType == ApiCommandJobType.DomainRouter) {
        VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
        if (vm != null) {
            jobInstanceId = vm.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Snapshot) {
        Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
        if (snapshot != null) {
            jobInstanceId = snapshot.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Host) {
        Host host = ApiDBUtils.findHostById(job.getInstanceId());
        if (host != null) {
            jobInstanceId = host.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.StoragePool) {
        StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
        if (spool != null) {
            jobInstanceId = spool.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.IpAddress) {
        IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
        if (ip != null) {
            jobInstanceId = ip.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.SecurityGroup) {
        SecurityGroup sg = ApiDBUtils.findSecurityGroupById(job.getInstanceId());
        if (sg != null) {
            jobInstanceId = sg.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
        PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
        if (pnet != null) {
            jobInstanceId = pnet.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.TrafficType) {
        PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
        if (trafficType != null) {
            jobInstanceId = trafficType.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
        PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
        if (sp != null) {
            jobInstanceId = sp.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
        FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
        if (fw != null) {
            jobInstanceId = fw.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Account) {
        Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
        if (acct != null) {
            jobInstanceId = acct.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.User) {
        User usr = ApiDBUtils.findUserById(job.getInstanceId());
        if (usr != null) {
            jobInstanceId = usr.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
        StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
        if (route != null) {
            jobInstanceId = route.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
        VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
        if (gateway != null) {
            jobInstanceId = gateway.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Counter) {
        CounterVO counter = ApiDBUtils.getCounter(job.getInstanceId());
        if (counter != null) {
            jobInstanceId = counter.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Condition) {
        ConditionVO condition = ApiDBUtils.findConditionById(job.getInstanceId());
        if (condition != null) {
            jobInstanceId = condition.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.AutoScalePolicy) {
        AutoScalePolicyVO policy = ApiDBUtils.findAutoScalePolicyById(job.getInstanceId());
        if (policy != null) {
            jobInstanceId = policy.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.AutoScaleVmProfile) {
        AutoScaleVmProfileVO profile = ApiDBUtils.findAutoScaleVmProfileById(job.getInstanceId());
        if (profile != null) {
            jobInstanceId = profile.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.AutoScaleVmGroup) {
        AutoScaleVmGroupVO group = ApiDBUtils.findAutoScaleVmGroupById(job.getInstanceId());
        if (group != null) {
            jobInstanceId = group.getUuid();
        }
    } else if (jobInstanceType == ApiCommandJobType.Network) {
        NetworkVO networkVO = ApiDBUtils.findNetworkById(job.getInstanceId());
        if (networkVO != null) {
            jobInstanceId = networkVO.getUuid();
        }
    } else if (jobInstanceType != ApiCommandJobType.None) {
        // entity table mapping
        assert (false);
    }
    return jobInstanceId;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) AutoScalePolicyVO(com.cloud.network.as.AutoScalePolicyVO) VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ApiCommandJobType(org.apache.cloudstack.api.ApiCommandJobType) User(com.cloud.user.User) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) StaticRouteVO(com.cloud.network.vpc.StaticRouteVO) SecurityGroup(com.cloud.network.security.SecurityGroup) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) AutoScaleVmProfileVO(com.cloud.network.as.AutoScaleVmProfileVO) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) VolumeVO(com.cloud.storage.VolumeVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ConditionVO(com.cloud.network.as.ConditionVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) CounterVO(com.cloud.network.as.CounterVO)

Example 14 with PhysicalNetworkServiceProvider

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

the class VpcRouterDeploymentDefinition method findVirtualProvider.

@Override
protected void findVirtualProvider() {
    final List<? extends PhysicalNetwork> pNtwks = pNtwkDao.listByZone(vpc.getZoneId());
    for (final PhysicalNetwork pNtwk : pNtwks) {
        final PhysicalNetworkServiceProvider provider = physicalProviderDao.findByServiceProvider(pNtwk.getId(), Type.VPCVirtualRouter.toString());
        if (provider == null) {
            throw new CloudRuntimeException("Cannot find service provider " + Type.VPCVirtualRouter.toString() + " in physical network " + pNtwk.getId());
        }
        vrProvider = vrProviderDao.findByNspIdAndType(provider.getId(), Type.VPCVirtualRouter);
        if (vrProvider != null) {
            break;
        }
    }
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider)

Example 15 with PhysicalNetworkServiceProvider

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

the class ApiResponseHelper method createNetworkServiceProviderResponse.

@Override
public ProviderResponse createNetworkServiceProviderResponse(PhysicalNetworkServiceProvider result) {
    ProviderResponse response = new ProviderResponse();
    response.setId(result.getUuid());
    response.setName(result.getProviderName());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(result.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    PhysicalNetwork dnw = ApiDBUtils.findPhysicalNetworkById(result.getDestinationPhysicalNetworkId());
    if (dnw != null) {
        response.setDestinationPhysicalNetworkId(dnw.getUuid());
    }
    response.setState(result.getState().toString());
    // set enabled services
    List<String> services = new ArrayList<String>();
    for (Service service : result.getEnabledServices()) {
        services.add(service.getName());
    }
    response.setServices(services);
    Provider serviceProvider = Provider.getProvider(result.getProviderName());
    boolean canEnableIndividualServices = ApiDBUtils.canElementEnableIndividualServices(serviceProvider);
    response.setCanEnableIndividualServices(canEnableIndividualServices);
    response.setObjectName("networkserviceprovider");
    return response;
}
Also used : ProviderResponse(org.apache.cloudstack.api.response.ProviderResponse) VirtualRouterProviderResponse(org.apache.cloudstack.api.response.VirtualRouterProviderResponse) OvsProviderResponse(org.apache.cloudstack.api.response.OvsProviderResponse) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) UsageService(org.apache.cloudstack.usage.UsageService) OvsProvider(com.cloud.network.OvsProvider) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider)

Aggregations

PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)19 ArrayList (java.util.ArrayList)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ProviderResponse (org.apache.cloudstack.api.response.ProviderResponse)4 ProviderResponse (com.cloud.api.response.ProviderResponse)3 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)3 List (java.util.List)3 ServerApiException (com.cloud.api.ServerApiException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 TrafficType (com.cloud.network.Networks.TrafficType)2 PhysicalNetwork (com.cloud.network.PhysicalNetwork)2 Type (com.cloud.network.VirtualRouterProvider.Type)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 OvsProviderResponse (org.apache.cloudstack.api.response.OvsProviderResponse)2 VirtualRouterProviderResponse (org.apache.cloudstack.api.response.VirtualRouterProviderResponse)2 ListResponse (com.cloud.api.response.ListResponse)1 NetworkType (com.cloud.dc.DataCenter.NetworkType)1 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)1