Replace CreateGuestNetwork config script with a json file.

This commit is contained in:
Hugo Trippaers 2014-07-29 15:44:31 +02:00 committed by wilderrodrigues
parent 8d9a4be9dd
commit 639b24a575
4 changed files with 149 additions and 36 deletions

View File

@ -56,10 +56,10 @@ import com.cloud.agent.api.routing.VmDataCommand;
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
import com.cloud.agent.api.to.DhcpTO;
import com.cloud.agent.api.to.FirewallRuleTO;
import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.PortForwardingRuleTO;
import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.agent.resource.virtualnetwork.model.GuestNetwork;
import com.cloud.network.HAProxyConfigurator;
import com.cloud.network.LoadBalancerConfigurator;
import com.cloud.network.rules.FirewallRule;
@ -511,12 +511,11 @@ public class ConfigHelper {
}
private static List<ConfigItem> generateConfig(SetupGuestNetworkCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
NicTO nic = cmd.getNic();
String routerGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
String gateway = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
String netmask = NetUtils.getSubNet(routerGIP, nic.getNetmask());
String domainName = cmd.getNetworkDomain();
String dns = cmd.getDefaultDns1();
@ -529,30 +528,17 @@ public class ConfigHelper {
}
}
String dev = "eth" + nic.getDeviceId();
String netmask = NetUtils.getSubNet(routerGIP, nic.getNetmask());
String args = "";
if (cmd.isAdd() == false) {
//pass the argument to script to delete the network
args += " -D";
} else {
// pass create option argument if the ip needs to be added to eth device
args += " -C";
}
args += " -M " + nic.getMac();
args += " -d " + dev;
args += " -i " + routerGIP;
args += " -g " + gateway;
args += " -m " + cidr;
args += " -n " + netmask;
if (dns != null && !dns.isEmpty()) {
args += " -s " + dns;
}
if (domainName != null && !domainName.isEmpty()) {
args += " -e " + domainName;
}
GuestNetwork guestNetwork = new GuestNetwork(cmd.isAdd(), nic.getMac(), "eth" + nic.getDeviceId(), routerGIP, netmask, gateway,
cidr, dns, domainName);
LinkedList<ConfigItem> cfg = new LinkedList<>();
ConfigItem guestNetworkConfig = new FileConfigItem(VRScripts.CONFIG_PERSIST_LOCATION, VRScripts.GUEST_NETWORK_CONFIG, gson.toJson(guestNetwork));
cfg.add(guestNetworkConfig);
ConfigItem updateGuestNetwork = new ScriptConfigItem(VRScripts.UPDATE_CONFIG, VRScripts.GUEST_NETWORK_CONFIG);
cfg.add(updateGuestNetwork);
cfg.add(new ScriptConfigItem(VRScripts.VPC_GUEST_NETWORK, args));
return cfg;
}
@ -593,15 +579,17 @@ public class ConfigHelper {
private static List<ConfigItem> generateConfig(SetSourceNatCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
IpAddressTO pubIP = cmd.getIpAddress();
String dev = "eth" + pubIP.getNicDevId();
String args = "-A";
args += " -l ";
args += pubIP.getPublicIp();
args += " -c ";
args += dev;
/* FIXME This seems useless as we already pass this info with the ipassoc
* IpAddressTO pubIP = cmd.getIpAddress();
* String dev = "eth" + pubIP.getNicDevId();
* String args = "-A";
* args += " -l ";
* args += pubIP.getPublicIp();
* args += " -c ";
* args += dev;
* cfg.add(new ScriptConfigItem(VRScripts.VPC_SOURCE_NAT, args));
*/
cfg.add(new ScriptConfigItem(VRScripts.VPC_SOURCE_NAT, args));
return cfg;
}

View File

@ -22,6 +22,7 @@ package com.cloud.agent.resource.virtualnetwork;
public class VRScripts {
protected final static String CONFIG_PERSIST_LOCATION = "/etc/cloudstack/";
protected final static String IP_ASSOCIATION_CONFIG = "ip_associations.json";
protected final static String GUEST_NETWORK_CONFIG = "guest_network.json";
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds

View File

@ -0,0 +1,123 @@
//
// 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 GuestNetwork {
private boolean add;
private String macAddress;
private String device;
private String routerGuestIp;
private String routerGuestNetmask;
private String routerGuestGateway;
private String cidr;
private String dns;
private String domainName;
public GuestNetwork() {
// Empty constructor for (de)serialization
}
public GuestNetwork(boolean add, String macAddress, String device, String routerGuestIp, String routerGuestNetmask, String routerGuestGateway, String cidr, String dns,
String domainName) {
super();
this.add = add;
this.macAddress = macAddress;
this.device = device;
this.routerGuestIp = routerGuestIp;
this.routerGuestNetmask = routerGuestNetmask;
this.routerGuestGateway = routerGuestGateway;
this.cidr = cidr;
this.dns = dns;
this.domainName = domainName;
}
public boolean isAdd() {
return add;
}
public void setAdd(boolean add) {
this.add = add;
}
public String getMacAddress() {
return macAddress;
}
public void setMacAddress(String macAddress) {
this.macAddress = macAddress;
}
public String getDevice() {
return device;
}
public void setDevice(String device) {
this.device = device;
}
public String getRouterGuestIp() {
return routerGuestIp;
}
public void setRouterGuestIp(String routerGuestIp) {
this.routerGuestIp = routerGuestIp;
}
public String getRouterGuestNetmask() {
return routerGuestNetmask;
}
public void setRouterGuestNetmask(String routerGuestNetmask) {
this.routerGuestNetmask = routerGuestNetmask;
}
public String getRouterGuestGateway() {
return routerGuestGateway;
}
public void setRouterGuestGateway(String routerGuestGateway) {
this.routerGuestGateway = routerGuestGateway;
}
public String getCidr() {
return cidr;
}
public void setCidr(String cidr) {
this.cidr = cidr;
}
public String getDns() {
return dns;
}
public void setDns(String dns) {
this.dns = dns;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
}

View File

@ -528,8 +528,9 @@ public class VirtualRoutingResourceTest implements VirtualRouterDeployer {
}
private void verifyArgs(SetupGuestNetworkCommand cmd, String script, String args) {
assertEquals(script, VRScripts.VPC_GUEST_NETWORK);
assertEquals(args, " -C -M 01:23:45:67:89:AB -d eth4 -i 10.1.1.2 -g 10.1.1.1 -m 24 -n 10.1.1.0 -s 8.8.8.8,8.8.4.4 -e cloud.test");
// TODO Check the contents of the json file
//assertEquals(script, VRScripts.VPC_GUEST_NETWORK);
//assertEquals(args, " -C -M 01:23:45:67:89:AB -d eth4 -i 10.1.1.2 -g 10.1.1.1 -m 24 -n 10.1.1.0 -s 8.8.8.8,8.8.4.4 -e cloud.test");
}
@Test