Search in sources :

Example 6 with Vlan

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

the class NiciraNvpElement method applyPFRules.

/**
 * From interface PortForwardingServiceProvider
 */
@Override
public boolean applyPFRules(final Network network, final List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Network.Service.PortForwarding)) {
        return false;
    }
    final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId());
    final NiciraNvpRouterMappingVO routermapping = this.niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    if (routermapping == null) {
        s_logger.error("No logical router uuid found for network " + network.getDisplayText());
        return false;
    }
    final List<PortForwardingRuleTO> portForwardingRules = new ArrayList<>();
    for (final PortForwardingRule rule : rules) {
        final IpAddress sourceIp = this.networkModel.getIp(rule.getSourceIpAddressId());
        final Vlan vlan = this.vlanDao.findById(sourceIp.getVlanId());
        final PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        portForwardingRules.add(ruleTO);
    }
    final ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
    final ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd);
    return answer.getResult();
}
Also used : PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) ConfigurePortForwardingRulesOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePortForwardingRulesOnLogicalRouterCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) Vlan(com.cloud.legacymodel.dc.Vlan) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule) ConfigurePortForwardingRulesOnLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.ConfigurePortForwardingRulesOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 7 with Vlan

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

the class ListVlanIpRangesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Pair<List<? extends Vlan>, Integer> vlans = _mgr.searchForVlans(this);
    final ListResponse<VlanIpRangeResponse> response = new ListResponse<>();
    final List<VlanIpRangeResponse> vlanResponses = new ArrayList<>();
    for (final Vlan vlan : vlans.first()) {
        final VlanIpRangeResponse vlanResponse = _responseGenerator.createVlanIpRangeResponse(vlan);
        vlanResponse.setObjectName("vlaniprange");
        vlanResponses.add(vlanResponse);
    }
    response.setResponses(vlanResponses, vlans.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : VlanIpRangeResponse(com.cloud.api.response.VlanIpRangeResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(com.cloud.legacymodel.dc.Vlan)

Example 8 with Vlan

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

the class ApiResponseHelper method createSystemVmResponse.

@Override
public SystemVmResponse createSystemVmResponse(final VirtualMachine vm) {
    final SystemVmResponse vmResponse = new SystemVmResponse();
    if (vm.getType() == VirtualMachineType.SecondaryStorageVm || vm.getType() == VirtualMachineType.ConsoleProxy || vm.getType() == VirtualMachineType.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) {
            final HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
            if (pod != null) {
                vmResponse.setPodId(pod.getUuid());
            }
        }
        final VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
        if (template != null) {
            vmResponse.setTemplateId(template.getUuid());
        }
        vmResponse.setCreated(vm.getCreated());
        if (vm.getHostId() != null) {
            final 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() == VirtualMachineType.ConsoleProxy) {
            final ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
            // proxy can be already destroyed
            if (proxy != null) {
                vmResponse.setActiveViewerSessions(proxy.getActiveSession());
            }
        }
        final 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());
        }
        final List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
        for (final NicProfile singleNicProfile : nicProfiles) {
            final 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.
                         * */
                    final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
                    if (networkOffering.getElasticIp()) {
                        final IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
                        if (ip != null) {
                            final 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(com.cloud.api.response.SystemVmResponse) DataCenter(com.cloud.legacymodel.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VMTemplateVO(com.cloud.storage.VMTemplateVO) Host(com.cloud.legacymodel.dc.Host) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) IpAddress(com.cloud.network.IpAddress) GuestVlan(com.cloud.network.GuestVlan) Vlan(com.cloud.legacymodel.dc.Vlan) NicProfile(com.cloud.vm.NicProfile) HostPodVO(com.cloud.dc.HostPodVO)

Example 9 with Vlan

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

the class ConfigurationManagerImpl method deletePod.

@Override
@DB
public boolean deletePod(final DeletePodCmd cmd) {
    final Long podId = cmd.getId();
    // Make sure the pod exists
    if (!validPod(podId)) {
        throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist.");
    }
    checkIfPodIsDeletable(podId);
    final HostPodVO pod = _podDao.findById(podId);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // Delete private ip addresses for the pod if there are any
            final List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(podId, pod.getDataCenterId());
            if (!privateIps.isEmpty()) {
                if (!_privateIpAddressDao.deleteIpAddressByPod(podId)) {
                    throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
                }
            }
            // Delete link local ip addresses for the pod
            final List<DataCenterLinkLocalIpAddressVO> localIps = _linkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId());
            if (!localIps.isEmpty()) {
                if (!_linkLocalIpAllocDao.deleteIpAddressByPod(podId)) {
                    throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
                }
            }
            // Delete vlans associated with the pod
            final List<? extends Vlan> vlans = _networkModel.listPodVlans(podId);
            if (vlans != null && !vlans.isEmpty()) {
                for (final Vlan vlan : vlans) {
                    _vlanDao.remove(vlan.getId());
                }
            }
            // Delete corresponding capacity records
            _capacityDao.removeBy(null, null, podId, null, null);
            // Delete the pod
            if (!_podDao.remove(podId)) {
                throw new CloudRuntimeException("Failed to delete pod " + podId);
            }
            // remove from dedicated resources
            final DedicatedResourceVO dr = _dedicatedDao.findByPodId(podId);
            if (dr != null) {
                _dedicatedDao.remove(dr.getId());
            }
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(com.cloud.legacymodel.dc.Vlan) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostPodVO(com.cloud.dc.HostPodVO) DB(com.cloud.utils.db.DB)

Example 10 with Vlan

use of com.cloud.legacymodel.dc.Vlan 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.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Vlan(com.cloud.legacymodel.dc.Vlan) VlanVO(com.cloud.dc.VlanVO)

Aggregations

Vlan (com.cloud.legacymodel.dc.Vlan)12 VlanVO (com.cloud.dc.VlanVO)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)4 ArrayList (java.util.ArrayList)4 VlanIpRangeResponse (com.cloud.api.response.VlanIpRangeResponse)3 Network (com.cloud.legacymodel.network.Network)3 ServerApiException (com.cloud.api.ServerApiException)2 HostPodVO (com.cloud.dc.HostPodVO)2 IpAddress (com.cloud.network.IpAddress)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 List (java.util.List)2 ListResponse (com.cloud.api.response.ListResponse)1 SystemVmResponse (com.cloud.api.response.SystemVmResponse)1 Zone (com.cloud.db.model.Zone)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 DedicatedResourceVO (com.cloud.dc.DedicatedResourceVO)1 HostVO (com.cloud.host.HostVO)1 ConfigurePortForwardingRulesOnLogicalRouterAnswer (com.cloud.legacymodel.communication.answer.ConfigurePortForwardingRulesOnLogicalRouterAnswer)1 ConfigurePortForwardingRulesOnLogicalRouterCommand (com.cloud.legacymodel.communication.command.ConfigurePortForwardingRulesOnLogicalRouterCommand)1