use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VirtualNetworkModelTest method setUp.
@Override
@Before
public void setUp() throws IOException {
//Network UUIDs
String uuid = UUID.randomUUID().toString();
String uuid1 = UUID.randomUUID().toString();
String uuid2 = UUID.randomUUID().toString();
String uuid3 = UUID.randomUUID().toString();
//ContrailManager
ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
controller = mock(ModelController.class);
VlanDao vlanDao = mock(VlanDao.class);
ApiConnector api = mock(ApiConnectorMock.class);
//Mock classes/methods
when(controller.getManager()).thenReturn(contrailMgr);
when(controller.getApiAccessor()).thenReturn(api);
when(controller.getVlanDao()).thenReturn(vlanDao);
//Policy References used by vnModel1
List<ObjectReference<VirtualNetworkPolicyType>> policyRefs1 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
ObjectReference<VirtualNetworkPolicyType> objectReference1 = new ObjectReference<VirtualNetworkPolicyType>();
policyRefs1.add(objectReference1);
//Policy References used by vnModel2
List<ObjectReference<VirtualNetworkPolicyType>> policyRefs2 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
ObjectReference<VirtualNetworkPolicyType> objectReference2 = new ObjectReference<VirtualNetworkPolicyType>();
policyRefs2.add(objectReference2);
//Policy References used by vnModel3
List<ObjectReference<VirtualNetworkPolicyType>> policyRefs3 = new ArrayList<ObjectReference<VirtualNetworkPolicyType>>();
ObjectReference<VirtualNetworkPolicyType> objectReference3 = new ObjectReference<VirtualNetworkPolicyType>();
objectReference3.setReference(Arrays.asList(""), null, null, UUID.randomUUID().toString());
policyRefs3.add(objectReference3);
//Network to be compared with
VirtualNetwork vn = mock(VirtualNetwork.class);
when(api.findById(VirtualNetwork.class, uuid)).thenReturn(vn);
//Network to be compared with
VirtualNetwork vn1 = mock(VirtualNetwork.class);
when(api.findById(VirtualNetwork.class, uuid1)).thenReturn(vn1);
when(vn1.getNetworkPolicy()).thenReturn(policyRefs1);
//Network to be compared to
VirtualNetwork vn2 = mock(VirtualNetwork.class);
when(api.findById(VirtualNetwork.class, uuid2)).thenReturn(vn2);
when(vn2.getNetworkPolicy()).thenReturn(policyRefs2);
//Network to be compared to
VirtualNetwork vn3 = mock(VirtualNetwork.class);
when(api.findById(VirtualNetwork.class, uuid3)).thenReturn(vn3);
when(vn3.getNetworkPolicy()).thenReturn(policyRefs3);
//Virtual-Network 1
NetworkVO network1 = mock(NetworkVO.class);
when(network1.getName()).thenReturn("testnetwork");
when(network1.getState()).thenReturn(State.Allocated);
when(network1.getGateway()).thenReturn("10.1.1.1");
when(network1.getCidr()).thenReturn("10.1.1.0/24");
when(network1.getPhysicalNetworkId()).thenReturn(42L);
when(network1.getDomainId()).thenReturn(10L);
when(network1.getAccountId()).thenReturn(42L);
//Virtual-Network 2
NetworkVO network2 = mock(NetworkVO.class);
when(network2.getName()).thenReturn("Testnetwork");
when(network2.getState()).thenReturn(State.Allocated);
when(network2.getGateway()).thenReturn("10.1.1.1");
when(network2.getCidr()).thenReturn("10.1.1.0/24");
when(network2.getPhysicalNetworkId()).thenReturn(42L);
when(network2.getDomainId()).thenReturn(10L);
when(network2.getAccountId()).thenReturn(42L);
//Virtual-Network 3
NetworkVO network3 = mock(NetworkVO.class);
when(network3.getName()).thenReturn("Testnetwork");
when(network3.getState()).thenReturn(State.Allocated);
when(network3.getGateway()).thenReturn("10.1.1.1");
when(network3.getCidr()).thenReturn("10.1.1.0/24");
when(network3.getPhysicalNetworkId()).thenReturn(42L);
when(network3.getDomainId()).thenReturn(10L);
when(network3.getAccountId()).thenReturn(42L);
when(contrailMgr.getCanonicalName(network1)).thenReturn("testnetwork");
when(contrailMgr.getProjectId(network1.getDomainId(), network1.getAccountId())).thenReturn("testProjectId");
vnModel = new VirtualNetworkModel(network1, uuid, "testnetwork", TrafficType.Guest);
vnModel1 = new VirtualNetworkModel(network1, uuid1, "testnetwork", TrafficType.Guest);
vnModel2 = new VirtualNetworkModel(network2, uuid2, "testnetwork", TrafficType.Guest);
vnModel3 = new VirtualNetworkModel(network3, uuid3, "testnetwork", TrafficType.Guest);
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class ManagementServerMock method createPublicVlanIpRange.
private void createPublicVlanIpRange() {
CreateVlanIpRangeCmd cmd = new CreateVlanIpRangeCmd();
BaseCmd proxy = ComponentContext.inject(cmd);
Long public_net_id = null;
List<NetworkVO> nets = _networksDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
if (nets != null && !nets.isEmpty()) {
NetworkVO public_net = nets.get(0);
public_net_id = public_net.getId();
} else {
s_logger.debug("no public network found in the zone: " + _zone.getId());
}
Account system = _accountMgr.getSystemAccount();
setParameter(cmd, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
setParameter(cmd, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
setParameter(cmd, "startIp", BaseCmd.CommandType.STRING, "10.84.60.200");
setParameter(cmd, "endIp", BaseCmd.CommandType.STRING, "10.84.60.250");
setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING, "10.84.60.254");
setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING, "255.255.255.0");
setParameter(cmd, "networkID", BaseCmd.CommandType.LONG, public_net_id);
setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, _zone.getId());
setParameter(cmd, "vlan", BaseCmd.CommandType.STRING, "untagged");
s_logger.debug("createPublicVlanIpRange execute : zone id: " + _zone.getId() + ", public net id: " + public_net_id);
try {
_configService.createVlanAndPublicIpRange(cmd);
} catch (Exception e) {
s_logger.debug("createPublicVlanIpRange: " + e);
}
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VxlanGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
long dcId = dest.getDataCenter().getId();
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
// physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
allocateVnet(network, implemented, dcId, physicalNetworkId, context.getReservationId());
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
return implemented;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VxlanGuestNetworkGuru method shutdown.
@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
NetworkVO networkObject = _networkDao.findById(profile.getId());
if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Vxlan || networkObject.getBroadcastUri() == null) {
s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText());
return;
}
super.shutdown(profile, offering);
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VxlanGuestNetworkGuruTest method testImplement.
@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById(anyLong())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
when(physnet.getId()).thenReturn(42L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
//TODO(VXLAN): doesn't support VNI specified
//when(confsvr.getConfigValue((String) any(), (String) any(), anyLong())).thenReturn("true");
when(dcdao.allocateVnet(anyLong(), anyLong(), anyLong(), (String) any(), eq(true))).thenReturn("42");
doNothing().when(guru).allocateVnetComplete((Network) any(), (NetworkVO) any(), anyLong(), anyLong(), (String) any(), eq("42"));
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
}
Aggregations