Staticroutes to new json style

This commit is contained in:
Hugo Trippaers 2014-08-12 11:59:56 +02:00 committed by wilderrodrigues
parent 58919dcf50
commit caef7ee9a9
4 changed files with 129 additions and 10 deletions

View File

@ -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<ConfigItem> generateConfig(SetStaticRouteCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
LinkedList<StaticRoute> 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<ConfigItem> generateConfig(IpAssocCommand cmd) {

View File

@ -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;

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 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;
}
}

View File

@ -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<StaticRoute> routes;
public StaticRoutes() {
super(ConfigBase.STATIC_ROUTES);
}
public StaticRoutes(List<StaticRoute> routes) {
super(ConfigBase.STATIC_ROUTES);
this.routes = routes;
}
public List<StaticRoute> getRoutes() {
return routes;
}
public void setRoutes(List<StaticRoute> routes) {
this.routes = routes;
}
}