diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java index dcc8f472c26..f02658cb800 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java @@ -72,6 +72,8 @@ import com.cloud.agent.resource.virtualnetwork.model.ProtocolAclRule; import com.cloud.agent.resource.virtualnetwork.model.Site2SiteVpn; import com.cloud.agent.resource.virtualnetwork.model.StaticNatRule; import com.cloud.agent.resource.virtualnetwork.model.StaticNatRules; +import com.cloud.agent.resource.virtualnetwork.model.StaticRoute; +import com.cloud.agent.resource.virtualnetwork.model.StaticRoutes; import com.cloud.agent.resource.virtualnetwork.model.TcpAclRule; import com.cloud.agent.resource.virtualnetwork.model.UdpAclRule; import com.cloud.agent.resource.virtualnetwork.model.VmData; @@ -82,6 +84,7 @@ import com.cloud.agent.resource.virtualnetwork.model.VpnUserList; import com.cloud.network.HAProxyConfigurator; import com.cloud.network.LoadBalancerConfigurator; import com.cloud.network.rules.FirewallRule; +import com.cloud.network.vpc.StaticRouteProfile; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; @@ -99,7 +102,7 @@ public class ConfigHelper { } else if (cmd instanceof SetPortForwardingRulesCommand) { cfg = generateConfig((SetPortForwardingRulesCommand)cmd); // Migrated } else if (cmd instanceof SetStaticRouteCommand) { - cfg = generateConfig((SetStaticRouteCommand)cmd); + cfg = generateConfig((SetStaticRouteCommand)cmd); // Migrated } else if (cmd instanceof SetStaticNatRulesCommand) { cfg = generateConfig((SetStaticNatRulesCommand)cmd); // Migrated } else if (cmd instanceof LoadBalancerConfigCommand) { @@ -489,19 +492,18 @@ public class ConfigHelper { } private static List generateConfig(SetStaticRouteCommand cmd) { - LinkedList cfg = new LinkedList<>(); + LinkedList routes = new LinkedList<>(); - String[] rules = cmd.generateSRouteRules(); - StringBuilder sb = new StringBuilder(); + for (StaticRouteProfile profile : cmd.getStaticRoutes()) { + String cidr = profile.getCidr(); + String subnet = NetUtils.getCidrSubNet(cidr); + String cidrSize = cidr.split("\\/")[1]; + boolean keep = profile.getState() == com.cloud.network.vpc.StaticRoute.State.Active || profile.getState() == com.cloud.network.vpc.StaticRoute.State.Add; - for (int i = 0; i < rules.length; i++) { - sb.append(rules[i]).append(','); + routes.add(new StaticRoute(!keep, profile.getIp4Address(), profile.getGateway(), subnet + "/" + cidrSize)); } - String args = " -a " + sb.toString(); - - cfg.add(new ScriptConfigItem(VRScripts.VPC_STATIC_ROUTE, args)); - return cfg; + return generateConfigItems(new StaticRoutes(routes)); } private static List generateConfig(IpAssocCommand 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 5af1dd092d3..8cecf8874cc 100644 --- a/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java @@ -32,6 +32,7 @@ public abstract class ConfigBase { public static final String STATICNAT_RULES = "staticnatrules"; public static final String IP_ALIAS_CONFIG = "ipaliases"; public static final String SITE2SITEVPN = "site2sitevpn"; + public static final String STATIC_ROUTES = "staticroutes"; private String type = UNKNOWN; diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/StaticRoute.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/StaticRoute.java new file mode 100644 index 00000000000..31ae8505db7 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/StaticRoute.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 StaticRoute { + private boolean revoke; + private String ipAddress; + private String gateway; + private String network; + + public StaticRoute() { + // Empty constructor for (de)serialization + } + + public StaticRoute(boolean revoke, String ipAddress, String gateway, String network) { + super(); + this.revoke = revoke; + this.ipAddress = ipAddress; + this.gateway = gateway; + this.network = network; + } + + public boolean isRevoke() { + return revoke; + } + + public void setRevoke(boolean revoke) { + this.revoke = revoke; + } + + public String getIpAddress() { + return ipAddress; + } + + public void setIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + } + + public String getGateway() { + return gateway; + } + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + public String getNetwork() { + return network; + } + + public void setNetwork(String network) { + this.network = network; + } + +} diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/model/StaticRoutes.java b/core/src/com/cloud/agent/resource/virtualnetwork/model/StaticRoutes.java new file mode 100644 index 00000000000..e05e8d17242 --- /dev/null +++ b/core/src/com/cloud/agent/resource/virtualnetwork/model/StaticRoutes.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 StaticRoutes extends ConfigBase { + private List routes; + + public StaticRoutes() { + super(ConfigBase.STATIC_ROUTES); + } + + public StaticRoutes(List routes) { + super(ConfigBase.STATIC_ROUTES); + this.routes = routes; + } + + public List getRoutes() { + return routes; + } + + public void setRoutes(List routes) { + this.routes = routes; + } + +}