Search in sources :

Example 16 with Vlan

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

the class ConfigurationManagerImpl method commitVlan.

private Vlan commitVlan(final Long zoneId, final Long podId, final String startIP, final String endIP, final String newVlanGatewayFinal, final String newVlanNetmaskFinal, final String vlanId, final Boolean forVirtualNetwork, final Long networkId, final Long physicalNetworkId, final String startIPv6, final String endIPv6, final String ip6Gateway, final String ip6Cidr, final Domain domain, final Account vlanOwner, final Network network, final Pair<Boolean, Pair<String, String>> sameSubnet) {
    return Transaction.execute(new TransactionCallback<Vlan>() {

        @Override
        public Vlan doInTransaction(final TransactionStatus status) {
            String newVlanNetmask = newVlanNetmaskFinal;
            String newVlanGateway = newVlanGatewayFinal;
            if ((sameSubnet == null || !sameSubnet.first()) && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared && _vlanDao.listVlansByNetworkId(networkId) != null) {
                final Map<Capability, String> dhcpCapabilities = _networkSvc.getNetworkOfferingServiceCapabilities(_networkOfferingDao.findById(network.getNetworkOfferingId()), Service.Dhcp);
                final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
                if (supportsMultipleSubnets == null || !Boolean.valueOf(supportsMultipleSubnets)) {
                    throw new InvalidParameterValueException("The dhcp service provider for this network does not support dhcp across multiple subnets");
                }
                s_logger.info("adding a new subnet to the network " + network.getId());
            } else if (sameSubnet != null) {
                // if it is same subnet the user might not send the vlan and the
                // netmask details. so we are
                // figuring out while validation and setting them here.
                newVlanGateway = sameSubnet.second().first();
                newVlanNetmask = sameSubnet.second().second();
            }
            final Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, newVlanGateway, newVlanNetmask, vlanId, domain, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
            // gateway that will be configured on the corresponding routervm.
            return vlan;
        }
    });
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Vlan(com.cloud.dc.Vlan) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 with Vlan

use of com.cloud.dc.Vlan 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 18 with Vlan

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

the class ApiResponseHelper method createSystemVmResponse.

@Override
public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
    SystemVmResponse vmResponse = new SystemVmResponse();
    if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy || vm.getType() == Type.DomainRouter) {
        // SystemVm vm = (SystemVm) systemVM;
        vmResponse.setId(vm.getUuid());
        // vmResponse.setObjectId(vm.getId());
        vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
        vmResponse.setName(vm.getHostName());
        if (vm.getPodIdToDeployIn() != null) {
            HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
            if (pod != null) {
                vmResponse.setPodId(pod.getUuid());
            }
        }
        VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
        if (template != null) {
            vmResponse.setTemplateId(template.getUuid());
        }
        vmResponse.setCreated(vm.getCreated());
        if (vm.getHostId() != null) {
            Host host = ApiDBUtils.findHostById(vm.getHostId());
            if (host != null) {
                vmResponse.setHostId(host.getUuid());
                vmResponse.setHostName(host.getName());
                vmResponse.setHypervisor(host.getHypervisorType().toString());
            }
        }
        if (vm.getState() != null) {
            vmResponse.setState(vm.getState().toString());
        }
        // for console proxies, add the active sessions
        if (vm.getType() == Type.ConsoleProxy) {
            ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
            // proxy can be already destroyed
            if (proxy != null) {
                vmResponse.setActiveViewerSessions(proxy.getActiveSession());
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(vm.getDataCenterId());
        if (zone != null) {
            vmResponse.setZoneId(zone.getUuid());
            vmResponse.setZoneName(zone.getName());
            vmResponse.setDns1(zone.getDns1());
            vmResponse.setDns2(zone.getDns2());
        }
        List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
        for (NicProfile singleNicProfile : nicProfiles) {
            Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
            if (network != null) {
                if (network.getTrafficType() == TrafficType.Management) {
                    vmResponse.setPrivateIp(singleNicProfile.getIPv4Address());
                    vmResponse.setPrivateMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setPrivateNetmask(singleNicProfile.getIPv4Netmask());
                } else if (network.getTrafficType() == TrafficType.Control) {
                    vmResponse.setLinkLocalIp(singleNicProfile.getIPv4Address());
                    vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setLinkLocalNetmask(singleNicProfile.getIPv4Netmask());
                } else if (network.getTrafficType() == TrafficType.Public) {
                    vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
                    vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
                    vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
                } else if (network.getTrafficType() == TrafficType.Guest) {
                    /*
                          * In basic zone, public ip has TrafficType.Guest in case EIP service is not enabled.
                          * When EIP service is enabled in the basic zone, system VM by default get the public
                          * IP allocated for EIP. So return the guest/public IP accordingly.
                          * */
                    NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
                    if (networkOffering.getElasticIp()) {
                        IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
                        if (ip != null) {
                            Vlan vlan = ApiDBUtils.findVlanById(ip.getVlanId());
                            vmResponse.setPublicIp(ip.getAddress().addr());
                            vmResponse.setPublicNetmask(vlan.getVlanNetmask());
                            vmResponse.setGateway(vlan.getVlanGateway());
                        }
                    } else {
                        vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
                        vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
                        vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
                        vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
                    }
                }
            }
        }
    }
    vmResponse.setObjectName("systemvm");
    return vmResponse;
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VMTemplateVO(com.cloud.storage.VMTemplateVO) Host(com.cloud.host.Host) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) IpAddress(com.cloud.network.IpAddress) Vlan(com.cloud.dc.Vlan) GuestVlan(com.cloud.network.GuestVlan) NicProfile(com.cloud.vm.NicProfile) HostPodVO(com.cloud.dc.HostPodVO)

Example 19 with Vlan

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

the class NetworkModelImpl method checkRequestedIpAddresses.

@Override
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6) throws InvalidParameterValueException {
    if (ip4 != null) {
        if (!NetUtils.isValidIp(ip4)) {
            throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
        }
    //Other checks for ipv4 are done in assignPublicIpAddress()
    }
    if (ip6 != null) {
        if (!NetUtils.isValidIpv6(ip6)) {
            throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
        }
        if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip6) != null) {
            throw new InvalidParameterValueException("The requested IP is already taken!");
        }
        List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
        if (vlans == null) {
            throw new CloudRuntimeException("Cannot find related vlan attached to network " + networkId);
        }
        Vlan ipVlan = null;
        for (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!");
        }
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Vlan(com.cloud.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Example 20 with Vlan

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

the class ExternalFirewallDeviceManagerImpl method applyPortForwardingRules.

@Override
public boolean applyPortForwardingRules(Network network, List<? extends PortForwardingRule> rules) throws ResourceUnavailableException {
    // Find the external firewall in this zone
    long zoneId = network.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    ExternalFirewallDeviceVO fwDeviceVO = getExternalFirewallForNetwork(network);
    HostVO externalFirewall = _hostDao.findById(fwDeviceVO.getHostId());
    assert (externalFirewall != null);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External firewall was asked to apply firewall rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return true;
    }
    List<PortForwardingRuleTO> pfRules = new ArrayList<PortForwardingRuleTO>();
    for (PortForwardingRule rule : rules) {
        IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
        PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        pfRules.add(ruleTO);
    }
    sendPortForwardingRules(pfRules, zone, externalFirewall.getId());
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ExternalFirewallDeviceVO(com.cloud.network.dao.ExternalFirewallDeviceVO) PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) HostVO(com.cloud.host.HostVO)

Aggregations

Vlan (com.cloud.dc.Vlan)22 ArrayList (java.util.ArrayList)10 HostVO (com.cloud.host.HostVO)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 VlanVO (com.cloud.dc.VlanVO)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)3 IpAddress (com.cloud.network.IpAddress)3 ExternalFirewallDeviceVO (com.cloud.network.dao.ExternalFirewallDeviceVO)3 PortForwardingRule (com.cloud.network.rules.PortForwardingRule)3 VlanIpRangeResponse (org.apache.cloudstack.api.response.VlanIpRangeResponse)3 Answer (com.cloud.agent.api.Answer)2 VlanIpRangeResponse (com.cloud.api.response.VlanIpRangeResponse)2 HostPodVO (com.cloud.dc.HostPodVO)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2 List (java.util.List)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1