Search in sources :

Example 1 with DhcpTO

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));
}
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 2 with DhcpTO

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;
}
Also used : ArrayList(java.util.ArrayList) DhcpTO(com.cloud.agent.api.to.DhcpTO) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Example 3 with DhcpTO

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);
}
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 4 with DhcpTO

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;
}
Also used : ArrayList(java.util.ArrayList) DhcpTO(com.cloud.agent.api.to.DhcpTO) DnsMasqConfigCommand(com.cloud.agent.api.routing.DnsMasqConfigCommand)

Example 5 with DhcpTO

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);
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) SetPortForwardingRulesAnswer(com.cloud.agent.api.routing.SetPortForwardingRulesAnswer) SetSourceNatAnswer(com.cloud.agent.api.routing.SetSourceNatAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) GetVmConfigAnswer(com.cloud.agent.api.GetVmConfigAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) SetFirewallRulesAnswer(com.cloud.agent.api.routing.SetFirewallRulesAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) SetStaticRouteAnswer(com.cloud.agent.api.routing.SetStaticRouteAnswer) DhcpTO(com.cloud.agent.api.to.DhcpTO)

Aggregations

DhcpTO (com.cloud.agent.api.to.DhcpTO)5 DnsMasqConfigCommand (com.cloud.agent.api.routing.DnsMasqConfigCommand)4 ArrayList (java.util.ArrayList)3 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 GetVmConfigAnswer (com.cloud.agent.api.GetVmConfigAnswer)1 NetworkUsageAnswer (com.cloud.agent.api.NetworkUsageAnswer)1 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)1 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)1 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)1 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)1 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)1 SetFirewallRulesAnswer (com.cloud.agent.api.routing.SetFirewallRulesAnswer)1 SetPortForwardingRulesAnswer (com.cloud.agent.api.routing.SetPortForwardingRulesAnswer)1 SetSourceNatAnswer (com.cloud.agent.api.routing.SetSourceNatAnswer)1 SetStaticNatRulesAnswer (com.cloud.agent.api.routing.SetStaticNatRulesAnswer)1 SetStaticRouteAnswer (com.cloud.agent.api.routing.SetStaticRouteAnswer)1 DhcpConfig (com.cloud.agent.resource.virtualnetwork.model.DhcpConfig)1