Search in sources :

Example 36 with NetworkVO

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

the class VirtualRouterElementTest method testGetRouters2.

@Test
public void testGetRouters2() {
    Network networkUpdateInprogress = new NetworkVO(2l, null, null, null, 1l, 1l, 1l, 1l, "d", "d", "d", null, 1l, 1l, null, true, null, true);
    mockDAOs((NetworkVO) networkUpdateInprogress, testOffering);
    //alwyas return backup routers first when both master and backup need update.
    List<DomainRouterVO> routers = virtualRouterElement.getRouters(networkUpdateInprogress);
    assertTrue(routers.size() == 1);
    assertTrue(routers.get(0).getRedundantState() == RedundantState.BACKUP && routers.get(0).getUpdateState() == VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) Network(com.cloud.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 37 with NetworkVO

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

the class VirtualRouterElementTest method testGetRouters1.

@Test
public void testGetRouters1() {
    Network networkUpdateInprogress = new NetworkVO(1l, null, null, null, 1l, 1l, 1l, 1l, "d", "d", "d", null, 1l, 1l, null, true, null, true);
    mockDAOs((NetworkVO) networkUpdateInprogress, testOffering);
    //getRoutes should always return the router that is updating.
    List<DomainRouterVO> routers = virtualRouterElement.getRouters(networkUpdateInprogress);
    assertTrue(routers.size() == 1);
    assertTrue(routers.get(0).getUpdateState() == VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) Network(com.cloud.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 38 with NetworkVO

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

the class ConsoleProxyManagerTest method getDefaultNetworkForAdvancedSG.

@Test
public void getDefaultNetworkForAdvancedSG() {
    DataCenterVO dc = Mockito.mock(DataCenterVO.class);
    when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(dc.isSecurityGroupEnabled()).thenReturn(true);
    when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
    NetworkVO network = Mockito.mock(NetworkVO.class);
    NetworkVO badNetwork = Mockito.mock(NetworkVO.class);
    when(_networkDao.listByZoneAndTrafficType(anyLong(), any(TrafficType.class))).thenReturn(Collections.singletonList(badNetwork));
    when(_networkDao.listByZoneSecurityGroup(anyLong())).thenReturn(Collections.singletonList(network));
    NetworkVO returnedNetwork = cpvmManager.getDefaultNetworkForAdvancedZone(dc);
    Assert.assertEquals(network, returnedNetwork);
    Assert.assertNotEquals(badNetwork, returnedNetwork);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) TrafficType(com.cloud.network.Networks.TrafficType) Test(org.junit.Test)

Example 39 with NetworkVO

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

the class ConfigurationServerImpl method createDefaultNetworks.

private void createDefaultNetworks() {
    List<DataCenterVO> zones = _dataCenterDao.listAll();
    long id = 1;
    HashMap<TrafficType, String> guruNames = new HashMap<TrafficType, String>();
    guruNames.put(TrafficType.Public, PublicNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Management, PodBasedNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Control, ControlNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Storage, StorageNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Guest, DirectPodBasedNetworkGuru.class.getSimpleName());
    for (DataCenterVO zone : zones) {
        long zoneId = zone.getId();
        long accountId = 1L;
        Long domainId = zone.getDomainId();
        if (domainId == null) {
            domainId = 1L;
        }
        // Create default networks - system only
        List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
        for (NetworkOfferingVO offering : ntwkOff) {
            if (offering.isSystemOnly()) {
                long related = id;
                long networkOfferingId = offering.getId();
                Mode mode = Mode.Static;
                String networkDomain = null;
                BroadcastDomainType broadcastDomainType = null;
                TrafficType trafficType = offering.getTrafficType();
                boolean specifyIpRanges = false;
                if (trafficType == TrafficType.Management) {
                    broadcastDomainType = BroadcastDomainType.Native;
                } else if (trafficType == TrafficType.Storage) {
                    broadcastDomainType = BroadcastDomainType.Native;
                    specifyIpRanges = true;
                } else if (trafficType == TrafficType.Control) {
                    broadcastDomainType = BroadcastDomainType.LinkLocal;
                } else if (offering.getTrafficType() == TrafficType.Public) {
                    if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) {
                        specifyIpRanges = true;
                        broadcastDomainType = BroadcastDomainType.Vlan;
                    } else {
                        continue;
                    }
                }
                if (broadcastDomainType != null) {
                    NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null, offering.getRedundantRouter());
                    network.setGuruName(guruNames.get(network.getTrafficType()));
                    network.setDns1(zone.getDns1());
                    network.setDns2(zone.getDns2());
                    network.setState(State.Implemented);
                    _networkDao.persist(network, false, getServicesAndProvidersForNetwork(networkOfferingId));
                    id++;
                }
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) HashMap(java.util.HashMap) Mode(com.cloud.network.Networks.Mode) StorageNetworkGuru(com.cloud.network.guru.StorageNetworkGuru) PublicNetworkGuru(com.cloud.network.guru.PublicNetworkGuru) ControlNetworkGuru(com.cloud.network.guru.ControlNetworkGuru) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) PodBasedNetworkGuru(com.cloud.network.guru.PodBasedNetworkGuru) DirectPodBasedNetworkGuru(com.cloud.network.guru.DirectPodBasedNetworkGuru) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) DirectPodBasedNetworkGuru(com.cloud.network.guru.DirectPodBasedNetworkGuru) TrafficType(com.cloud.network.Networks.TrafficType)

Example 40 with NetworkVO

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

the class CloudOrchestrator method createVirtualMachineFromScratch.

@Override
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, NicProfile> networkNicMap, DeploymentPlan plan) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    //load vm instance and offerings and call virtualMachineManagerImpl
    VMInstanceVO vm = _vmDao.findByUuid(id);
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    rootDiskOfferingInfo.setDiskOffering(computeOffering);
    Long diskOfferingId = vm.getDiskOfferingId();
    if (diskOfferingId == null) {
        throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
    }
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
    if (diskOffering == null) {
        throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
    }
    Long size = null;
    if (diskOffering.getDiskSize() == 0) {
        size = diskSize;
        if (size == null) {
            throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
        }
        _volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
    }
    rootDiskOfferingInfo.setDiskOffering(diskOffering);
    rootDiskOfferingInfo.setSize(size);
    if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIopsDo");
            String maxIops = userVmDetails.get("maxIopsDo");
            rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
            rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
        }
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<Network, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
        }
    }
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Aggregations

NetworkVO (com.cloud.network.dao.NetworkVO)230 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)108 ArrayList (java.util.ArrayList)79 Test (org.junit.Test)56 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)55 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)49 Account (com.cloud.user.Account)44 Network (com.cloud.network.Network)39 DataCenterVO (com.cloud.dc.DataCenterVO)35 DataCenter (com.cloud.dc.DataCenter)34 NicVO (com.cloud.vm.NicVO)33 NicProfile (com.cloud.vm.NicProfile)27 HostVO (com.cloud.host.HostVO)24 NetworkOffering (com.cloud.offering.NetworkOffering)24 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)22 ReservationContext (com.cloud.vm.ReservationContext)22 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)20 DeployDestination (com.cloud.deploy.DeployDestination)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 NetworkGuru (com.cloud.network.guru.NetworkGuru)19