Search in sources :

Example 1 with DnsMasqConfigCommand

use of com.cloud.agent.api.routing.DnsMasqConfigCommand in project cloudstack by apache.

the class CommandSetupHelper method configDnsMasq.

public void configDnsMasq(final VirtualRouter router, final Network network, final Commands cmds) {
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    final List<NicIpAliasVO> ipAliasVOList = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.State.active);
    final List<DhcpTO> ipList = new ArrayList<DhcpTO>();
    final NicVO router_guest_nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId());
    final String cidr = NetUtils.getCidrFromGatewayAndNetmask(router_guest_nic.getIPv4Gateway(), router_guest_nic.getIPv4Netmask());
    final String[] cidrPair = cidr.split("\\/");
    final String cidrAddress = cidrPair[0];
    final long cidrSize = Long.parseLong(cidrPair[1]);
    final String startIpOfSubnet = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize);
    ipList.add(new DhcpTO(router_guest_nic.getIPv4Address(), router_guest_nic.getIPv4Gateway(), router_guest_nic.getIPv4Netmask(), startIpOfSubnet));
    for (final NicIpAliasVO ipAliasVO : ipAliasVOList) {
        final DhcpTO DhcpTO = new DhcpTO(ipAliasVO.getIp4Address(), ipAliasVO.getGateway(), ipAliasVO.getNetmask(), ipAliasVO.getStartIpOfSubnet());
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("configDnsMasq : adding ip {" + DhcpTO.getGateway() + ", " + DhcpTO.getNetmask() + ", " + DhcpTO.getRouterIp() + ", " + DhcpTO.getStartIpOfSubnet() + "}");
        }
        ipList.add(DhcpTO);
        ipAliasVO.setVmId(router.getId());
    }
    _dcDao.findById(router.getDataCenterId());
    final DnsMasqConfigCommand dnsMasqConfigCmd = new DnsMasqConfigCommand(ipList);
    dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(network.getId(), router.getId()));
    dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand("dnsMasqConfig", dnsMasqConfigCmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) NicIpAliasVO(com.cloud.vm.dao.NicIpAliasVO) DhcpTO(com.cloud.agent.api.to.DhcpTO) NicVO(com.cloud.vm.NicVO) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Example 2 with DnsMasqConfigCommand

use of com.cloud.agent.api.routing.DnsMasqConfigCommand in project cloudstack by apache.

the class DnsMasqConfigItem method generateConfig.

@Override
public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
    final DnsMasqConfigCommand command = (DnsMasqConfigCommand) cmd;
    final LinkedList<DhcpConfigEntry> entries = new LinkedList<DhcpConfigEntry>();
    for (final DhcpTO dhcpTo : command.getIps()) {
        final DhcpConfigEntry entry = new DhcpConfigEntry(dhcpTo.getRouterIp(), dhcpTo.getGateway(), dhcpTo.getNetmask(), dhcpTo.getStartIpOfSubnet());
        entries.add(entry);
    }
    return generateConfigItems(new DhcpConfig(entries));
}
Also used : DhcpConfig(com.cloud.agent.resource.virtualnetwork.model.DhcpConfig) DhcpConfigEntry(com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry) DhcpTO(com.cloud.agent.api.to.DhcpTO) LinkedList(java.util.LinkedList) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Example 3 with DnsMasqConfigCommand

use of com.cloud.agent.api.routing.DnsMasqConfigCommand in project cloudstack by apache.

the class VirtualRoutingResourceTest method generateDnsMasqConfigCommand.

protected DnsMasqConfigCommand generateDnsMasqConfigCommand() {
    final List<DhcpTO> dhcps = new ArrayList<>();
    dhcps.add(new DhcpTO("10.1.20.2", "10.1.20.1", "255.255.255.0", "10.1.20.5"));
    dhcps.add(new DhcpTO("10.1.21.2", "10.1.21.1", "255.255.255.0", "10.1.21.5"));
    final DnsMasqConfigCommand cmd = new DnsMasqConfigCommand(dhcps);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
    return cmd;
}
Also used : ArrayList(java.util.ArrayList) DhcpTO(com.cloud.agent.api.to.DhcpTO) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Example 4 with DnsMasqConfigCommand

use of com.cloud.agent.api.routing.DnsMasqConfigCommand in project cloudstack by apache.

the class ConfigHelperTest method testDnsMasqConfig.

@Test
public void testDnsMasqConfig() {
    final DnsMasqConfigCommand command = generateDnsMasqConfigCommand();
    final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(command.getClass());
    final List<ConfigItem> config = configItemFacade.generateConfig(command);
    assertTrue(config.size() > 0);
    final ConfigItem fileConfig = config.get(0);
    assertNotNull(fileConfig);
    assertTrue(fileConfig instanceof FileConfigItem);
    final String fileContents = ((FileConfigItem) fileConfig).getFileContents();
    assertNotNull(fileContents);
    final DhcpConfig jsonClass = gson.fromJson(fileContents, DhcpConfig.class);
    assertNotNull(jsonClass);
    assertEquals(jsonClass.getType(), "dhcpconfig");
    final List<DhcpConfigEntry> entries = jsonClass.getEntries();
    assertNotNull(entries);
    assertTrue(entries.size() == 2);
    assertEquals(entries.get(0).getRouterIpAddress(), "10.1.20.2");
    final ConfigItem scriptConfig = config.get(1);
    assertNotNull(scriptConfig);
    assertTrue(scriptConfig instanceof ScriptConfigItem);
}
Also used : AbstractConfigItemFacade(com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade) DhcpConfig(com.cloud.agent.resource.virtualnetwork.model.DhcpConfig) DhcpConfigEntry(com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand) Test(org.junit.Test)

Example 5 with DnsMasqConfigCommand

use of com.cloud.agent.api.routing.DnsMasqConfigCommand in project cloudstack by apache.

the class ConfigHelperTest method generateDnsMasqConfigCommand.

protected DnsMasqConfigCommand generateDnsMasqConfigCommand() {
    final List<DhcpTO> dhcps = new ArrayList<>();
    dhcps.add(new DhcpTO("10.1.20.2", "10.1.20.1", "255.255.255.0", "10.1.20.5"));
    dhcps.add(new DhcpTO("10.1.21.2", "10.1.21.1", "255.255.255.0", "10.1.21.5"));
    final DnsMasqConfigCommand cmd = new DnsMasqConfigCommand(dhcps);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, ROUTERNAME);
    return cmd;
}
Also used : ArrayList(java.util.ArrayList) DhcpTO(com.cloud.agent.api.to.DhcpTO) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Aggregations

DnsMasqConfigCommand (com.cloud.agent.api.routing.DnsMasqConfigCommand)5 DhcpTO (com.cloud.agent.api.to.DhcpTO)4 ArrayList (java.util.ArrayList)3 DhcpConfig (com.cloud.agent.resource.virtualnetwork.model.DhcpConfig)2 DhcpConfigEntry (com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry)2 AbstractConfigItemFacade (com.cloud.agent.resource.virtualnetwork.facade.AbstractConfigItemFacade)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 NicVO (com.cloud.vm.NicVO)1 NicIpAliasVO (com.cloud.vm.dao.NicIpAliasVO)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1