Search in sources :

Example 6 with NuageVspDeviceVO

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

the class NuageVspGuestNetworkGuruTest method testDesign.

@Test
public void testDesign() {
    final NuageVspDeviceVO device = mock(NuageVspDeviceVO.class);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(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(offering.getIsPersistent()).thenReturn(false);
    when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(false);
    when(_networkOfferingServiceMapDao.canProviderSupportServiceInNetworkOffering(NETWORK_ID, Service.Connectivity, Network.Provider.NuageVsp)).thenReturn(true);
    when(_networkOfferingServiceMapDao.canProviderSupportServiceInNetworkOffering(NETWORK_ID, Service.SourceNat, Network.Provider.NuageVsp)).thenReturn(true);
    when(_networkModel.getNetworkOfferingServiceProvidersMap(NETWORK_ID)).thenReturn(ImmutableMap.of(Service.Connectivity, Sets.newSet(Network.Provider.NuageVsp), Service.SourceNat, Sets.newSet(Network.Provider.NuageVsp)));
    final DeploymentPlan plan = mock(DeploymentPlan.class);
    final Network network = mock(Network.class);
    final Account account = mock(Account.class);
    final Network designednetwork = _nuageVspGuestNetworkGuru.design(offering, plan, network, account);
    assertThat(designednetwork, notNullValue(Network.class));
    assertThat(designednetwork.getBroadcastDomainType(), is(BroadcastDomainType.Vsp));
    // Can't design non-persistent VPC tier
    when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(true);
    assertThat(_nuageVspGuestNetworkGuru.design(offering, plan, network, account), nullValue(Network.class));
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) DeploymentPlan(com.cloud.deploy.DeploymentPlan) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 7 with NuageVspDeviceVO

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

the class NuageVspManagerTest method testListNuageVspDevices.

@Test
public void testListNuageVspDevices() {
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final PhysicalNetworkVO phyNtwkVO = mock(PhysicalNetworkVO.class);
    when(_physicalNetworkDao.findById(NETWORK_ID)).thenReturn(phyNtwkVO);
    when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NuageVspDeviceVO>());
    final ListNuageVspDevicesCmd cmd = mock(ListNuageVspDevicesCmd.class);
    when(cmd.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(cmd.getNuageVspDeviceId()).thenReturn(null);
    _nuageVspManager.listNuageVspDevices(cmd);
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ListNuageVspDevicesCmd(com.cloud.api.commands.ListNuageVspDevicesCmd) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 8 with NuageVspDeviceVO

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

the class NuageVspManagerTest method testDeleteNuageVspDevice.

@Test
public void testDeleteNuageVspDevice() throws ConfigurationException {
    final PhysicalNetworkVO physicalNetwork = mock(PhysicalNetworkVO.class);
    when(physicalNetwork.getDataCenterId()).thenReturn(NETWORK_ID);
    when(physicalNetwork.getId()).thenReturn(NETWORK_ID);
    when(_physicalNetworkDao.findById(NETWORK_ID)).thenReturn(physicalNetwork);
    final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
    when(nuageVspDevice.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
    when(_nuageVspDao.findById(NETWORK_ID)).thenReturn(nuageVspDevice);
    when(_networkDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NetworkVO>());
    final HostVO host = mock(HostVO.class);
    when(host.getId()).thenReturn(NETWORK_ID);
    when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
    final DeleteNuageVspDeviceCmd cmd = mock(DeleteNuageVspDeviceCmd.class);
    when(cmd.getNuageVspDeviceId()).thenReturn(NETWORK_ID);
    ConfigurationVO cmsIdConfig = mock(ConfigurationVO.class);
    when(cmsIdConfig.getValue()).thenReturn("1:1");
    when(_configurationDao.findByName("nuagevsp.cms.id")).thenReturn(cmsIdConfig);
    final SyncNuageVspCmsIdAnswer answer = mock(SyncNuageVspCmsIdAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    _nuageVspManager.deleteNuageVspDevice(cmd);
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteNuageVspDeviceCmd(com.cloud.api.commands.DeleteNuageVspDeviceCmd) ConfigurationVO(org.apache.cloudstack.framework.config.impl.ConfigurationVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) HostVO(com.cloud.host.HostVO) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 9 with NuageVspDeviceVO

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

the class NuageVspManagerImpl method updateNuageVspDevice.

@Override
public NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd command) {
    NuageVspResource resource = new NuageVspResource();
    final String deviceName = Network.Provider.NuageVsp.getName();
    ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = command.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    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");
    }
    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");
    }
    HostVO nuageVspHost = null;
    NuageVspDeviceVO nuageVspDevice = null;
    List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
    if (nuageVspDevices == null || nuageVspDevices.isEmpty()) {
        throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
    } else {
        nuageVspDevice = nuageVspDevices.iterator().next();
        nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
        _hostDao.loadDetails(nuageVspHost);
    }
    boolean resourceConfigurationChanged = false;
    NuageVspResourceConfiguration resourceConfiguration = NuageVspResourceConfiguration.fromConfiguration(nuageVspHost.getDetails());
    if (!Strings.isNullOrEmpty(command.getHostName()) && !command.getHostName().equals(resourceConfiguration.hostName())) {
        resourceConfiguration.hostName(command.getHostName());
        resourceConfigurationChanged = true;
    }
    if (!Strings.isNullOrEmpty(command.getUserName()) && !command.getUserName().equals(resourceConfiguration.cmsUser())) {
        resourceConfiguration.cmsUser(command.getUserName());
        resourceConfigurationChanged = true;
    }
    if (!Strings.isNullOrEmpty(command.getPassword())) {
        String encodedNewPassword = NuageVspUtil.encodePassword(command.getPassword());
        if (!encodedNewPassword.equals(resourceConfiguration.cmsUserPassword())) {
            resourceConfiguration.cmsUserPassword(encodedNewPassword);
            resourceConfigurationChanged = true;
        }
    }
    if (command.getPort() != null && command.getPort() != Integer.parseInt(resourceConfiguration.port())) {
        resourceConfiguration.port(String.valueOf(command.getPort()));
        resourceConfigurationChanged = true;
    }
    String apiVersion = MoreObjects.firstNonNull(command.getApiVersion(), resourceConfiguration.apiVersion());
    NuageVspApiVersion apiVersionObj = NuageVspApiVersion.fromString(apiVersion);
    NuageVspApiVersion apiVersionCurrent = null;
    try {
        apiVersionCurrent = resourceConfiguration.getApiVersion();
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Current version is not configured correctly");
    }
    if (command.getApiVersion() != null) {
        if (apiVersionObj.compareTo(apiVersionCurrent) < 0) {
            throw new CloudRuntimeException("Downgrading is not supported");
        }
        GetApiDefaultsCommand apiDefaultsCmd = new GetApiDefaultsCommand();
        GetApiDefaultsAnswer apiDefaultsAnswer = (GetApiDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), apiDefaultsCmd);
        SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion);
        Answer supportedApiVersionAnswer = _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd);
        if (!supportedApiVersionAnswer.getResult()) {
            throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
        }
        String apiRelativePath = "/nuage/api/" + apiVersion;
        if (!apiRelativePath.equals(resourceConfiguration.apiRelativePath())) {
            resourceConfiguration.apiVersion(apiVersion);
            resourceConfiguration.apiRelativePath(apiRelativePath);
            resourceConfigurationChanged = true;
        }
    }
    if (command.getApiRetryCount() != null && resourceConfiguration.retryCount() != null) {
        final int retryCount = Integer.parseInt(resourceConfiguration.retryCount());
        if (command.getApiRetryCount() != retryCount) {
            resourceConfiguration.retryCount(String.valueOf(command.getApiRetryCount()));
            resourceConfigurationChanged = true;
        }
    }
    if (command.getApiRetryInterval() != null && resourceConfiguration.retryInterval() != null) {
        final int apiRetryInterval = Integer.parseInt(resourceConfiguration.retryInterval());
        if (command.getApiRetryInterval() != apiRetryInterval) {
            resourceConfiguration.retryInterval(String.valueOf(command.getApiRetryInterval()));
            resourceConfigurationChanged = true;
        }
    }
    if (!resourceConfigurationChanged) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No change in the NuageVsp device parameters. None of the NuageVsp device parameters are modified");
        }
        return nuageVspDevice;
    }
    Map<String, String> config = resourceConfiguration.build();
    try {
        resource.validate(config);
        UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(resourceConfiguration);
        Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("UpdateNuageVspDeviceCommand failed");
            if ((null != answer) && (null != answer.getDetails())) {
                throw new CloudRuntimeException(answer.getDetails());
            }
        }
        _hostDetailsDao.persist(nuageVspDevice.getHostId(), config);
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException("Failed to update Nuage VSP device " + nuageVspDevice.getId() + " with parameters " + resourceConfiguration, e);
    }
    return nuageVspDevice;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) NuageVspResourceConfiguration(com.cloud.network.resource.NuageVspResourceConfiguration) ExternalNetworkDeviceManager(org.apache.cloudstack.network.ExternalNetworkDeviceManager) GetApiDefaultsCommand(com.cloud.agent.api.manager.GetApiDefaultsCommand) SupportedApiVersionCommand(com.cloud.agent.api.manager.SupportedApiVersionCommand) UpdateNuageVspDeviceCommand(com.cloud.agent.api.manager.UpdateNuageVspDeviceCommand) HostVO(com.cloud.host.HostVO) NuageVspResource(com.cloud.network.resource.NuageVspResource) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetApiDefaultsAnswer(com.cloud.agent.api.manager.GetApiDefaultsAnswer) SyncNuageVspCmsIdAnswer(com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NuageVspApiVersion(net.nuage.vsp.acs.client.common.NuageVspApiVersion)

Example 10 with NuageVspDeviceVO

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

the class NuageVspManagerImpl method findMatchingNuageVspDevice.

private NuageVspDeviceVO findMatchingNuageVspDevice(NuageVspDeviceVO nuageVspDevice) {
    DetailVO nuageVspDeviceHost = _hostDetailsDao.findDetail(nuageVspDevice.getHostId(), "hostname");
    String nuageVspDeviceHostName = (nuageVspDeviceHost != null) ? nuageVspDeviceHost.getValue() : null;
    List<NuageVspDeviceVO> otherNuageVspDevices = _nuageVspDao.listAll();
    for (NuageVspDeviceVO otherNuageVspDevice : otherNuageVspDevices) {
        if (otherNuageVspDevice.getId() == nuageVspDevice.getId())
            continue;
        DetailVO otherNuageVspDeviceHostName = _hostDetailsDao.findDetail(otherNuageVspDevice.getHostId(), "hostname");
        if (otherNuageVspDeviceHostName != null && nuageVspDeviceHostName.equals(otherNuageVspDeviceHostName.getValue())) {
            return otherNuageVspDevice;
        }
    }
    return null;
}
Also used : NuageVspDeviceVO(com.cloud.network.NuageVspDeviceVO) DetailVO(com.cloud.host.DetailVO)

Aggregations

NuageVspDeviceVO (com.cloud.network.NuageVspDeviceVO)23 HostVO (com.cloud.host.HostVO)11 NuageTest (com.cloud.NuageTest)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 Test (org.junit.Test)9 DomainVO (com.cloud.domain.DomainVO)8 Answer (com.cloud.agent.api.Answer)7 SyncNuageVspCmsIdAnswer (com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 ArrayList (java.util.ArrayList)6 Network (com.cloud.network.Network)5 PhysicalNetwork (com.cloud.network.PhysicalNetwork)5 SyncNuageVspCmsIdCommand (com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand)4 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)4 NuageVspDeviceResponse (com.cloud.api.response.NuageVspDeviceResponse)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 Account (com.cloud.user.Account)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2