Search in sources :

Example 1 with PhysicalNetworkSetupInfo

use of com.cloud.legacymodel.network.PhysicalNetworkSetupInfo in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckNetworkCommand.

@Test
public void testCheckNetworkCommand() {
    final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<>();
    final PhysicalNetworkSetupInfo nic = Mockito.mock(PhysicalNetworkSetupInfo.class);
    networkInfoList.add(nic);
    final CheckNetworkCommand command = new CheckNetworkCommand(networkInfoList);
    when(this.libvirtComputingResource.checkNetwork(nic.getGuestNetworkName())).thenReturn(true);
    when(this.libvirtComputingResource.checkNetwork(nic.getPrivateNetworkName())).thenReturn(true);
    when(this.libvirtComputingResource.checkNetwork(nic.getPublicNetworkName())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(3)).checkNetwork(nic.getGuestNetworkName());
    verify(this.libvirtComputingResource, times(3)).checkNetwork(nic.getPrivateNetworkName());
    verify(this.libvirtComputingResource, times(3)).checkNetwork(nic.getPublicNetworkName());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) ArrayList(java.util.ArrayList) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo) Test(org.junit.Test)

Example 2 with PhysicalNetworkSetupInfo

use of com.cloud.legacymodel.network.PhysicalNetworkSetupInfo in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckNetworkCommandFail1.

@Test
public void testCheckNetworkCommandFail1() {
    final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<>();
    final PhysicalNetworkSetupInfo networkSetupInfo = Mockito.mock(PhysicalNetworkSetupInfo.class);
    networkInfoList.add(networkSetupInfo);
    final CheckNetworkCommand command = new CheckNetworkCommand(networkInfoList);
    when(this.libvirtComputingResource.checkNetwork(networkSetupInfo.getGuestNetworkName())).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).checkNetwork(networkSetupInfo.getGuestNetworkName());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) ArrayList(java.util.ArrayList) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo) Test(org.junit.Test)

Example 3 with PhysicalNetworkSetupInfo

use of com.cloud.legacymodel.network.PhysicalNetworkSetupInfo in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method getPhysicalNetworkInfo.

@Override
public List<PhysicalNetworkSetupInfo> getPhysicalNetworkInfo(final long dcId, final HypervisorType hypervisorType) {
    final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<>();
    final List<PhysicalNetworkVO> physicalNtwkList = _physicalNetworkDao.listByZone(dcId);
    for (final PhysicalNetworkVO pNtwk : physicalNtwkList) {
        final String publicName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Public, hypervisorType);
        final String privateName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Management, hypervisorType);
        final String guestName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Guest, hypervisorType);
        final String storageName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Storage, hypervisorType);
        // String controlName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Control, hypervisorType);
        final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
        info.setPhysicalNetworkId(pNtwk.getId());
        info.setGuestNetworkName(guestName);
        info.setPrivateNetworkName(privateName);
        info.setPublicNetworkName(publicName);
        info.setStorageNetworkName(storageName);
        final PhysicalNetworkTrafficTypeVO mgmtTraffic = _pNTrafficTypeDao.findBy(pNtwk.getId(), TrafficType.Management);
        if (mgmtTraffic != null) {
            final String vlan = mgmtTraffic.getVlan();
            info.setMgmtVlan(vlan);
        }
        networkInfoList.add(info);
    }
    return networkInfoList;
}
Also used : ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo)

Example 4 with PhysicalNetworkSetupInfo

