Search in sources :

Example 66 with PhysicalNetworkVO

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

the class CiscoVnmcElement method addCiscoVnmcResource.

@Override
public CiscoVnmcController addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
    final String deviceName = Provider.CiscoVnmc.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    CiscoVnmcController ciscoVnmcResource = null;
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "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: " + physicalNetworkId + "to add this device");
    }
    if (_ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A Cisco Vnmc device is already configured on this physical network");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "Cisco VNMC Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("username", cmd.getUsername());
    params.put("password", cmd.getPassword());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    ServerResource resource = new CiscoVnmcResource();
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalFirewall, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<CiscoVnmcController>() {

                @Override
                public CiscoVnmcController doInTransaction(TransactionStatus status) {
                    CiscoVnmcController ciscoVnmcResource = new CiscoVnmcControllerVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    _ciscoVnmcDao.persist((CiscoVnmcControllerVO) ciscoVnmcResource);
                    DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcResource.getId()));
                    _hostDetailsDao.persist(detail);
                    return ciscoVnmcResource;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Cisco Vnmc device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CiscoVnmcResource(com.cloud.network.resource.CiscoVnmcResource) CiscoVnmcController(com.cloud.network.cisco.CiscoVnmcController) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO)

Example 67 with PhysicalNetworkVO

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

the class PaloAltoExternalFirewallElement method listPaloAltoFirewalls.

@Override
public List<ExternalFirewallDeviceVO> listPaloAltoFirewalls(ListPaloAltoFirewallsCmd cmd) {
    Long physcialNetworkId = cmd.getPhysicalNetworkId();
    Long fwDeviceId = cmd.getFirewallDeviceId();
    PhysicalNetworkVO pNetwork = null;
    List<ExternalFirewallDeviceVO> fwDevices = new ArrayList<ExternalFirewallDeviceVO>();
    if (physcialNetworkId == null && fwDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
    }
    if (fwDeviceId != null) {
        ExternalFirewallDeviceVO fwDeviceVo = _fwDevicesDao.findById(fwDeviceId);
        if (fwDeviceVo == null || !fwDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.PaloAltoFirewall.getName())) {
            throw new InvalidParameterValueException("Could not find Palo Alto firewall device with ID: " + fwDeviceId);
        }
        fwDevices.add(fwDeviceVo);
    }
    if (physcialNetworkId != null) {
        pNetwork = _physicalNetworkDao.findById(physcialNetworkId);
        if (pNetwork == null) {
            throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId);
        }
        fwDevices = _fwDevicesDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.PaloAlto.getName());
    }
    return fwDevices;
}
Also used : ExternalFirewallDeviceVO(com.cloud.network.dao.ExternalFirewallDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 68 with PhysicalNetworkVO

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

the class VxlanGuestNetworkGuruTest method testImplementWithCidr.

@Test
public void testImplementWithCidr() 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.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    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);
    assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24"));
    assertTrue(implementednetwork.getGateway().equals("10.1.1.1"));
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 69 with PhysicalNetworkVO

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

the class VxlanGuestNetworkGuruTest method testCanHandle.

@Test
public void testCanHandle() {
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
    // Not supported TrafficType != Guest
    when(offering.getTrafficType()).thenReturn(TrafficType.Management);
    assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
    // Not supported: GuestType Shared
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
    // Not supported: Basic networking
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    assertFalse(guru.canHandle(offering, NetworkType.Basic, physnet) == true);
    // Not supported: IsolationMethod != VXLAN
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
    assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Test(org.junit.Test)

Example 70 with PhysicalNetworkVO

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

the class VxlanGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    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.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vxlan);
    when(network.getBroadcastUri()).thenReturn(new URI("vxlan:12345"));
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    when(netdao.findById(42L)).thenReturn(network);
    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);
    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);
    NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(42L);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("vxlan:12345"));
    when(offering.getSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) 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