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);
}
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);
}
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);
}
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++;
}
}
}
}
}
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;
}
Aggregations