Search in sources :

Example 1 with NetworkUsageCommand

use of com.cloud.legacymodel.communication.command.NetworkUsageCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testNetworkUsageCommandVpcGet.

@Test
public void testNetworkUsageCommandVpcGet() {
    final String privateIP = "127.0.0.1";
    final String domRName = "domR";
    final boolean forVpc = true;
    final String gatewayIP = "127.0.0.1";
    final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, forVpc, gatewayIP);
    this.libvirtComputingResource.getNetworkStats(command.getPrivateIP());
    when(this.libvirtComputingResource.getVpcNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption())).thenReturn(new long[] { 10l, 10l });
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getVpcNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption());
}
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) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Example 2 with NetworkUsageCommand

use of com.cloud.legacymodel.communication.command.NetworkUsageCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testNetworkUsageCommandVpcCreate.

@Test
public void testNetworkUsageCommandVpcCreate() {
    final String privateIP = "127.0.0.1";
    final String domRName = "domR";
    final boolean forVpc = true;
    final String gatewayIP = "127.0.0.1";
    final String vpcCidr = "10.1.1.0/24";
    final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, forVpc, gatewayIP, vpcCidr);
    this.libvirtComputingResource.getNetworkStats(command.getPrivateIP());
    when(this.libvirtComputingResource.configureVpcNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR())).thenReturn("SUCCESS");
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).configureVpcNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR());
}
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) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Example 3 with NetworkUsageCommand

use of com.cloud.legacymodel.communication.command.NetworkUsageCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testNetworkUsageCommandNonVpcCreate.

@Test
public void testNetworkUsageCommandNonVpcCreate() {
    final String privateIP = "127.0.0.1";
    final String domRName = "domR";
    final boolean forVpc = false;
    final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, "create", forVpc);
    this.libvirtComputingResource.getNetworkStats(command.getPrivateIP());
    when(this.libvirtComputingResource.networkUsage(command.getPrivateIP(), "create", null)).thenReturn("SUCCESS");
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).networkUsage(command.getPrivateIP(), "create", null);
}
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) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) Test(org.junit.Test)

Example 4 with NetworkUsageCommand

use of com.cloud.legacymodel.communication.command.NetworkUsageCommand in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeSshAndVersionAndNetworkUsageOnStart.

protected void finalizeSshAndVersionAndNetworkUsageOnStart(final Commands cmds, final VirtualMachineProfile profile, final DomainRouterVO router, final NicProfile controlNic) {
    final DomainRouterVO vr = _routerDao.findById(profile.getId());
    cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIPv4Address(), 3922));
    // Update router template/scripts version
    final GetDomRVersionCommand command = new GetDomRVersionCommand();
    command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlNic.getIPv4Address());
    command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    cmds.addCommand("getDomRVersion", command);
    // Network usage command to create iptables rules
    final boolean forVpc = vr.getVpcId() != null;
    if (!forVpc) {
        cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIPv4Address(), router.getHostName(), "create", forVpc));
    }
}
Also used : GetDomRVersionCommand(com.cloud.legacymodel.communication.command.GetDomRVersionCommand) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 5 with NetworkUsageCommand

use of com.cloud.legacymodel.communication.command.NetworkUsageCommand in project cosmic by MissionCriticalCloud.

