Search in sources :

Example 91 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class NiciraNvpElement method listNiciraNvpDevices.

@Override
public List<NiciraNvpDeviceVO> listNiciraNvpDevices(ListNiciraNvpDevicesCmd cmd) {
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    Long niciraNvpDeviceId = cmd.getNiciraNvpDeviceId();
    List<NiciraNvpDeviceVO> responseList = new ArrayList<NiciraNvpDeviceVO>();
    if (physicalNetworkId == null && niciraNvpDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or nicira device Id must be specified");
    }
    if (niciraNvpDeviceId != null) {
        NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao.findById(niciraNvpDeviceId);
        if (niciraNvpDevice == null) {
            throw new InvalidParameterValueException("Could not find Nicira Nvp device with id: " + niciraNvpDevice);
        }
        responseList.add(niciraNvpDevice);
    } else {
        PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
        if (physicalNetwork == null) {
            throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
        }
        responseList = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
    }
    return responseList;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 92 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class ApiResponseHelper method createIPAddressResponse.

@Override
public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr) {
    VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
    boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
    long zoneId = ipAddr.getDataCenterId();
    IPAddressResponse ipResponse = new IPAddressResponse();
    ipResponse.setId(ipAddr.getUuid());
    ipResponse.setIpAddress(ipAddr.getAddress().toString());
    if (ipAddr.getAllocatedTime() != null) {
        ipResponse.setAllocated(ipAddr.getAllocatedTime());
    }
    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) {
        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) {
        Network ntwk = ApiDBUtils.findNetworkById(ipAddr.getAssociatedWithNetworkId());
        if (ntwk != null) {
            ipResponse.setAssociatedNetworkId(ntwk.getUuid());
            ipResponse.setAssociatedNetworkName(ntwk.getName());
        }
    }
    if (ipAddr.getVpcId() != null) {
        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)
    Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId());
    // Network id the ip belongs to
    Long networkId;
    if (vlanNetworkId != null) {
        networkId = vlanNetworkId;
    } else {
        networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
    }
    if (networkId != null) {
        NetworkVO nw = ApiDBUtils.findNetworkById(networkId);
        if (nw != null) {
            ipResponse.setNetworkId(nw.getUuid());
        }
    }
    ipResponse.setState(ipAddr.getState().toString());
    if (ipAddr.getPhysicalNetworkId() != null) {
        PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
        if (pnw != null) {
            ipResponse.setPhysicalNetworkId(pnw.getUuid());
        }
    }
    // show this info to full view only
    if (view == ResponseView.Full) {
        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());
    ipResponse.setPortable(ipAddr.isPortable());
    //set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PublicIpAddress, ipAddr.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        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) 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(org.apache.cloudstack.api.response.ResourceTagResponse) VlanVO(com.cloud.dc.VlanVO) IPAddressResponse(org.apache.cloudstack.api.response.IPAddressResponse)

Example 93 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class ApiResponseHelper method createDedicatedGuestVlanRangeResponse.

@Override
public GuestVlanRangeResponse createDedicatedGuestVlanRangeResponse(GuestVlan vlan) {
    GuestVlanRangeResponse guestVlanRangeResponse = new GuestVlanRangeResponse();
    guestVlanRangeResponse.setId(vlan.getUuid());
    Long accountId = ApiDBUtils.getAccountIdForGuestVlan(vlan.getId());
    Account owner = ApiDBUtils.findAccountById(accountId);
    if (owner != null) {
        populateAccount(guestVlanRangeResponse, owner.getId());
        populateDomain(guestVlanRangeResponse, owner.getDomainId());
    }
    guestVlanRangeResponse.setGuestVlanRange(vlan.getGuestVlanRange());
    guestVlanRangeResponse.setPhysicalNetworkId(vlan.getPhysicalNetworkId());
    PhysicalNetworkVO physicalNetwork = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
    guestVlanRangeResponse.setZoneId(physicalNetwork.getDataCenterId());
    return guestVlanRangeResponse;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) GuestVlanRangeResponse(org.apache.cloudstack.api.response.GuestVlanRangeResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 94 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class GuestNetworkGuru method design.

@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
    final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    final PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        return null;
    }
    final NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
    if (userSpecified != null) {
        if (userSpecified.getCidr() == null && userSpecified.getGateway() != null || userSpecified.getCidr() != null && userSpecified.getGateway() == null) {
            throw new InvalidParameterValueException("cidr and gateway must be specified together.");
        }
        if (userSpecified.getCidr() != null) {
            network.setCidr(userSpecified.getCidr());
            network.setGateway(userSpecified.getGateway());
        } else {
            final String guestNetworkCidr = dc.getGuestNetworkCidr();
            if (guestNetworkCidr != null) {
                final String[] cidrTuple = guestNetworkCidr.split("\\/");
                network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
                network.setCidr(guestNetworkCidr);
            } else if (dc.getNetworkType() == NetworkType.Advanced) {
                throw new CloudRuntimeException("Can't design network " + network + "; guest CIDR is not configured per zone " + dc);
            }
        }
        if (offering.getSpecifyVlan()) {
            network.setBroadcastUri(userSpecified.getBroadcastUri());
            network.setState(State.Setup);
        }
    } else {
        final String guestNetworkCidr = dc.getGuestNetworkCidr();
        if (guestNetworkCidr == null && dc.getNetworkType() == NetworkType.Advanced) {
            throw new CloudRuntimeException("Can't design network " + network + "; guest CIDR is not configured per zone " + dc);
        }
        final String[] cidrTuple = guestNetworkCidr.split("\\/");
        network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
        network.setCidr(guestNetworkCidr);
    }
    return network;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 95 with PhysicalNetworkVO

