Search in sources :

Example 51 with PhysicalNetworkVO

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

the class OpendaylightGuestNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        s_logger.debug("Refusing to design this network");
        return null;
    }
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physnet.getId());
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + physnet.getName());
        return null;
    }
    s_logger.debug("Controller " + devices.get(0).getUuid() + " found on physical network " + physnet.getId());
    s_logger.debug("Physical isolation type is ODL, asking GuestNetworkGuru to design this network");
    NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner);
    if (networkObject == null) {
        return null;
    }
    // Override the broadcast domain type
    networkObject.setBroadcastDomainType(BroadcastDomainType.OpenDaylight);
    return networkObject;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 52 with PhysicalNetworkVO

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

the class BaremetalDhcpManagerImpl method generateApiResponse.

@Override
public BaremetalDhcpResponse generateApiResponse(BaremetalDhcpVO vo) {
    BaremetalDhcpResponse response = new BaremetalDhcpResponse();
    response.setDeviceType(vo.getDeviceType());
    response.setId(vo.getUuid());
    HostVO host = _hostDao.findById(vo.getHostId());
    response.setUrl(host.getPrivateIpAddress());
    PhysicalNetworkVO nwVO = _physicalNetworkDao.findById(vo.getPhysicalNetworkId());
    response.setPhysicalNetworkId(nwVO.getUuid());
    PhysicalNetworkServiceProviderVO providerVO = _physicalNetworkServiceProviderDao.findById(vo.getNetworkServiceProviderId());
    response.setProviderId(providerVO.getUuid());
    response.setObjectName("baremetaldhcp");
    return response;
}
Also used : PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO)

Example 53 with PhysicalNetworkVO

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

the class BaremetalDhcpManagerImpl method addDchpServer.

@Override
@DB
public BaremetalDhcpVO addDchpServer(AddBaremetalDhcpCmd cmd) {
    PhysicalNetworkVO pNetwork = null;
    long zoneId;
    if (cmd.getPhysicalNetworkId() == null || cmd.getUrl() == null || cmd.getUsername() == null || cmd.getPassword() == null) {
        throw new IllegalArgumentException("At least one of the required parameters(physical network id, url, username, password) is null");
    }
    pNetwork = _physicalNetworkDao.findById(cmd.getPhysicalNetworkId());
    if (pNetwork == null) {
        throw new IllegalArgumentException("Could not find phyical network with ID: " + cmd.getPhysicalNetworkId());
    }
    zoneId = pNetwork.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), BaremetalDhcpManager.BAREMETAL_DHCP_SERVICE_PROVIDER.getName());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + BaremetalDhcpManager.BAREMETAL_DHCP_SERVICE_PROVIDER.getName() + " is not enabled in the physical network: " + cmd.getPhysicalNetworkId() + "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: " + cmd.getPhysicalNetworkId() + "to add this device");
    }
    List<HostVO> dhcps = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.BaremetalDhcp, null, null, zoneId);
    if (dhcps.size() != 0) {
        throw new IllegalArgumentException("Already had a DHCP server in zone: " + zoneId);
    }
    URI uri;
    try {
        uri = new URI(cmd.getUrl());
    } catch (Exception e) {
        s_logger.debug(e);
        throw new IllegalArgumentException(e.getMessage());
    }
    String ipAddress = uri.getHost();
    if (ipAddress == null) {
        // the url is raw ip. For backforward compatibility, we have to support http://ip format as well
        ipAddress = cmd.getUrl();
    }
    String guid = getDhcpServerGuid(Long.toString(zoneId), "ExternalDhcp", ipAddress);
    Map params = new HashMap<String, String>();
    params.put("type", cmd.getDhcpType());
    params.put("zone", Long.toString(zoneId));
    params.put("ip", ipAddress);
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    params.put("guid", guid);
    String dns = zone.getDns1();
    if (dns == null) {
        dns = zone.getDns2();
    }
    params.put("dns", dns);
    ServerResource resource = null;
    try {
        if (cmd.getDhcpType().equalsIgnoreCase(BaremetalDhcpType.DNSMASQ.toString())) {
            resource = new BaremetalDnsmasqResource();
            resource.configure("Dnsmasq resource", params);
        } else if (cmd.getDhcpType().equalsIgnoreCase(BaremetalDhcpType.DHCPD.toString())) {
            resource = new BaremetalDhcpdResource();
            resource.configure("Dhcpd resource", params);
        } else {
            throw new CloudRuntimeException("Unsupport DHCP server type: " + cmd.getDhcpType());
        }
    } catch (Exception e) {
        s_logger.debug(e);
        throw new CloudRuntimeException(e.getMessage());
    }
    Host dhcpServer = _resourceMgr.addHost(zoneId, resource, Host.Type.BaremetalDhcp, params);
    if (dhcpServer == null) {
        throw new CloudRuntimeException("Cannot add external Dhcp server as a host");
    }
    BaremetalDhcpVO vo = new BaremetalDhcpVO();
    vo.setDeviceType(cmd.getDhcpType());
    vo.setHostId(dhcpServer.getId());
    vo.setNetworkServiceProviderId(ntwkSvcProvider.getId());
    vo.setPhysicalNetworkId(cmd.getPhysicalNetworkId());
    _extDhcpDao.persist(vo);
    return vo;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) Host(com.cloud.host.Host) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) BaremetalDhcpVO(com.cloud.baremetal.database.BaremetalDhcpVO) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HashMap(java.util.HashMap) Map(java.util.Map) DB(com.cloud.utils.db.DB)