the class NicPlugInOutRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    final Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = getNicsToChangeOnRouter(visitor);
    final Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
    final Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
    final NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
    final VirtualMachineManager itMgr = visitor.getVirtualNetworkApplianceFactory().getItMgr();
    // 1) Unplug the nics
    for (final Entry<String, PublicIpAddress> entry : nicsToUnplug.entrySet()) {
        Network publicNtwk = null;
        try {
            publicNtwk = networkModel.getNetwork(entry.getValue().getNetworkId());
            final URI broadcastUri = BroadcastDomainType.Vlan.toUri(entry.getKey());
            itMgr.removeVmFromNetwork(_router, publicNtwk, broadcastUri);
        } catch (final ConcurrentOperationException e) {
            s_logger.warn("Failed to remove router " + _router + " from vlan " + entry.getKey() + " in public network " + publicNtwk + " due to ", e);
            return false;
        }
    }
    _netUsageCommands = new Commands(Command.OnError.Continue);
    final VpcDao vpcDao = visitor.getVirtualNetworkApplianceFactory().getVpcDao();
    final VpcVO vpc = vpcDao.findById(_router.getVpcId());
    // 2) Plug the nics
    for (final String vlanTag : nicsToPlug.keySet()) {
        final PublicIpAddress ip = nicsToPlug.get(vlanTag);
        // have to plug the nic(s)
        final NicProfile defaultNic = new NicProfile();
        if (ip.isSourceNat()) {
            defaultNic.setDefaultNic(true);
        }
        defaultNic.setIPv4Address(ip.getAddress().addr());
        defaultNic.setIPv4Gateway(ip.getGateway());
        defaultNic.setIPv4Netmask(ip.getNetmask());
        defaultNic.setMacAddress(ip.getMacAddress());
        defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
        defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
        defaultNic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
        NicProfile publicNic = null;
        Network publicNtwk = null;
        try {
            publicNtwk = networkModel.getNetwork(ip.getNetworkId());
            publicNic = itMgr.addVmToNetwork(_router, publicNtwk, defaultNic);
        } catch (final ConcurrentOperationException e) {
            s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
        } catch (final InsufficientCapacityException e) {
            s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
        } finally {
            if (publicNic == null) {
                s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk);
                return false;
            }
        }
        // Create network usage commands. Send commands to router after
        // IPAssoc
        final NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(_router.getPrivateIpAddress(), _router.getInstanceName(), true, defaultNic.getIPv4Address(), vpc.getCidr());
        _netUsageCommands.addCommand(netUsageCmd);
        final UserStatisticsDao userStatsDao = visitor.getVirtualNetworkApplianceFactory().getUserStatsDao();
        UserStatisticsVO stats = userStatsDao.findBy(_router.getAccountId(), _router.getDataCenterId(), publicNtwk.getId(), publicNic.getIPv4Address(), _router.getId(), _router.getType().toString());
        if (stats == null) {
            stats = new UserStatisticsVO(_router.getAccountId(), _router.getDataCenterId(), publicNic.getIPv4Address(), _router.getId(), _router.getType().toString(), publicNtwk.getId());
            userStatsDao.persist(stats);
        }
    }
    // VpcIpAssociation is done.
    return true;
}
Also used : NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) UserStatisticsDao(com.cloud.user.dao.UserStatisticsDao) PublicIpAddress(com.cloud.network.PublicIpAddress) VpcDao(com.cloud.network.vpc.dao.VpcDao) VpcVO(com.cloud.network.vpc.VpcVO) Network(com.cloud.legacymodel.network.Network) Commands(com.cloud.agent.manager.Commands) NetworkModel(com.cloud.network.NetworkModel) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) HashMap(java.util.HashMap) Map(java.util.Map) UserStatisticsVO(com.cloud.user.UserStatisticsVO)

Aggregations

NetworkUsageCommand (com.cloud.legacymodel.communication.command.NetworkUsageCommand)17 Answer (com.cloud.legacymodel.communication.answer.Answer)13 Test (org.junit.Test)13 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)6 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)6 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)6 Connection (com.xensource.xenapi.Connection)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)3 Network (com.cloud.legacymodel.network.Network)3 UserStatisticsVO (com.cloud.user.UserStatisticsVO)3 DomainRouterVO (com.cloud.vm.DomainRouterVO)3 ExecutionResult (com.cloud.legacymodel.ExecutionResult)2 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)2 Nic (com.cloud.legacymodel.network.Nic)2 VpcVO (com.cloud.network.vpc.VpcVO)2 ConfigurationException (javax.naming.ConfigurationException)2 Commands (com.cloud.agent.manager.Commands)1 NetworkUsageAnswer (com.cloud.legacymodel.communication.answer.NetworkUsageAnswer)1