use of com.cloud.network.dao.PhysicalNetworkVO in project cloudstack by apache.

the class BigSwitchBcfElement method addBigSwitchBcfDevice.

@Override
@DB
public BigSwitchBcfDeviceVO addBigSwitchBcfDevice(AddBigSwitchBcfDeviceCmd cmd) {
    BigSwitchBcfDeviceVO newBcfDevice;
    bcfUtilsInit();
    ServerResource resource = new BigSwitchBcfResource();
    final String deviceName = BcfConstants.BIG_SWITCH_BCF.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final String hostname = cmd.getHost();
    final String username = cmd.getUsername();
    final String password = cmd.getPassword();
    final Boolean nat = cmd.getNat();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    ntwkSvcProvider.setFirewallServiceProvided(true);
    ntwkSvcProvider.setGatewayServiceProvided(true);
    ntwkSvcProvider.setNetworkAclServiceProvided(true);
    ntwkSvcProvider.setSourcenatServiceProvided(true);
    ntwkSvcProvider.setStaticnatServiceProvided(true);
    if (_bigswitchBcfDao.listByPhysicalNetwork(physicalNetworkId).size() > 1) {
        throw new CloudRuntimeException("At most two BCF controllers can be configured");
    }
    DataCenterVO zone = _zoneDao.findById(physicalNetwork.getDataCenterId());
    String zoneName;
    if (zone != null) {
        zoneName = zone.getName();
    } else {
        zoneName = String.valueOf(zoneId);
    }
    Boolean natNow = _bcfUtils.isNatEnabled();
    if (!nat && natNow) {
        throw new CloudRuntimeException("NAT is enabled in existing controller. Enable NAT for new controller or remove existing controller first.");
    } else if (nat && !natNow) {
        throw new CloudRuntimeException("NAT is disabled in existing controller. Disable NAT for new controller or remove existing controller first.");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", zoneName);
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "BigSwitch Controller - " + cmd.getHost());
    params.put("hostname", cmd.getHost());
    params.put("username", username);
    params.put("password", password);
    params.put("nat", nat.toString());
    // FIXME What to do with multiple isolation types
    params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        // store current topology in bcf resource
        TopologyData topo = _bcfUtils.getTopology(physicalNetwork.getId());
        ((BigSwitchBcfResource) resource).setTopology(topo);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            newBcfDevice = Transaction.execute(new TransactionCallback<BigSwitchBcfDeviceVO>() {

                @Override
                public BigSwitchBcfDeviceVO doInTransaction(TransactionStatus status) {
                    BigSwitchBcfDeviceVO bigswitchBcfDevice = new BigSwitchBcfDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName, hostname, username, password, nat, BigSwitchBcfApi.HASH_IGNORE);
                    _bigswitchBcfDao.persist(bigswitchBcfDevice);
                    DetailVO detail = new DetailVO(host.getId(), "bigswitchbcfdeviceid", String.valueOf(bigswitchBcfDevice.getId()));
                    _hostDetailsDao.persist(detail);
                    return bigswitchBcfDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add BigSwitch BCF Controller Device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    // initial topology sync to newly added BCF controller
    HostVO bigswitchBcfHost = _hostDao.findById(newBcfDevice.getHostId());
    _bcfUtils.syncTopologyToBcfHost(bigswitchBcfHost, nat);
    return newBcfDevice;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) BigSwitchBcfResource(com.cloud.network.resource.BigSwitchBcfResource) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) TopologyData(com.cloud.network.bigswitch.TopologyData) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO) DB(com.cloud.utils.db.DB)

Aggregations

PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)112 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)50 ArrayList (java.util.ArrayList)40 NetworkVO (com.cloud.network.dao.NetworkVO)35 HostVO (com.cloud.host.HostVO)28 Test (org.junit.Test)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 Account (com.cloud.user.Account)25 DataCenter (com.cloud.dc.DataCenter)22 NetworkOffering (com.cloud.offering.NetworkOffering)22 Network (com.cloud.network.Network)18 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)18 Host (com.cloud.host.Host)15 DB (com.cloud.utils.db.DB)15 ConfigurationException (javax.naming.ConfigurationException)14 HashMap (java.util.HashMap)12 DataCenterVO (com.cloud.dc.DataCenterVO)11 Domain (com.cloud.domain.Domain)11 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)10