Example 54 with PhysicalNetworkVO

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

the class ManagementServerMock method locatePhysicalNetwork.

private void locatePhysicalNetwork() {
    // mandatory: name, zone-id
    try {
        long id = _networkService.findPhysicalNetworkId(_zone.getId(), "znet", TrafficType.Guest);
        _znet = _networkService.getPhysicalNetwork(id);
        List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
        if (nets == null || nets.isEmpty()) {
            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), "vlan", null, null, null, null, null, null, null);
        }
    } catch (InvalidParameterValueException e) {
        List<String> isolationMethods = new ArrayList<String>();
        isolationMethods.add("L3VPN");
        _znet = _networkService.createPhysicalNetwork(_zone.getId(), null, null, isolationMethods, BroadcastDomainRange.ZONE.toString(), _zone.getDomainId(), null, "znet");
        List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
        if (nets == null || nets.isEmpty()) {
            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), "vlan", null, null, null, null, null, null, null);
        }
    }
    if (_znet.getState() != PhysicalNetwork.State.Enabled) {
        _znet = _networkService.updatePhysicalNetwork(_znet.getId(), null, null, null, PhysicalNetwork.State.Enabled.toString());
    }
    // Ensure that the physical network supports Guest traffic.
    Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(_znet.getId());
    boolean found = false;
    for (PhysicalNetworkTrafficType ttype : trafficTypes.first()) {
        if (ttype.getTrafficType() == TrafficType.Guest) {
            found = true;
        }
    }
    if (!found) {
        _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Guest.toString(), "vlan", null, null, null, null, null, null, null);
    }
    Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> providers = _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null, null);
    if (providers.second() == 0) {
        s_logger.debug("Add " + Provider.JuniperContrailRouter.getName() + " to network " + _znet.getName());
        PhysicalNetworkServiceProvider provider = _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null);
        _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
    } else {
        PhysicalNetworkServiceProvider provider = providers.first().get(0);
        if (provider.getState() != PhysicalNetworkServiceProvider.State.Enabled) {
            _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
        }
    }
    providers = _networkService.listNetworkServiceProviders(_znet.getId(), null, PhysicalNetworkServiceProvider.State.Enabled.toString(), null, null);
    s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled providers");
    for (PhysicalNetworkServiceProvider provider : providers.first()) {
        if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName())) {
            continue;
        }
        s_logger.debug("Disabling " + provider.getProviderName());
        _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Disabled.toString(), null);
    }
}
Also used : PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) List(java.util.List) ArrayList(java.util.ArrayList) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 55 with PhysicalNetworkVO

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

the class ConfigurationManagerTest method checkIfZoneIsDeletableFailureOnPodTest.

@Test(expected = CloudRuntimeException.class)
public void checkIfZoneIsDeletableFailureOnPodTest() {
    HostPodVO hostPodVO = Mockito.mock(HostPodVO.class);
    ArrayList<HostPodVO> arrayList = new ArrayList<HostPodVO>();
    arrayList.add(hostPodVO);
    Mockito.when(_hostDao.listByDataCenterId(anyLong())).thenReturn(new ArrayList<HostVO>());
    Mockito.when(_podDao.listByDataCenterId(anyLong())).thenReturn(arrayList);
    Mockito.when(_privateIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_publicIpAddressDao.countIPs(anyLong(), anyBoolean())).thenReturn(0);
    Mockito.when(_vmInstanceDao.listByZoneId(anyLong())).thenReturn(new ArrayList<VMInstanceVO>());
    Mockito.when(_volumeDao.findByDc(anyLong())).thenReturn(new ArrayList<VolumeVO>());
    Mockito.when(_physicalNetworkDao.listByZone(anyLong())).thenReturn(new ArrayList<PhysicalNetworkVO>());
    configurationMgr.checkIfZoneIsDeletable(new Random().nextLong());
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) Random(java.util.Random) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) Test(org.junit.Test)

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