Search in sources :

Example 11 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cloudstack by apache.

the class NiciraNvpGuestNetworkGuruTest method testImplementURIException.

@Test
public void testImplementURIException() throws InsufficientVirtualNetworkCapacityException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    // when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork == null);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 12 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method release.

@Override
public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    if (!canHandle(network, Network.Service.Connectivity)) {
        return false;
    }
    if (network.getBroadcastUri() == null) {
        s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
        return false;
    }
    final NicVO nicVO = nicDao.findById(nic.getId());
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    final NiciraNvpNicMappingVO nicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
    if (nicMap == null) {
        s_logger.error("No mapping for nic " + nic.getName());
        return false;
    }
    // When the lswitch is used in another network in the zone, simply return without deleting the lswitch
    if (networkDao.countByZoneAndUri(network.getDataCenterId(), network.getBroadcastUri().toString()) > 1) {
        s_logger.error("There are other networks using this lswitch, so not deleting lswitch!");
        return true;
    }
    final DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
    final DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("DeleteLogicalSwitchPortCommand failed");
        return false;
    }
    niciraNvpNicMappingDao.remove(nicMap.getId());
    return true;
}
Also used : NiciraNvpNicMappingVO(com.cloud.network.NiciraNvpNicMappingVO) DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) DeleteLogicalSwitchPortAnswer(com.cloud.agent.api.DeleteLogicalSwitchPortAnswer) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO)

Example 13 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method applyStaticNats.

/**
 * From interface StaticNatServiceProvider
 */
@Override
public boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Network.Service.StaticNat)) {
        return false;
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    final NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    if (routermapping == null) {
        s_logger.error("No logical router uuid found for network " + network.getDisplayText());
        return false;
    }
    final List<StaticNatRuleTO> staticNatRules = new ArrayList<>();
    for (final StaticNat rule : rules) {
        final IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
        // Force the nat rule into the StaticNatRuleTO, no use making a new TO object
        // we only need the source and destination ip. Unfortunately no mention if a rule
        // is new.
        final StaticNatRuleTO ruleTO = new StaticNatRuleTO(1, sourceIp.getAddress().addr(), MIN_PORT, MAX_PORT, rule.getDestIpAddress(), MIN_PORT, MAX_PORT, "any", rule.isForRevoke(), false);
        staticNatRules.add(ruleTO);
    }
    final ConfigureStaticNatRulesOnLogicalRouterCommand cmd = new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
    final ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    return answer.getResult();
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) ConfigureStaticNatRulesOnLogicalRouterCommand(com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) ConfigureStaticNatRulesOnLogicalRouterAnswer(com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO) StaticNat(com.cloud.network.rules.StaticNat)

Example 14 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method applyPFRules.

/**
 * From interface PortForwardingServiceProvider
 */
@Override
public boolean applyPFRules(final Network network, final List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Network.Service.PortForwarding)) {
        return false;
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    final NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    if (routermapping == null) {
        s_logger.error("No logical router uuid found for network " + network.getDisplayText());
        return false;
    }
    final List<PortForwardingRuleTO> portForwardingRules = new ArrayList<>();
    for (final PortForwardingRule rule : rules) {
        final IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
        final Vlan vlan = vlanDao.findById(sourceIp.getVlanId());
        final PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        portForwardingRules.add(ruleTO);
    }
    final ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
    final ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    return answer.getResult();
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) ConfigurePortForwardingRulesOnLogicalRouterCommand(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) ConfigurePortForwardingRulesOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 15 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method addNiciraNvpDevice.

@Override
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd) {
    final ServerResource resource = new NiciraNvpResource();
    final String deviceName = Network.Provider.NiciraNvp.getName();
    final NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    if (networkDevice == null) {
        throw new CloudRuntimeException("No network device found for " + deviceName);
    }
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    final 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 (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
        throw new CloudRuntimeException("A NiciraNvp device is already configured on this physical network");
    }
    final Map<String, String> params = new HashMap<>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "Nicira Controller - " + cmd.getHost());
    params.put("ip", cmd.getHost());
    params.put("adminuser", cmd.getUsername());
    params.put("adminpass", cmd.getPassword());
    params.put("transportzoneuuid", cmd.getTransportzoneUuid());
    // FIXME What to do with multiple isolation types
    params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
    if (cmd.getL3GatewayServiceUuid() != null) {
        params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
    }
    final Map<String, Object> hostdetails = new HashMap<>();
    hostdetails.putAll(params);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        final Host host = resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {

                @Override
                public NiciraNvpDeviceVO doInTransaction(final TransactionStatus status) {
                    final NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
                    niciraNvpDao.persist(niciraNvpDevice);
                    final DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
                    hostDetailsDao.persist(detail);
                    return niciraNvpDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add Nicira Nvp Device due to internal error.");
        }
    } catch (final ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NetworkDevice(com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ServerResource(com.cloud.resource.ServerResource) NiciraNvpResource(com.cloud.network.resource.NiciraNvpResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DB(com.cloud.utils.db.DB)

Aggregations

NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)50 HostVO (com.cloud.host.HostVO)34 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)26 NetworkVO (com.cloud.network.dao.NetworkVO)18 NetworkOffering (com.cloud.offering.NetworkOffering)18 Account (com.cloud.user.Account)18 Test (org.junit.Test)18 Network (com.cloud.network.Network)16 ArrayList (java.util.ArrayList)14 NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)13 DeployDestination (com.cloud.deploy.DeployDestination)12 Domain (com.cloud.domain.Domain)12 ReservationContext (com.cloud.vm.ReservationContext)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)8 PublicIpAddress (com.cloud.network.PublicIpAddress)8 URI (java.net.URI)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)6 DataCenter (com.cloud.dc.DataCenter)5