mirror of https://github.com/apache/cloudstack.git
modified StaticNatRule to use the new style
This commit is contained in:
parent
fac3bdecd2
commit
660fdbe238
|
|
@ -63,6 +63,8 @@ import com.cloud.agent.resource.virtualnetwork.model.IpAddress;
|
|||
import com.cloud.agent.resource.virtualnetwork.model.IpAssociation;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.NetworkACL;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.ProtocolAclRule;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.StaticNatRule;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.StaticNatRules;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.TcpAclRule;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.UdpAclRule;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.VmData;
|
||||
|
|
@ -91,11 +93,11 @@ public class ConfigHelper {
|
|||
if (cmd instanceof SetPortForwardingRulesVpcCommand) {
|
||||
cfg = generateConfig((SetPortForwardingRulesVpcCommand)cmd);
|
||||
} else if (cmd instanceof SetPortForwardingRulesCommand) {
|
||||
cfg = generateConfig((SetPortForwardingRulesCommand)cmd);
|
||||
cfg = generateConfig((SetPortForwardingRulesCommand)cmd); // Migrated
|
||||
} else if (cmd instanceof SetStaticRouteCommand) {
|
||||
cfg = generateConfig((SetStaticRouteCommand)cmd);
|
||||
} else if (cmd instanceof SetStaticNatRulesCommand) {
|
||||
cfg = generateConfig((SetStaticNatRulesCommand)cmd);
|
||||
cfg = generateConfig((SetStaticNatRulesCommand)cmd); // Migrated
|
||||
} else if (cmd instanceof LoadBalancerConfigCommand) {
|
||||
cfg = generateConfig((LoadBalancerConfigCommand)cmd);
|
||||
} else if (cmd instanceof SavePasswordCommand) {
|
||||
|
|
@ -227,34 +229,15 @@ public class ConfigHelper {
|
|||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(SetStaticNatRulesCommand cmd) {
|
||||
LinkedList<ConfigItem> cfg = new LinkedList<>();
|
||||
if (cmd.getVpcId() != null) {
|
||||
for (StaticNatRuleTO rule : cmd.getRules()) {
|
||||
String args = rule.revoked() ? " -D" : " -A";
|
||||
args += " -l " + rule.getSrcIp();
|
||||
args += " -r " + rule.getDstIp();
|
||||
|
||||
cfg.add(new ScriptConfigItem(VRScripts.VPC_STATIC_NAT, args));
|
||||
}
|
||||
} else {
|
||||
for (StaticNatRuleTO rule : cmd.getRules()) {
|
||||
//1:1 NAT needs instanceip;publicip;domrip;op
|
||||
StringBuilder args = new StringBuilder();
|
||||
args.append(rule.revoked() ? " -D " : " -A ");
|
||||
args.append(" -l ").append(rule.getSrcIp());
|
||||
args.append(" -r ").append(rule.getDstIp());
|
||||
|
||||
if (rule.getProtocol() != null) {
|
||||
args.append(" -P ").append(rule.getProtocol().toLowerCase());
|
||||
}
|
||||
|
||||
args.append(" -d ").append(rule.getStringSrcPortRange());
|
||||
args.append(" -G ");
|
||||
|
||||
cfg.add(new ScriptConfigItem(VRScripts.FIREWALL_NAT, args.toString()));
|
||||
}
|
||||
LinkedList<StaticNatRule> rules = new LinkedList<>();
|
||||
for (StaticNatRuleTO rule : cmd.getRules()) {
|
||||
StaticNatRule staticNatRule = new StaticNatRule(rule.revoked(), rule.getProtocol(), rule.getSrcIp(), rule.getStringSrcPortRange(), rule.getDstIp());
|
||||
rules.add(staticNatRule);
|
||||
}
|
||||
return cfg;
|
||||
StaticNatRules staticNatRules = new StaticNatRules(rules);
|
||||
|
||||
return generateConfigItems(staticNatRules);
|
||||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(LoadBalancerConfigCommand cmd) {
|
||||
|
|
@ -603,6 +586,9 @@ public class ConfigHelper {
|
|||
case ConfigBase.NETWORK_ACL:
|
||||
destinationFile = VRScripts.NETWORK_ACL_CONFIG;
|
||||
break;
|
||||
case ConfigBase.STATICNAT_RULES:
|
||||
destinationFile = VRScripts.STATICNAT_RULES_CONFIG;
|
||||
break;
|
||||
case ConfigBase.VM_DHCP:
|
||||
destinationFile = VRScripts.VM_DHCP_CONFIG;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public class VRScripts {
|
|||
protected final static String VM_PASSWORD_CONFIG = "vm_password.json";
|
||||
protected static final String FORWARDING_RULES_CONFIG = "forwarding_rules.json";
|
||||
protected static final String VPN_USER_LIST_CONFIG = "vpn_user_list.json";
|
||||
protected static final String STATICNAT_RULES_CONFIG = "staticnat_rules.json";
|
||||
|
||||
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
|
||||
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public abstract class ConfigBase {
|
|||
public static final String VM_PASSWORD = "vmpassword";
|
||||
public static final String FORWARDING_RULES = "forwardrules";
|
||||
public static final String VPN_USER_LIST = "vpnuserlist";
|
||||
public static final String STATICNAT_RULES = "staticnatrules";
|
||||
|
||||
private String type = UNKNOWN;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// 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 StaticNatRule {
|
||||
private boolean revoke;
|
||||
private String protocol;
|
||||
private String sourceIpAddress;
|
||||
private String sourcePortRange;
|
||||
private String destinationIpAddress;
|
||||
|
||||
public StaticNatRule() {
|
||||
// Empty constructor for (de)serialization
|
||||
}
|
||||
|
||||
public StaticNatRule(boolean revoke, String protocol, String sourceIpAddress, String sourcePortRange, String destinationIpAddress) {
|
||||
super();
|
||||
this.revoke = revoke;
|
||||
this.protocol = protocol;
|
||||
this.sourceIpAddress = sourceIpAddress;
|
||||
this.sourcePortRange = sourcePortRange;
|
||||
this.destinationIpAddress = destinationIpAddress;
|
||||
}
|
||||
|
||||
public boolean isRevoke() {
|
||||
return revoke;
|
||||
}
|
||||
|
||||
public void setRevoke(boolean revoke) {
|
||||
this.revoke = revoke;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getSourceIpAddress() {
|
||||
return sourceIpAddress;
|
||||
}
|
||||
|
||||
public void setSourceIpAddress(String sourceIpAddress) {
|
||||
this.sourceIpAddress = sourceIpAddress;
|
||||
}
|
||||
|
||||
public String getSourcePortRange() {
|
||||
return sourcePortRange;
|
||||
}
|
||||
|
||||
public void setSourcePortRange(String sourcePortRange) {
|
||||
this.sourcePortRange = sourcePortRange;
|
||||
}
|
||||
|
||||
public String getDestinationIpAddress() {
|
||||
return destinationIpAddress;
|
||||
}
|
||||
|
||||
public void setDestinationIpAddress(String destinationIpAddress) {
|
||||
this.destinationIpAddress = destinationIpAddress;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 StaticNatRules extends ConfigBase {
|
||||
private List<StaticNatRule> rules;
|
||||
|
||||
public StaticNatRules() {
|
||||
super(ConfigBase.STATICNAT_RULES);
|
||||
}
|
||||
|
||||
public StaticNatRules(List<StaticNatRule> rules) {
|
||||
super(ConfigBase.STATICNAT_RULES);
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
public List<StaticNatRule> getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public void setRules(List<StaticNatRule> rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue