Search in sources :

Example 76 with VlanVO

use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method checkRequestedIpAddresses.

@Override
public void checkRequestedIpAddresses(long networkId, IpAddresses ips) throws InvalidParameterValueException {
    final String ip4 = ips.getIp4Address();
    final String ip6 = ips.getIp6Address();
    final String mac = ips.getMacAddress();
    if (ip4 != null) {
        if (!NetUtils.isValidIp4(ip4)) {
            throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
        }
    // Other checks for ipv4 are done in assignPublicIpAddress()
    }
    if (ip6 != null) {
        if (!NetUtils.isValidIp6(ip6)) {
            throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
        }
        if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip6) != null) {
            throw new InvalidParameterValueException("The requested IP is already taken!");
        }
        final List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
        if (vlans == null) {
            throw new CloudRuntimeException("Cannot find related vlan attached to network " + networkId);
        }
        Vlan ipVlan = null;
        for (final Vlan vlan : vlans) {
            if (NetUtils.isIp6InRange(ip6, vlan.getIp6Range())) {
                ipVlan = vlan;
                break;
            }
        }
        if (ipVlan == null) {
            throw new InvalidParameterValueException("Requested IPv6 is not in the predefined range!");
        }
        if (mac != null) {
            if (!NetUtils.isValidMac(mac)) {
                throw new InvalidParameterValueException("Invalid specified MAC-Address " + mac);
            }
            if (_nicDao.findByNetworkIdAndMacAddress(networkId, mac) != null) {
                throw new InvalidParameterValueException("The requested MAC-Address is already taken! " + mac);
            }
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Vlan(com.cloud.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Example 77 with VlanVO

use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getStartIpv6Address.

@Override
public String getStartIpv6Address(final long networkId) {
    final List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
    if (vlans == null) {
        return null;
    }
    String startIpv6 = null;
    // Get the start ip of first create vlan(not the lowest, because if you add a lower vlan, lowest vlan would change)
    for (final Vlan vlan : vlans) {
        if (vlan.getIp6Range() != null) {
            startIpv6 = vlan.getIp6Range().split("-")[0];
            break;
        }
    }
    return startIpv6;
}
Also used : Vlan(com.cloud.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Example 78 with VlanVO

use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createIPAddressResponse.

@Override
public IPAddressResponse createIPAddressResponse(final ResponseView view, final IpAddress ipAddr) {
    final VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
    final boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
    final long zoneId = ipAddr.getDataCenterId();
    final IPAddressResponse ipResponse = new IPAddressResponse();
    ipResponse.setId(ipAddr.getUuid());
    ipResponse.setIpAddress(ipAddr.getAddress().toString());
    if (ipAddr.getAllocatedTime() != null) {
        ipResponse.setAllocated(ipAddr.getAllocatedTime());
    }
    final DataCenter zone = ApiDBUtils.findZoneById(ipAddr.getDataCenterId());
    if (zone != null) {
        ipResponse.setZoneId(zone.getUuid());
        ipResponse.setZoneName(zone.getName());
    }
    ipResponse.setSourceNat(ipAddr.isSourceNat());
    ipResponse.setIsSystem(ipAddr.getSystem());
    // get account information
    if (ipAddr.getAllocatedToAccountId() != null) {
        populateOwner(ipResponse, ipAddr);
    }
    ipResponse.setForVirtualNetwork(forVirtualNetworks);
    ipResponse.setStaticNat(ipAddr.isOneToOneNat());
    if (ipAddr.getAssociatedWithVmId() != null) {
        final UserVm vm = ApiDBUtils.findUserVmById(ipAddr.getAssociatedWithVmId());
        if (vm != null) {
            ipResponse.setVirtualMachineId(vm.getUuid());
            ipResponse.setVirtualMachineName(vm.getHostName());
            if (vm.getDisplayName() != null) {
                ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
            } else {
                ipResponse.setVirtualMachineDisplayName(vm.getHostName());
            }
        }
    }
    if (ipAddr.getVmIp() != null) {
        ipResponse.setVirtualMachineIp(ipAddr.getVmIp());
    }
    if (ipAddr.getAssociatedWithNetworkId() != null) {
        final Network ntwk = ApiDBUtils.findNetworkById(ipAddr.getAssociatedWithNetworkId());
        if (ntwk != null) {
            ipResponse.setAssociatedNetworkId(ntwk.getUuid());
            ipResponse.setAssociatedNetworkName(ntwk.getName());
        }
    }
    if (ipAddr.getVpcId() != null) {
        final Vpc vpc = ApiDBUtils.findVpcById(ipAddr.getVpcId());
        if (vpc != null) {
            ipResponse.setVpcId(vpc.getUuid());
        }
    }
    // Network id the ip is associated with (if associated networkId is
    // null, try to get this information from vlan)
    final Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId());
    // Network id the ip belongs to
    final Long networkId;
    if (vlanNetworkId != null) {
        networkId = vlanNetworkId;
    } else {
        networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
    }
    if (networkId != null) {
        final NetworkVO nw = ApiDBUtils.findNetworkById(networkId);
        if (nw != null) {
            ipResponse.setNetworkId(nw.getUuid());
            ipResponse.setAssociatedNetworkName(nw.getName());
        }
    }
    ipResponse.setState(ipAddr.getState().toString());
    final NetworkACL acl = ApiDBUtils.findByNetworkACLId(ipAddr.getIpACLId());
    if (acl != null) {
        ipResponse.setAclId(acl.getUuid());
        ipResponse.setAclName(acl.getName());
    }
    if (ipAddr.getPhysicalNetworkId() != null) {
        final PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
        if (pnw != null) {
            ipResponse.setPhysicalNetworkId(pnw.getUuid());
        }
    }
    // show this info to full view only
    if (view == ResponseView.Full) {
        final VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
        if (vl != null) {
            ipResponse.setVlanId(vl.getUuid());
            ipResponse.setVlanName(vl.getVlanTag());
        }
    }
    if (ipAddr.getSystem()) {
        if (ipAddr.isOneToOneNat()) {
            ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString());
        } else {
            ipResponse.setPurpose(IpAddress.Purpose.Lb.toString());
        }
    }
    ipResponse.setForDisplay(ipAddr.isDisplay());
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PublicIpAddress, ipAddr.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    ipResponse.setTags(tagResponses);
    ipResponse.setObjectName("ipaddress");
    return ipResponse;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) NetworkACL(com.cloud.network.vpc.NetworkACL) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) VlanVO(com.cloud.dc.VlanVO) IPAddressResponse(com.cloud.api.response.IPAddressResponse)

