Search in sources :

Example 21 with DataCenter

use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createPhysicalNetworkResponse.

@Override
public PhysicalNetworkResponse createPhysicalNetworkResponse(final PhysicalNetwork result) {
    final PhysicalNetworkResponse response = new PhysicalNetworkResponse();
    final DataCenter zone = ApiDBUtils.findZoneById(result.getDataCenterId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
    }
    response.setNetworkSpeed(result.getSpeed());
    response.setVlan(result.getVnetString());
    if (result.getDomainId() != null) {
        final Domain domain = ApiDBUtils.findDomainById(result.getDomainId());
        if (domain != null) {
            response.setDomainId(domain.getUuid());
        }
    }
    response.setId(result.getUuid());
    if (result.getBroadcastDomainRange() != null) {
        response.setBroadcastDomainRange(result.getBroadcastDomainRange().toString());
    }
    response.setIsolationMethods(result.getIsolationMethods());
    response.setTags(result.getTags());
    if (result.getState() != null) {
        response.setState(result.getState().toString());
    }
    response.setName(result.getName());
    response.setObjectName("physicalnetwork");
    return response;
}
Also used : DataCenter(com.cloud.legacymodel.dc.DataCenter) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) Domain(com.cloud.legacymodel.domain.Domain)

Example 22 with DataCenter

use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.

the class PrivateNetworkGuru method design.

@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
    final PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    final DataCenter dc = _entityMgr.findById(DataCenter.class, plan.getDataCenterId());
    if (!canHandle(offering, dc, physnet)) {
        return null;
    }
    final BroadcastDomainType broadcastType;
    if (userSpecified != null && userSpecified.getBroadcastDomainType() != null) {
        broadcastType = userSpecified.getBroadcastDomainType();
    } else {
        broadcastType = BroadcastDomainType.Vlan;
    }
    final NetworkVO network = new NetworkVO(offering.getTrafficType(), DHCPMode.Static, broadcastType, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
    if (userSpecified != null) {
        if (!GuestType.Private.equals(offering.getGuestType()) && ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null))) {
            throw new InvalidParameterValueException("CIDR and gateway must be specified together or the CIDR must represents the gateway.");
        }
        if (userSpecified.getCidr() != null) {
            network.setCidr(userSpecified.getCidr());
            network.setGateway(userSpecified.getGateway());
        } else {
            throw new InvalidParameterValueException("Can't design network " + network + "; netmask/gateway or cidr must be passed in");
        }
        if (offering.getSpecifyVlan()) {
            network.setBroadcastUri(userSpecified.getBroadcastUri());
            network.setState(State.Setup);
        }
    } else {
        throw new CloudRuntimeException("Can't design network " + network + "; netmask/gateway or cidr must be passed in");
    }
    return network;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.legacymodel.dc.DataCenter) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 23 with DataCenter

use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.

the class PublicNetworkGuru method updateNicProfile.

@Override
public void updateNicProfile(final NicProfile profile, final Network network) {
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    if (profile != null) {
        profile.setIPv4Dns1(dc.getDns1());
        profile.setIPv4Dns2(dc.getDns2());
    }
}
Also used : DataCenter(com.cloud.legacymodel.dc.DataCenter)

Example 24 with DataCenter

use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.

the class DirectNetworkGuru method design.

@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
    final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc)) {
        return null;
    }
    State state = State.Allocated;
    if (dc.getNetworkType() == NetworkType.Basic) {
        state = State.Setup;
    }
    final NetworkVO config = new NetworkVO(offering.getTrafficType(), DHCPMode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), state, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
    if (userSpecified != null) {
        if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
            throw new InvalidParameterValueException("CIDR and gateway must be specified together or the CIDR must represents the gateway.");
        }
        if ((userSpecified.getIp6Cidr() == null && userSpecified.getIp6Gateway() != null) || (userSpecified.getIp6Cidr() != null && userSpecified.getIp6Gateway() == null)) {
            throw new InvalidParameterValueException("CIDRv6 and gatewayv6 must be specified together or the CIDRv6 must represents the gateway.");
        }
        if (userSpecified.getCidr() != null) {
            config.setCidr(userSpecified.getCidr());
            config.setGateway(userSpecified.getGateway());
        }
        if (userSpecified.getIp6Cidr() != null) {
            config.setIp6Cidr(userSpecified.getIp6Cidr());
            config.setIp6Gateway(userSpecified.getIp6Gateway());
        }
        if (userSpecified.getBroadcastUri() != null) {
            config.setBroadcastUri(userSpecified.getBroadcastUri());
            config.setState(State.Setup);
        }
        if (userSpecified.getBroadcastDomainType() != null) {
            config.setBroadcastDomainType(userSpecified.getBroadcastDomainType());
        }
    }
    return config;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.legacymodel.dc.DataCenter) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) State(com.cloud.legacymodel.network.Network.State)

