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);
}
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));
}
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;
}
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);
}
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;
}
Aggregations