diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java index a1a5b9d0678..a39da1e0bc2 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java @@ -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 generateConfig(SetupGuestNetworkCommand cmd) { - LinkedList 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 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 generateConfig(SetSourceNatCommand cmd) { LinkedList 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; } diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java index cdf43281e69..9798fa88dd3 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VRScripts.java @@ -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 diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java new file mode 100644 index 00000000000..9bb59d7889c --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java @@ -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; + } + +} diff --git a/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java b/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java index e6a627486fb..6b2e5a696c5 100644 --- a/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java +++ b/core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java @@ -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