Example 25 with DataCenter

use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.

the class DirectPodBasedNetworkGuru method getIp.

@DB
protected void getIp(final NicProfile nic, final Pod pod, final VirtualMachineProfile vm, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final DataCenter dc = _dcDao.findById(pod.getDataCenterId());
    if (nic.getIPv4Address() == null) {
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientAddressCapacityException>() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientAddressCapacityException {
                PublicIp ip = null;
                final List<PodVlanMapVO> podRefs = _podVlanDao.listPodVlanMapsByPod(pod.getId());
                String podRangeGateway = null;
                if (!podRefs.isEmpty()) {
                    podRangeGateway = _vlanDao.findById(podRefs.get(0).getVlanDbId()).getVlanGateway();
                }
                // Get ip address from the placeholder and don't allocate a new one
                if (vm.getType() == VirtualMachineType.DomainRouter) {
                    final Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
                    if (placeholderNic != null) {
                        final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIPv4Address());
                        ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                        s_logger.debug("Nic got an ip address " + placeholderNic.getIPv4Address() + " stored in placeholder nic for the network " + network + " and gateway " + podRangeGateway);
                    }
                }
                if (ip == null) {
                    ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
                }
                nic.setIPv4Address(ip.getAddress().toString());
                nic.setFormat(IpAddressFormat.Ip4);
                nic.setIPv4Gateway(ip.getGateway());
                nic.setIPv4Netmask(ip.getNetmask());
                if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) {
                    nic.setIsolationUri(IsolationType.Ec2.toUri(Vlan.UNTAGGED));
                    nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED));
                    nic.setBroadcastType(BroadcastDomainType.Native);
                }
                nic.setReservationId(String.valueOf(ip.getVlanTag()));
                nic.setMacAddress(ip.getMacAddress());
                // save the placeholder nic if the vm is the Virtual router
                if (vm.getType() == VirtualMachineType.DomainRouter) {
                    final Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
                    if (placeholderNic == null) {
                        s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIPv4Address() + " for the network " + network);
                        _networkMgr.savePlaceholderNic(network, nic.getIPv4Address(), null, VirtualMachineType.DomainRouter);
                    }
                }
            }
        });
    }
    nic.setIPv4Dns1(dc.getDns1());
    nic.setIPv4Dns2(dc.getDns2());
}
Also used : DataCenter(com.cloud.legacymodel.dc.DataCenter) PublicIp(com.cloud.network.addr.PublicIp) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Nic(com.cloud.legacymodel.network.Nic) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO) DB(com.cloud.utils.db.DB)

Aggregations

DataCenter (com.cloud.legacymodel.dc.DataCenter)50 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)17 Network (com.cloud.legacymodel.network.Network)15 Account (com.cloud.legacymodel.user.Account)14 ArrayList (java.util.ArrayList)11 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)8 DB (com.cloud.utils.db.DB)8 ActionEvent (com.cloud.event.ActionEvent)7 PhysicalNetwork (com.cloud.network.PhysicalNetwork)7 NetworkVO (com.cloud.network.dao.NetworkVO)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)6 TransactionStatus (com.cloud.utils.db.TransactionStatus)6 HashSet (java.util.HashSet)6 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)5 HostPodVO (com.cloud.dc.HostPodVO)5 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)5 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)5 Vpc (com.cloud.legacymodel.network.vpc.Vpc)5 NetworkOffering (com.cloud.offering.NetworkOffering)5