diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java index bac33397bbb..f66e34b1212 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java @@ -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; @@ -60,6 +64,8 @@ import com.cloud.agent.resource.virtualnetwork.model.ForwardingRules; import com.cloud.agent.resource.virtualnetwork.model.GuestNetwork; import com.cloud.agent.resource.virtualnetwork.model.IcmpAclRule; import com.cloud.agent.resource.virtualnetwork.model.IpAddress; +import com.cloud.agent.resource.virtualnetwork.model.IpAddressAlias; +import com.cloud.agent.resource.virtualnetwork.model.IpAliases; import com.cloud.agent.resource.virtualnetwork.model.IpAssociation; import com.cloud.agent.resource.virtualnetwork.model.NetworkACL; import com.cloud.agent.resource.virtualnetwork.model.ProtocolAclRule; @@ -77,9 +83,6 @@ import com.cloud.network.LoadBalancerConfigurator; import com.cloud.network.rules.FirewallRule; 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; @@ -91,7 +94,7 @@ public class ConfigHelper { public static List generateCommandCfg(NetworkElementCommand cmd) { List cfg; if (cmd instanceof SetPortForwardingRulesVpcCommand) { - cfg = generateConfig((SetPortForwardingRulesVpcCommand)cmd); + cfg = generateConfig((SetPortForwardingRulesVpcCommand)cmd); // Migrated } else if (cmd instanceof SetPortForwardingRulesCommand) { cfg = generateConfig((SetPortForwardingRulesCommand)cmd); // Migrated } else if (cmd instanceof SetStaticRouteCommand) { @@ -105,11 +108,11 @@ public class ConfigHelper { } else if (cmd instanceof DhcpEntryCommand) { cfg = generateConfig((DhcpEntryCommand)cmd); // Migrated } else if (cmd instanceof CreateIpAliasCommand) { - cfg = generateConfig((CreateIpAliasCommand)cmd); + cfg = generateConfig((CreateIpAliasCommand)cmd); // Migrated } else if (cmd instanceof DnsMasqConfigCommand) { cfg = generateConfig((DnsMasqConfigCommand)cmd); } else if (cmd instanceof DeleteIpAliasCommand) { - cfg = generateConfig((DeleteIpAliasCommand)cmd); + cfg = generateConfig((DeleteIpAliasCommand)cmd); // Migrated } else if (cmd instanceof VmDataCommand) { cfg = generateConfig((VmDataCommand)cmd); // Migrated } else if (cmd instanceof SetFirewallRulesCommand) { @@ -320,48 +323,34 @@ public class ConfigHelper { } private static List generateConfig(CreateIpAliasCommand cmd) { - LinkedList cfg = new LinkedList<>(); - + List ipAliases = new LinkedList(); List ipAliasTOs = cmd.getIpAliasList(); - StringBuilder args = new StringBuilder(); for (IpAliasTO ipaliasto : ipAliasTOs) { - args.append(ipaliasto.getAlias_count()); - args.append(':'); - args.append(ipaliasto.getRouterip()); - args.append(':'); - args.append(ipaliasto.getNetmask()); - args.append('-'); + IpAddressAlias alias = new IpAddressAlias(false, ipaliasto.getRouterip(), ipaliasto.getNetmask(), Long.parseLong(ipaliasto.getAlias_count())); + ipAliases.add(alias); } - cfg.add(new ScriptConfigItem(VRScripts.IPALIAS_CREATE, args.toString())); - return cfg; + + IpAliases ipAliasList = new IpAliases(ipAliases); + return generateConfigItems(ipAliasList); } private static List generateConfig(DeleteIpAliasCommand cmd) { - LinkedList cfg = new LinkedList<>(); + List ipAliases = new LinkedList(); - StringBuffer buff = new StringBuffer(); List revokedIpAliasTOs = cmd.getDeleteIpAliasTos(); for (IpAliasTO ipAliasTO : revokedIpAliasTOs) { - buff.append(ipAliasTO.getAlias_count()); - buff.append(":"); - buff.append(ipAliasTO.getRouterip()); - buff.append(":"); - buff.append(ipAliasTO.getNetmask()); - buff.append("-"); + IpAddressAlias alias = new IpAddressAlias(true, ipAliasTO.getRouterip(), ipAliasTO.getNetmask(), Long.parseLong(ipAliasTO.getAlias_count())); + ipAliases.add(alias); } - //this is to ensure that thre is some argument passed to the deleteipAlias script when there are no revoked rules. - buff.append("- "); + List activeIpAliasTOs = cmd.getCreateIpAliasTos(); for (IpAliasTO ipAliasTO : activeIpAliasTOs) { - buff.append(ipAliasTO.getAlias_count()); - buff.append(":"); - buff.append(ipAliasTO.getRouterip()); - buff.append(":"); - buff.append(ipAliasTO.getNetmask()); - buff.append("-"); + IpAddressAlias alias = new IpAddressAlias(false, ipAliasTO.getRouterip(), ipAliasTO.getNetmask(), Long.parseLong(ipAliasTO.getAlias_count())); + ipAliases.add(alias); } - cfg.add(new ScriptConfigItem(VRScripts.IPALIAS_DELETE, buff.toString())); - return cfg; + + IpAliases ipAliasList = new IpAliases(ipAliases); + return generateConfigItems(ipAliasList); } private static List generateConfig(DnsMasqConfigCommand cmd) { diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java index 4b8b4cbc2e7..462af81a7f5 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java @@ -30,6 +30,7 @@ public abstract class ConfigBase { public static final String FORWARDING_RULES = "forwardrules"; public static final String VPN_USER_LIST = "vpnuserlist"; public static final String STATICNAT_RULES = "staticnatrules"; + public static final String IP_ALIAS_CONFIG = "ipaliases"; private String type = UNKNOWN; diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAddressAlias.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAddressAlias.java new file mode 100644 index 00000000000..f3b3e833af9 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAddressAlias.java @@ -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 IpAddressAlias { + private boolean revoke; + private String IpAddress; + private String netmask; + private long count; + + public IpAddressAlias() { + // Empty constructor for (de)serialization + } + + public IpAddressAlias(boolean revoke, String ipAddress, String netmask, long count) { + super(); + this.revoke = revoke; + IpAddress = ipAddress; + this.netmask = netmask; + this.count = count; + } + + public boolean isRevoke() { + return revoke; + } + + public void setRevoke(boolean revoke) { + this.revoke = revoke; + } + + public String getIpAddress() { + return IpAddress; + } + + public void setIpAddress(String ipAddress) { + IpAddress = ipAddress; + } + + public String getNetmask() { + return netmask; + } + + public void setNetmask(String netmask) { + this.netmask = netmask; + } + + public long getCount() { + return count; + } + + public void setCount(long count) { + this.count = count; + } + +} diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAliases.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAliases.java new file mode 100644 index 00000000000..b7dde70de05 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/IpAliases.java @@ -0,0 +1,44 @@ +// +// 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.List; + +public class IpAliases extends ConfigBase { + List aliases; + + public IpAliases() { + super(ConfigBase.IP_ALIAS_CONFIG); + } + + public IpAliases(List aliases) { + super(ConfigBase.IP_ALIAS_CONFIG); + this.aliases = aliases; + } + + public List getAliases() { + return aliases; + } + + public void setAliases(List aliases) { + this.aliases = aliases; + } + +}