Search in sources :

Example 1 with NetworkGuruAdditionalFunctions

use of com.cloud.network.guru.NetworkGuruAdditionalFunctions in project cloudstack by apache.

the class NetworkOrchestrator method listVmNics.

@Override
public List<? extends Nic> listVmNics(final long vmId, final Long nicId, final Long networkId) {
    List<NicVO> result = null;
    if (nicId == null && networkId == null) {
        result = _nicDao.listByVmId(vmId);
    } else {
        result = _nicDao.listByVmIdAndNicIdAndNtwkId(vmId, nicId, networkId);
    }
    for (final NicVO nic : result) {
        if (_networkModel.isProviderForNetwork(Provider.NiciraNvp, nic.getNetworkId())) {
            //For NSX Based networks, add nsxlogicalswitch, nsxlogicalswitchport to each result
            s_logger.info("Listing NSX logical switch and logical switch por for each nic");
            final NetworkVO network = _networksDao.findById(nic.getNetworkId());
            final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
            final NetworkGuruAdditionalFunctions guruFunctions = (NetworkGuruAdditionalFunctions) guru;
            final Map<String, ? extends Object> nsxParams = guruFunctions.listAdditionalNicParams(nic.getUuid());
            if (nsxParams != null) {
                final String lswitchUuuid = nsxParams.containsKey(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID) ? (String) nsxParams.get(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID) : null;
                final String lswitchPortUuuid = nsxParams.containsKey(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID) ? (String) nsxParams.get(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID) : null;
                nic.setNsxLogicalSwitchUuid(lswitchUuuid);
                nic.setNsxLogicalSwitchPortUuid(lswitchPortUuuid);
            }
        }
    }
    return result;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicVO(com.cloud.vm.NicVO) NetworkGuruAdditionalFunctions(com.cloud.network.guru.NetworkGuruAdditionalFunctions)

Example 2 with NetworkGuruAdditionalFunctions

use of com.cloud.network.guru.NetworkGuruAdditionalFunctions in project cloudstack by apache.

the class NetworkOrchestrator method setupNetwork.

@Override
@DB
public List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final Network predefined, final DeploymentPlan plan, final String name, final String displayText, final boolean errorIfAlreadySetup, final Long domainId, final ACLType aclType, final Boolean subdomainAccess, final Long vpcId, final Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException {
    final Account locked = _accountDao.acquireInLockTable(owner.getId());
    if (locked == null) {
        throw new ConcurrentOperationException("Unable to acquire lock on " + owner);
    }
    try {
        if (predefined == null || offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && !(predefined.getBroadcastDomainType() == BroadcastDomainType.Vlan || predefined.getBroadcastDomainType() == BroadcastDomainType.Lswitch || predefined.getBroadcastDomainType() == BroadcastDomainType.Vxlan)) {
            final List<NetworkVO> configs = _networksDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId());
            if (configs.size() > 0) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found existing network configuration for offering " + offering + ": " + configs.get(0));
                }
                if (errorIfAlreadySetup) {
                    final InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)");
                    ex.addProxyObject(offering.getUuid(), "offeringId");
                    ex.addProxyObject(configs.get(0).getUuid(), "networkConfigId");
                    throw ex;
                } else {
                    return configs;
                }
            }
        }
        final List<NetworkVO> networks = new ArrayList<NetworkVO>();
        long related = -1;
        for (final NetworkGuru guru : networkGurus) {
            final Network network = guru.design(offering, plan, predefined, owner);
            if (network == null) {
                continue;
            }
            if (network.getId() != -1) {
                if (network instanceof NetworkVO) {
                    networks.add((NetworkVO) network);
                } else {
                    networks.add(_networksDao.findById(network.getId()));
                }
                continue;
            }
            final long id = _networksDao.getNextInSequence(Long.class, "id");
            if (related == -1) {
                related = id;
            }
            final long relatedFile = related;
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    final NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), relatedFile, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId, offering.getRedundantRouter());
                    vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
                    vo.setStrechedL2Network(offering.getSupportsStrechedL2());
                    final NetworkVO networkPersisted = _networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()));
                    networks.add(networkPersisted);
                    if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions) {
                        final NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru;
                        functions.finalizeNetworkDesign(networkPersisted.getId(), ((NetworkVO) predefined).getVlanIdAsUUID());
                    }
                    if (domainId != null && aclType == ACLType.Domain) {
                        _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess);
                    }
                }
            });
        }
        if (networks.size() < 1) {
            // see networkOfferingVO.java
            final CloudRuntimeException ex = new CloudRuntimeException("Unable to convert network offering with specified id to network profile");
            ex.addProxyObject(offering.getUuid(), "offeringId");
            throw ex;
        }
        return networks;
    } finally {
        s_logger.debug("Releasing lock for " + locked);
        _accountDao.releaseFromLockTable(locked.getId());
    }
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) ArrayList(java.util.ArrayList) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkGuruAdditionalFunctions(com.cloud.network.guru.NetworkGuruAdditionalFunctions) DB(com.cloud.utils.db.DB)

Aggregations

NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NetworkGuru (com.cloud.network.guru.NetworkGuru)2 NetworkGuruAdditionalFunctions (com.cloud.network.guru.NetworkGuruAdditionalFunctions)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 Account (com.cloud.user.Account)1 DB (com.cloud.utils.db.DB)1 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NicVO (com.cloud.vm.NicVO)1 ArrayList (java.util.ArrayList)1