use of com.cloud.network.dao.NetworkDao in project cosmic by MissionCriticalCloud.
the class DhcpPvlanRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
String op = "add";
if (!_isAddPvlan) {
op = "delete";
}
final NetworkDao networkDao = visitor.getVirtualNetworkApplianceFactory().getNetworkDao();
final Network network = networkDao.findById(_nic.getNetworkId());
final NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
final String networkTag = networkModel.getNetworkTag(_router.getHypervisorType(), network);
_setupCommand = PvlanSetupCommand.createDhcpSetup(op, _nic.getBroadCastUri(), networkTag, _router.getInstanceName(), _nic.getMacAddress(), _nic.getIPv4Address());
return visitor.visit(this);
}
use of com.cloud.network.dao.NetworkDao in project cosmic by MissionCriticalCloud.
the class PrivateGatewayRules method retrievePrivateNetwork.
public Network retrievePrivateNetwork(final NetworkTopologyVisitor visitor) {
// This network might be the same we have already as an instance in the
// RuleApplier super class.
// Just doing this here, but will double check is remove if it's not
// needed.
final NetworkDao networkDao = visitor.getVirtualNetworkApplianceFactory().getNetworkDao();
final Network network = networkDao.findById(_nicProfile.getNetworkId());
return network;
}
use of com.cloud.network.dao.NetworkDao in project cloudstack by apache.
the class VMInterfaceModelTest method testCreateVMInterface.
@Test
public void testCreateVMInterface() throws IOException {
String uuid;
ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
ModelController controller = mock(ModelController.class);
ApiConnector api = new ApiConnectorMock(null, 0);
when(controller.getManager()).thenReturn(contrailMgr);
when(controller.getApiAccessor()).thenReturn(api);
// Create Virtual-Network (VN)
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(Network.State.Implemented);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkDao networkDao = mock(NetworkDao.class);
when(networkDao.findById(anyLong())).thenReturn(network);
when(controller.getNetworkDao()).thenReturn(networkDao);
when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
VirtualNetworkModel vnModel = new VirtualNetworkModel(network, UUID.randomUUID().toString(), "test", TrafficType.Guest);
vnModel.build(controller, network);
try {
vnModel.update(controller);
} catch (Exception ex) {
fail("virtual-network update failed ");
}
// Create Virtual-Machine (VM)
VMInstanceVO vm = mock(VMInstanceVO.class);
when(vm.getInstanceName()).thenReturn("testVM1");
when(vm.getState()).thenReturn(VirtualMachine.State.Running);
when(vm.getDomainId()).thenReturn(10L);
when(vm.getAccountId()).thenReturn(42L);
UserVmDao VmDao = mock(UserVmDao.class);
when(VmDao.findById(anyLong())).thenReturn(null);
when(controller.getVmDao()).thenReturn(VmDao);
VirtualMachineModel vmModel = new VirtualMachineModel(vm, UUID.randomUUID().toString());
vmModel.build(controller, vm);
try {
vmModel.update(controller);
} catch (Exception ex) {
fail("virtual-machine update failed ");
}
// Create Virtual=Machine-Interface (VMInterface)
NicVO nic = mock(NicVO.class);
when(nic.getIPv4Address()).thenReturn("10.1.1.2");
when(nic.getMacAddress()).thenReturn("00:01:02:03:04:05");
when(nic.getDeviceId()).thenReturn(100);
when(nic.getState()).thenReturn(NicVO.State.Allocated);
when(nic.getNetworkId()).thenReturn(10L);
when(contrailMgr.getVifNameByVmName(anyString(), anyInt())).thenReturn("testVM1-100");
uuid = UUID.randomUUID().toString();
VMInterfaceModel vmiModel = new VMInterfaceModel(uuid);
assertEquals(uuid, vmiModel.getUuid());
vmiModel.addToVirtualMachine(vmModel);
vmiModel.addToVirtualNetwork(vnModel);
try {
vmiModel.build(controller, vm, nic);
vmiModel.setActive();
} catch (Exception ex) {
fail("vm-interface build failed ");
}
try {
vmiModel.update(controller);
} catch (Exception ex) {
fail("vm-interface update failed ");
}
// Verify virtual-machine-interface creation.
try {
VirtualMachineInterface vmi = (VirtualMachineInterface) api.findById(VirtualMachineInterface.class, vmiModel.getUuid());
assertNotNull(vmi);
} catch (Exception ex) {
fail("vm-interface verify failed ");
}
}
use of com.cloud.network.dao.NetworkDao in project cloudstack by apache.
the class VirtualMachineModel method setServiceInstanceNics.
private void setServiceInstanceNics(ModelController controller, VMInstanceVO instance) throws IOException {
NicDao nicDao = controller.getNicDao();
ContrailManager manager = controller.getManager();
NetworkDao networkDao = controller.getNetworkDao();
List<NicVO> nics = nicDao.listByVmId(_instanceId);
for (NicVO nic : nics) {
String tag;
switch(nic.getDeviceId()) {
case 0:
tag = "management";
break;
case 1:
tag = "left";
break;
case 2:
tag = "right";
break;
default:
tag = null;
}
VMInterfaceModel vmiModel = getVMInterface(nic.getUuid());
if (vmiModel == null) {
vmiModel = new VMInterfaceModel(nic.getUuid());
vmiModel.addToVirtualMachine(this);
NetworkVO network = networkDao.findById(nic.getNetworkId());
VirtualNetworkModel vnModel = manager.getDatabase().lookupVirtualNetwork(network.getUuid(), manager.getCanonicalName(network), network.getTrafficType());
assert vnModel != null;
vmiModel.addToVirtualNetwork(vnModel);
}
vmiModel.setProperties(controller, instance, nic);
vmiModel.setServiceTag(tag);
}
}
use of com.cloud.network.dao.NetworkDao in project cloudstack by apache.
the class InstanceIpModelTest method testCreateInstanceIp.
@Test
public void testCreateInstanceIp() throws IOException {
ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
ModelController controller = mock(ModelController.class);
ApiConnector api = new ApiConnectorMock(null, 0);
when(controller.getApiAccessor()).thenReturn(api);
when(controller.getManager()).thenReturn(contrailMgr);
// Create Virtual-Network (VN)
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(Network.State.Implemented);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkDao networkDao = mock(NetworkDao.class);
when(networkDao.findById(anyLong())).thenReturn(network);
when(controller.getNetworkDao()).thenReturn(networkDao);
when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
VirtualNetworkModel vnModel = new VirtualNetworkModel(network, UUID.randomUUID().toString(), "test", TrafficType.Guest);
vnModel.build(controller, network);
try {
vnModel.update(controller);
} catch (Exception ex) {
fail("virtual-network update failed ");
}
// Create Virtual-Machine (VM)
VMInstanceVO vm = mock(VMInstanceVO.class);
when(vm.getInstanceName()).thenReturn("testVM1");
when(vm.getState()).thenReturn(VirtualMachine.State.Running);
when(vm.getDomainId()).thenReturn(10L);
when(vm.getAccountId()).thenReturn(42L);
UserVmDao VmDao = mock(UserVmDao.class);
when(VmDao.findById(anyLong())).thenReturn(null);
when(controller.getVmDao()).thenReturn(VmDao);
VirtualMachineModel vmModel = new VirtualMachineModel(vm, UUID.randomUUID().toString());
vmModel.build(controller, vm);
try {
vmModel.update(controller);
} catch (Exception ex) {
fail("virtual-machine update failed ");
}
// Create Virtual=Machine-Interface (VMInterface)
NicVO nic = mock(NicVO.class);
when(nic.getIPv4Address()).thenReturn("10.1.1.2");
when(nic.getMacAddress()).thenReturn("00:01:02:03:04:05");
when(nic.getDeviceId()).thenReturn(100);
when(nic.getState()).thenReturn(NicVO.State.Allocated);
when(nic.getNetworkId()).thenReturn(10L);
when(contrailMgr.getVifNameByVmName(anyString(), anyInt())).thenReturn("testVM1-100");
VMInterfaceModel vmiModel = new VMInterfaceModel(UUID.randomUUID().toString());
vmiModel.addToVirtualMachine(vmModel);
vmiModel.addToVirtualNetwork(vnModel);
try {
vmiModel.build(controller, vm, nic);
vmiModel.setActive();
} catch (Exception ex) {
fail("vm-interface build failed ");
}
try {
vmiModel.update(controller);
} catch (Exception ex) {
fail("vm-interface update failed ");
}
InstanceIpModel ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
ipModel.addToVMInterface(vmiModel);
ipModel.setAddress(nic.getIPv4Address());
try {
ipModel.update(controller);
} catch (Exception ex) {
fail("ipInstance update failed ");
}
}
Aggregations