Skip to content

Commit

Permalink
Staticroutes to new json style
Browse files Browse the repository at this point in the history
  • Loading branch information
spark404 authored and wilderrodrigues committed Mar 16, 2015
1 parent 58919dc commit caef7ee
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 10 deletions.
22 changes: 12 additions & 10 deletions core/src/com/cloud/agent/resource/virtualnetwork/ConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
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;
Expand All @@ -82,6 +84,7 @@
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;

Expand All @@ -99,7 +102,7 @@ public static List<ConfigItem> generateCommandCfg(NetworkElementCommand cmd) {
} 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) {
Expand Down Expand Up @@ -489,19 +492,18 @@ private static List<ConfigItem> generateConfig(SetSourceNatCommand cmd) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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:https://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;
}

}
Original file line number Diff line number Diff line change
@@ -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:https://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;
}

}

0 comments on commit caef7ee

Please sign in to comment.