Search in sources :

Example 11 with DomainVlanMapVO

use of com.cloud.dc.DomainVlanMapVO in project cloudstack by apache.

the class ConfigurationManagerImpl method getVlanDomain.

@Override
public Domain getVlanDomain(long vlanId) {
    Vlan vlan = _vlanDao.findById(vlanId);
    Long domainId = null;
    // from the network
    if (vlan.getVlanType() == VlanType.VirtualNetwork) {
        List<DomainVlanMapVO> maps = _domainVlanMapDao.listDomainVlanMapsByVlan(vlanId);
        if (maps != null && !maps.isEmpty()) {
            return _domainDao.findById(maps.get(0).getDomainId());
        }
    }
    return null;
}
Also used : Vlan(com.cloud.dc.Vlan) DomainVlanMapVO(com.cloud.dc.DomainVlanMapVO)

Example 12 with DomainVlanMapVO

use of com.cloud.dc.DomainVlanMapVO in project cloudstack by apache.

the class ConfigurationManagerImpl method updateVlanAndPublicIpRange.

@DB
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_UPDATE, eventDescription = "update vlan ip Range", async = false)
public Vlan updateVlanAndPublicIpRange(final long id, String startIp, String endIp, String gateway, String netmask, String startIpv6, String endIpv6, String ip6Gateway, String ip6Cidr, Boolean forSystemVms) throws ConcurrentOperationException {
    VlanVO vlanRange = _vlanDao.findById(id);
    if (vlanRange == null) {
        throw new InvalidParameterValueException("Please specify a valid IP range id.");
    }
    final boolean ipv4 = vlanRange.getVlanGateway() != null;
    final boolean ipv6 = vlanRange.getIp6Gateway() != null;
    if (!ipv4) {
        if (startIp != null || endIp != null || gateway != null || netmask != null) {
            throw new InvalidParameterValueException("IPv4 is not support in this IP range.");
        }
    }
    if (!ipv6) {
        if (startIpv6 != null || endIpv6 != null || ip6Gateway != null || ip6Cidr != null) {
            throw new InvalidParameterValueException("IPv6 is not support in this IP range.");
        }
    }
    final Boolean isRangeForSystemVM = checkIfVlanRangeIsForSystemVM(id);
    if (forSystemVms != null && isRangeForSystemVM != forSystemVms) {
        if (VlanType.DirectAttached.equals(vlanRange.getVlanType())) {
            throw new InvalidParameterValueException("forSystemVms is not available for this IP range with vlan type: " + VlanType.DirectAttached);
        }
        // Check if range has already been dedicated
        final List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByVlan(id);
        if (maps != null && !maps.isEmpty()) {
            throw new InvalidParameterValueException("Specified Public IP range has already been dedicated to an account");
        }
        List<DomainVlanMapVO> domainmaps = _domainVlanMapDao.listDomainVlanMapsByVlan(id);
        if (domainmaps != null && !domainmaps.isEmpty()) {
            throw new InvalidParameterValueException("Specified Public IP range has already been dedicated to a domain");
        }
    }
    if (ipv4) {
        updateVlanAndIpv4Range(id, vlanRange, startIp, endIp, gateway, netmask, isRangeForSystemVM, forSystemVms);
    }
    if (ipv6) {
        updateVlanAndIpv6Range(id, vlanRange, startIpv6, endIpv6, ip6Gateway, ip6Cidr, isRangeForSystemVM, forSystemVms);
    }
    return _vlanDao.findById(id);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AccountVlanMapVO(com.cloud.dc.AccountVlanMapVO) VlanVO(com.cloud.dc.VlanVO) DomainVlanMapVO(com.cloud.dc.DomainVlanMapVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 13 with DomainVlanMapVO

use of com.cloud.dc.DomainVlanMapVO in project cloudstack by apache.

the class ConfigurationManagerImpl method dedicatePublicIpRange.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DEDICATE, eventDescription = "dedicating vlan ip range", async = false)
public Vlan dedicatePublicIpRange(final DedicatePublicIpRangeCmd cmd) throws ResourceAllocationException {
    final Long vlanDbId = cmd.getId();
    final String accountName = cmd.getAccountName();
    final Long domainId = cmd.getDomainId();
    final Long projectId = cmd.getProjectId();
    // Check if account is valid
    Account vlanOwner = null;
    if (projectId != null) {
        if (accountName != null) {
            throw new InvalidParameterValueException("accountName and projectId are mutually exclusive");
        }
        final Project project = _projectMgr.getProject(projectId);
        if (project == null) {
            throw new InvalidParameterValueException("Unable to find project by id " + projectId);
        }
        vlanOwner = _accountMgr.getAccount(project.getProjectAccountId());
        if (vlanOwner == null) {
            throw new InvalidParameterValueException("Please specify a valid projectId");
        }
    }
    Domain domain = null;
    if (accountName != null && domainId != null) {
        vlanOwner = _accountDao.findActiveAccount(accountName, domainId);
        if (vlanOwner == null) {
            throw new InvalidParameterValueException("Unable to find account by name " + accountName);
        } else if (vlanOwner.getId() == Account.ACCOUNT_ID_SYSTEM) {
            throw new InvalidParameterValueException("Please specify a valid account. Cannot dedicate IP range to system account");
        }
    } else if (domainId != null) {
        domain = _domainDao.findById(domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Please specify a valid domain id");
        }
    }
    // Check if range is valid
    final VlanVO vlan = _vlanDao.findById(vlanDbId);
    if (vlan == null) {
        throw new InvalidParameterValueException("Unable to find vlan by id " + vlanDbId);
    }
    // Check if range has already been dedicated
    final List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByVlan(vlanDbId);
    if (maps != null && !maps.isEmpty()) {
        throw new InvalidParameterValueException("Specified Public IP range has already been dedicated");
    }
    List<DomainVlanMapVO> domainmaps = _domainVlanMapDao.listDomainVlanMapsByVlan(vlanDbId);
    if (domainmaps != null && !domainmaps.isEmpty()) {
        throw new InvalidParameterValueException("Specified Public IP range has already been dedicated to a domain");
    }
    // Verify that zone exists and is advanced
    final Long zoneId = vlan.getDataCenterId();
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Unable to find zone by id " + zoneId);
    }
    if (zone.getNetworkType() == NetworkType.Basic) {
        throw new InvalidParameterValueException("Public IP range can be dedicated to an account only in the zone of type " + NetworkType.Advanced);
    }
    // Check Public IP resource limits
    if (vlanOwner != null) {
        final int accountPublicIpRange = _publicIpAddressDao.countIPs(zoneId, vlanDbId, false);
        _resourceLimitMgr.checkResourceLimit(vlanOwner, ResourceType.public_ip, accountPublicIpRange);
    }
    // Check if any of the Public IP addresses is allocated to another
    // account
    boolean forSystemVms = false;
    final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlanDbId);
    for (final IPAddressVO ip : ips) {
        forSystemVms = ip.isForSystemVms();
        final Long allocatedToAccountId = ip.getAllocatedToAccountId();
        if (allocatedToAccountId != null) {
            if (vlanOwner != null && allocatedToAccountId != vlanOwner.getId()) {
                throw new InvalidParameterValueException(ip.getAddress() + " Public IP address in range is allocated to another account ");
            }
            final Account accountAllocatedTo = _accountMgr.getActiveAccountById(allocatedToAccountId);
            if (vlanOwner == null && domain != null && domain.getId() != accountAllocatedTo.getDomainId()) {
                throw new InvalidParameterValueException(ip.getAddress() + " Public IP address in range is allocated to another domain/account ");
            }
        }
    }
    if (vlanOwner != null) {
        // Create an AccountVlanMapVO entry
        final AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(vlanOwner.getId(), vlan.getId());
        _accountVlanMapDao.persist(accountVlanMapVO);
        // generate usage event for dedication of every ip address in the range
        for (final IPAddressVO ip : ips) {
            final boolean usageHidden = _ipAddrMgr.isUsageHidden(ip);
            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), ip.getSystem(), usageHidden, ip.getClass().getName(), ip.getUuid());
        }
    } else if (domain != null && !forSystemVms) {
        // Create an DomainVlanMapVO entry
        DomainVlanMapVO domainVlanMapVO = new DomainVlanMapVO(domain.getId(), vlan.getId());
        _domainVlanMapDao.persist(domainVlanMapVO);
    }
    // increment resource count for dedicated public ip's
    if (vlanOwner != null) {
        _resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip, new Long(ips.size()));
    }
    return vlan;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) AccountVlanMapVO(com.cloud.dc.AccountVlanMapVO) DomainVlanMapVO(com.cloud.dc.DomainVlanMapVO) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) IPAddressVO(com.cloud.network.dao.IPAddressVO) Domain(com.cloud.domain.Domain) VlanVO(com.cloud.dc.VlanVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

DomainVlanMapVO (com.cloud.dc.DomainVlanMapVO)13 AccountVlanMapVO (com.cloud.dc.AccountVlanMapVO)12 VlanVO (com.cloud.dc.VlanVO)12 IPAddressVO (com.cloud.network.dao.IPAddressVO)9 DB (com.cloud.utils.db.DB)8 ArrayList (java.util.ArrayList)7 TransactionStatus (com.cloud.utils.db.TransactionStatus)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 List (java.util.List)5 PodVlanMapVO (com.cloud.dc.PodVlanMapVO)3 ActionEvent (com.cloud.event.ActionEvent)3 Project (com.cloud.projects.Project)3 Account (com.cloud.user.Account)3 Filter (com.cloud.utils.db.Filter)3 SearchCriteria (com.cloud.utils.db.SearchCriteria)3 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 DataCenter (com.cloud.dc.DataCenter)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 Pod (com.cloud.dc.Pod)2