use of com.cloud.legacymodel.network.PhysicalNetworkSetupInfo in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
    for (final StartupCommand startupCommand : startupCommands) {
        if (!(startupCommand instanceof StartupRoutingCommand)) {
            return;
        }
        final long hostId = host.getId();
        final StartupRoutingCommand startup = (StartupRoutingCommand) startupCommand;
        final String dataCenter = startup.getDataCenter();
        long dcId = -1;
        Zone dc = _zoneRepository.findByName(dataCenter);
        if (dc == null) {
            try {
                dcId = Long.parseLong(dataCenter);
                dc = _zoneRepository.findById(dcId).orElse(null);
            } catch (final NumberFormatException e) {
            }
        }
        if (dc == null) {
            throw new IllegalArgumentException("Host " + startup.getPrivateIpAddress() + " sent incorrect data center: " + dataCenter);
        }
        dcId = dc.getId();
        final HypervisorType hypervisorType = startup.getHypervisorType();
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Host's hypervisorType is: " + hypervisorType);
        }
        final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<>();
        // list all physicalnetworks in the zone & for each get the network names
        final List<PhysicalNetworkVO> physicalNtwkList = _physicalNetworkDao.listByZone(dcId);
        for (final PhysicalNetworkVO pNtwk : physicalNtwkList) {
            final String publicName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Public, hypervisorType);
            final String privateName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Management, hypervisorType);
            final String guestName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Guest, hypervisorType);
            final String storageName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Storage, hypervisorType);
            // String controlName = _pNTrafficTypeDao._networkModel.getNetworkTag(pNtwk.getId(), TrafficType.Control, hypervisorType);
            final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
            info.setPhysicalNetworkId(pNtwk.getId());
            info.setGuestNetworkName(guestName);
            info.setPrivateNetworkName(privateName);
            info.setPublicNetworkName(publicName);
            info.setStorageNetworkName(storageName);
            final PhysicalNetworkTrafficTypeVO mgmtTraffic = _pNTrafficTypeDao.findBy(pNtwk.getId(), TrafficType.Management);
            if (mgmtTraffic != null) {
                final String vlan = mgmtTraffic.getVlan();
                info.setMgmtVlan(vlan);
            }
            networkInfoList.add(info);
        }
        // send the names to the agent
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Sending CheckNetworkCommand to check the Network is setup correctly on Agent");
        }
        final CheckNetworkCommand nwCmd = new CheckNetworkCommand(networkInfoList);
        final CheckNetworkAnswer answer = (CheckNetworkAnswer) _agentMgr.easySend(hostId, nwCmd);
        if (answer == null) {
            s_logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId());
            throw new ConnectionException(true, "Unable to get an answer to the CheckNetworkCommand from agent: " + host.getId());
        }
        if (!answer.getResult()) {
            s_logger.warn("Unable to setup agent " + hostId + " due to " + answer.getDetails());
            final String msg = "Incorrect Network setup on agent, Reinitialize agent after network names are setup, details : " + answer.getDetails();
            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, host.getPodId(), msg, msg);
            throw new ConnectionException(true, msg);
        } else {
            if (answer.needReconnect()) {
                throw new ConnectionException(false, "Reinitialize agent after network setup.");
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Network setup is correct on Agent");
            }
            return;
        }
    }
}
Also used : Zone(com.cloud.db.model.Zone) ArrayList(java.util.ArrayList) CheckNetworkAnswer(com.cloud.legacymodel.communication.answer.CheckNetworkAnswer) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) HypervisorType(com.cloud.model.enumeration.HypervisorType) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo)

Example 5 with PhysicalNetworkSetupInfo

use of com.cloud.legacymodel.network.PhysicalNetworkSetupInfo in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testCheckNetworkCommandSuccess.

@Test
public void testCheckNetworkCommandSuccess() {
    final List<PhysicalNetworkSetupInfo> setupInfos = new ArrayList<>();
    final CheckNetworkCommand checkNet = new CheckNetworkCommand(setupInfos);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(checkNet, this.citrixResourceBase);
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) ArrayList(java.util.ArrayList) CheckNetworkCommand(com.cloud.legacymodel.communication.command.CheckNetworkCommand) PhysicalNetworkSetupInfo(com.cloud.legacymodel.network.PhysicalNetworkSetupInfo) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PhysicalNetworkSetupInfo (com.cloud.legacymodel.network.PhysicalNetworkSetupInfo)12 ArrayList (java.util.ArrayList)10 CheckNetworkCommand (com.cloud.legacymodel.communication.command.CheckNetworkCommand)9 Answer (com.cloud.legacymodel.communication.answer.Answer)8 Test (org.junit.Test)8 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)6 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 CheckNetworkAnswer (com.cloud.legacymodel.communication.answer.CheckNetworkAnswer)3 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)2 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)2 PhysicalNetworkTrafficTypeVO (com.cloud.network.dao.PhysicalNetworkTrafficTypeVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Zone (com.cloud.db.model.Zone)1 XenServer610Resource (com.cloud.hypervisor.xenserver.resource.XenServer610Resource)1 XenServer620Resource (com.cloud.hypervisor.xenserver.resource.XenServer620Resource)1 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)1 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)1 ConnectionException (com.cloud.legacymodel.exceptions.ConnectionException)1