New style dnsmasq configuration

This commit is contained in:
Hugo Trippaers 2014-08-12 15:00:55 +02:00 committed by wilderrodrigues
parent 4c5f4a1f9f
commit d2e3b238ed
5 changed files with 141 additions and 18 deletions

View File

@ -23,6 +23,10 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.cloud.agent.api.BumpUpPriorityCommand;
import com.cloud.agent.api.SetupGuestNetworkCommand;
import com.cloud.agent.api.routing.CreateIpAliasCommand;
@ -55,6 +59,8 @@ import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.agent.resource.virtualnetwork.model.AclRule;
import com.cloud.agent.resource.virtualnetwork.model.AllAclRule;
import com.cloud.agent.resource.virtualnetwork.model.ConfigBase;
import com.cloud.agent.resource.virtualnetwork.model.DhcpConfig;
import com.cloud.agent.resource.virtualnetwork.model.DhcpConfigEntry;
import com.cloud.agent.resource.virtualnetwork.model.ForwardingRule;
import com.cloud.agent.resource.virtualnetwork.model.ForwardingRules;
import com.cloud.agent.resource.virtualnetwork.model.GuestNetwork;
@ -85,9 +91,6 @@ import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class ConfigHelper {
private final static Gson gson;
@ -115,7 +118,7 @@ public class ConfigHelper {
} else if (cmd instanceof CreateIpAliasCommand) {
cfg = generateConfig((CreateIpAliasCommand)cmd); // Migrated
} else if (cmd instanceof DnsMasqConfigCommand) {
cfg = generateConfig((DnsMasqConfigCommand)cmd);
cfg = generateConfig((DnsMasqConfigCommand)cmd); // Migrated
} else if (cmd instanceof DeleteIpAliasCommand) {
cfg = generateConfig((DeleteIpAliasCommand)cmd); // Migrated
} else if (cmd instanceof VmDataCommand) {
@ -336,22 +339,14 @@ public class ConfigHelper {
}
private static List<ConfigItem> generateConfig(DnsMasqConfigCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
LinkedList<DhcpConfigEntry> entries = new LinkedList<DhcpConfigEntry>();
List<DhcpTO> dhcpTos = cmd.getIps();
StringBuffer buff = new StringBuffer();
for (DhcpTO dhcpTo : dhcpTos) {
buff.append(dhcpTo.getRouterIp());
buff.append(":");
buff.append(dhcpTo.getGateway());
buff.append(":");
buff.append(dhcpTo.getNetmask());
buff.append(":");
buff.append(dhcpTo.getStartIpOfSubnet());
buff.append("-");
for (DhcpTO dhcpTo : cmd.getIps()) {
DhcpConfigEntry entry = new DhcpConfigEntry(dhcpTo.getRouterIp(), dhcpTo.getGateway(), dhcpTo.getNetmask(), dhcpTo.getStartIpOfSubnet());
entries.add(entry);
}
cfg.add(new ScriptConfigItem(VRScripts.DNSMASQ_CONFIG, buff.toString()));
return cfg;
return generateConfigItems(new DhcpConfig(entries));
}
private static List<ConfigItem> generateConfig(BumpUpPriorityCommand cmd) {
@ -535,6 +530,14 @@ public class ConfigHelper {
break;
case ConfigBase.MONITORSERVICE:
destinationFile = VRScripts.MONITOR_SERVICE_CONFIG;
case ConfigBase.STATIC_ROUTES:
destinationFile = VRScripts.STATIC_ROUTES_CONFIG;
break;
case ConfigBase.DHCP_CONFIG:
destinationFile = VRScripts.DHCP_CONFIG;
break;
case ConfigBase.IP_ALIAS_CONFIG:
destinationFile = VRScripts.IP_ALIAS_CONFIG;
break;
default:
throw new CloudRuntimeException("Unable to process the configuration for " + configuration.getType());

View File

@ -34,6 +34,8 @@ public class VRScripts {
protected static final String STATIC_ROUTES_CONFIG = "static_routes.json";
protected static final String REMOTE_ACCESS_VPN_CONFIG = "remote_access_vpn.json";
protected static final String MONITOR_SERVICE_CONFIG = "monitor_service.json";
protected static final String DHCP_CONFIG = "dhcp.json";
protected static final String IP_ALIAS_CONFIG = "ip_aliases.json";
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds

View File

@ -35,6 +35,7 @@ public abstract class ConfigBase {
public static final String STATIC_ROUTES = "staticroutes";
public static final String REMOTEACCESSVPN = "remoteaccessvpn";
public static final String MONITORSERVICE = "monitorservice";
public static final String DHCP_CONFIG = "dhcpconfig";
private String type = UNKNOWN;

View File

@ -0,0 +1,45 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
package com.cloud.agent.resource.virtualnetwork.model;
import java.util.LinkedList;
import java.util.List;
public class DhcpConfig extends ConfigBase {
List<DhcpConfigEntry> entries = new LinkedList<DhcpConfigEntry>();
public DhcpConfig() {
super(ConfigBase.DHCP_CONFIG);
}
public DhcpConfig(List<DhcpConfigEntry> entries) {
super(ConfigBase.DHCP_CONFIG);
this.entries = entries;
}
public List<DhcpConfigEntry> getEntries() {
return entries;
}
public void setEntries(List<DhcpConfigEntry> entries) {
this.entries = entries;
}
}

View File

@ -0,0 +1,72 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
package com.cloud.agent.resource.virtualnetwork.model;
public class DhcpConfigEntry {
private String routerIpAddress;
private String gateway;
private String netmask;
private String firstIpOfSubnet;
public DhcpConfigEntry() {
// Empty for (de)serialization
}
public DhcpConfigEntry(String routerIpAddress, String gateway, String netmask, String firstIpOfSubnet) {
super();
this.routerIpAddress = routerIpAddress;
this.gateway = gateway;
this.netmask = netmask;
this.firstIpOfSubnet = firstIpOfSubnet;
}
public String getRouterIpAddress() {
return routerIpAddress;
}
public void setRouterIpAddress(String routerIpAddress) {
this.routerIpAddress = routerIpAddress;
}
public String getGateway() {
return gateway;
}
public void setGateway(String gateway) {
this.gateway = gateway;
}
public String getNetmask() {
return netmask;
}
public void setNetmask(String netmask) {
this.netmask = netmask;
}
public String getFirstIpOfSubnet() {
return firstIpOfSubnet;
}
public void setFirstIpOfSubnet(String firstIpOfSubnet) {
this.firstIpOfSubnet = firstIpOfSubnet;
}
}