Example 79 with VlanVO

use of com.cloud.dc.VlanVO in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method deleteVlansInNetwork.

protected boolean deleteVlansInNetwork(final long networkId, final long userId, final Account callerAccount) {
    // cleanup Public vlans
    final List<VlanVO> publicVlans = _vlanDao.listVlansByNetworkId(networkId);
    boolean result = true;
    for (final VlanVO vlan : publicVlans) {
        if (!_configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId(), callerAccount)) {
            s_logger.warn("Failed to delete vlan " + vlan.getId() + ");");
            result = false;
        }
    }
    // cleanup private vlans
    final int privateIpAllocCount = _privateIpDao.countAllocatedByNetworkId(networkId);
    if (privateIpAllocCount > 0) {
        s_logger.warn("Can't delete Private ip range for network " + networkId + " as it has allocated ip addresses");
        result = false;
    } else {
        _privateIpDao.deleteByNetworkId(networkId);
        s_logger.debug("Deleted ip range for private network id=" + networkId);
    }
    return result;
}
Also used : VlanVO(com.cloud.dc.VlanVO)

Example 80 with VlanVO

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

the class NetworkOrchestrator method deleteVlansInNetwork.

protected boolean deleteVlansInNetwork(final long networkId, final long userId, final Account callerAccount) {
    // cleanup Public vlans
    final List<VlanVO> publicVlans = _vlanDao.listVlansByNetworkId(networkId);
    boolean result = true;
    for (final VlanVO vlan : publicVlans) {
        if (!_configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId(), callerAccount)) {
            s_logger.warn("Failed to delete vlan " + vlan.getId() + ");");
            result = false;
        }
    }
    // cleanup private vlans
    final int privateIpAllocCount = _privateIpDao.countAllocatedByNetworkId(networkId);
    if (privateIpAllocCount > 0) {
        s_logger.warn("Can't delete Private ip range for network " + networkId + " as it has allocated ip addresses");
        result = false;
    } else {
        _privateIpDao.deleteByNetworkId(networkId);
        s_logger.debug("Deleted ip range for private network id=" + networkId);
    }
    return result;
}
Also used : VlanVO(com.cloud.dc.VlanVO)

Aggregations

VlanVO (com.cloud.dc.VlanVO)103 ArrayList (java.util.ArrayList)39 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 DB (com.cloud.utils.db.DB)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionStatus (com.cloud.utils.db.TransactionStatus)18 Network (com.cloud.network.Network)17 Account (com.cloud.user.Account)17 AccountVlanMapVO (com.cloud.dc.AccountVlanMapVO)15 List (java.util.List)15 DomainVlanMapVO (com.cloud.dc.DomainVlanMapVO)12 ActionEvent (com.cloud.event.ActionEvent)12 HostVO (com.cloud.host.HostVO)12 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)12 Vlan (com.cloud.dc.Vlan)11 NetworkVO (com.cloud.network.dao.NetworkVO)11 DataCenter (com.cloud.dc.DataCenter)10 DataCenterVO (com.cloud.dc.DataCenterVO)10 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)10