Search in sources :

Example 6 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)

Example 7 with DataCenter

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

the class NetworkServiceImpl method updatePhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_UPDATE, eventDescription = "updating physical network", async = true)
public PhysicalNetwork updatePhysicalNetwork(final Long id, final String networkSpeed, final List<String> tags, final String newVnetRange, final String state) {
    // verify input parameters
    final PhysicalNetworkVO network = _physicalNetworkDao.findById(id);
    if (network == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
        ex.addProxyObject(id.toString(), "physicalNetworkId");
        throw ex;
    }
    // if zone is of Basic type, don't allow to add vnet range
    final DataCenter zone = _dcDao.findById(network.getDataCenterId());
    if (zone == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Zone with id=" + network.getDataCenterId() + " doesn't exist in the system");
        ex.addProxyObject(String.valueOf(network.getDataCenterId()), "dataCenterId");
        throw ex;
    }
    if (newVnetRange != null) {
        if (zone.getNetworkType() == NetworkType.Basic) {
            throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zone.getNetworkType() + " network");
        }
    }
    if (tags != null && tags.size() > 1) {
        throw new InvalidParameterException("Unable to support more than one tag on network yet");
    }
    PhysicalNetwork.State networkState = null;
    if (state != null && !state.isEmpty()) {
        try {
            networkState = PhysicalNetwork.State.valueOf(state);
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve state '" + state + "' to a supported value {Enabled or Disabled}");
        }
    }
    if (state != null) {
        network.setState(networkState);
    }
    if (tags != null) {
        network.setTags(tags);
    }
    if (networkSpeed != null) {
        network.setSpeed(networkSpeed);
    }
    if (newVnetRange != null) {
        final String[] listOfRanges = newVnetRange.split(",");
        addOrRemoveVnets(listOfRanges, network);
    }
    _physicalNetworkDao.update(id, network);
    return network;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) DataCenter(com.cloud.legacymodel.dc.DataCenter) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 8 with DataCenter

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

the class NetworkServiceImpl method allocateIP.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true)
public IpAddress allocateIP(final Account ipOwner, final long zoneId, final Long networkId, final Boolean displayIp) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final long callerUserId = CallContext.current().getCallingUserId();
    final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
    if (networkId != null) {
        final Network network = _networksDao.findById(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Invalid network id is given");
        }
        if (network.getGuestType() == GuestType.Shared) {
            if (zone == null) {
                throw new InvalidParameterValueException("Invalid zone Id is given");
            }
            // if shared network in the advanced zone, then check the caller against the network for 'AccessType.UseNetwork'
            if (zone.getNetworkType() == NetworkType.Advanced) {
                if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
                    _accountMgr.checkAccess(caller, AccessType.UseEntry, false, network);
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Associate IP address called by the user " + callerUserId + " account " + ipOwner.getId());
                    }
                    return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp);
                } else {
                    throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" + " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
                }
            }
        }
    } else {
        _accountMgr.checkAccess(caller, null, false, ipOwner);
    }
    return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone, displayIp);
}
Also used : Account(com.cloud.legacymodel.user.Account) DataCenter(com.cloud.legacymodel.dc.DataCenter) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Network(com.cloud.legacymodel.network.Network) ActionEvent(com.cloud.event.ActionEvent)

Example 9 with DataCenter

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

the class GuestNetworkGuru 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 10 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)

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