use of com.cloud.agent.api.to.DhcpTO 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.to.DhcpTO 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.to.DhcpTO 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.to.DhcpTO 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;
}
use of com.cloud.agent.api.to.DhcpTO in project cloudstack by apache.
the class HypervDirectConnectResource method execute.
protected Answer execute(final DnsMasqConfigCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing dnsmasqConfig command: " + s_gson.toJson(cmd));
}
final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
final String controlIp = getRouterSshControlIp(cmd);
assert controlIp != null;
final List<DhcpTO> dhcpTos = cmd.getIps();
final StringBuilder args = new StringBuilder();
for (final DhcpTO dhcpTo : dhcpTos) {
args.append(dhcpTo.getRouterIp());
args.append(":");
args.append(dhcpTo.getGateway());
args.append(":");
args.append(dhcpTo.getNetmask());
args.append(":");
args.append(dhcpTo.getStartIpOfSubnet());
args.append("-");
}
try {
final String command = String.format("%s%s %s", "/root/", VRScripts.DHCP, args);
final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Run command on domain router " + routerIp + ", /root/dnsmasq.sh");
}
if (!result.first()) {
s_logger.error("Unable update dnsmasq config file");
return new Answer(cmd, false, "dnsmasq config update failed due to: " + result.second());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("dnsmasq config command on domain router " + routerIp + " completed");
}
} catch (final Throwable e) {
final String msg = "Dnsmasqconfig command failed due to " + e.getMessage();
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
}
return new Answer(cmd);
}
Aggregations