mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Add forwarding rules to the new config format and do a little rewrite on
the models
This commit is contained in:
parent
712fa9c92c
commit
6ae56b7275
@ -59,6 +59,8 @@ import com.cloud.agent.api.to.StaticNatRuleTO;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.AclRule;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.AllAclRule;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.ConfigBase;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.ForwardingRule;
|
||||
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;
|
||||
@ -214,20 +216,17 @@ public class ConfigHelper {
|
||||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(SetPortForwardingRulesCommand cmd) {
|
||||
LinkedList<ConfigItem> cfg = new LinkedList<>();
|
||||
List<ForwardingRule> rules = new ArrayList<ForwardingRule>();
|
||||
|
||||
for (PortForwardingRuleTO rule : cmd.getRules()) {
|
||||
StringBuilder args = new StringBuilder();
|
||||
args.append(rule.revoked() ? "-D" : "-A");
|
||||
args.append(" -P ").append(rule.getProtocol().toLowerCase());
|
||||
args.append(" -l ").append(rule.getSrcIp());
|
||||
args.append(" -p ").append(rule.getStringSrcPortRange());
|
||||
args.append(" -r ").append(rule.getDstIp());
|
||||
args.append(" -d ").append(rule.getStringDstPortRange());
|
||||
cfg.add(new ScriptConfigItem(VRScripts.FIREWALL_NAT, args.toString()));
|
||||
ForwardingRule fwdRule = new ForwardingRule(rule.revoked(), rule.getProtocol().toLowerCase(), rule.getSrcIp(), rule.getStringSrcPortRange(), rule.getDstIp(),
|
||||
rule.getStringDstPortRange());
|
||||
rules.add(fwdRule);
|
||||
}
|
||||
|
||||
return cfg;
|
||||
ForwardingRules ruleSet = new ForwardingRules(rules.toArray(new ForwardingRule[rules.size()]));
|
||||
|
||||
return generateConfigItems(ruleSet);
|
||||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(SetStaticNatRulesCommand cmd) {
|
||||
@ -559,23 +558,6 @@ public class ConfigHelper {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(SetPortForwardingRulesVpcCommand cmd) {
|
||||
LinkedList<ConfigItem> cfg = new LinkedList<>();
|
||||
|
||||
for (PortForwardingRuleTO rule : cmd.getRules()) {
|
||||
String args = rule.revoked() ? "-D" : "-A";
|
||||
args += " -P " + rule.getProtocol().toLowerCase();
|
||||
args += " -l " + rule.getSrcIp();
|
||||
args += " -p " + rule.getStringSrcPortRange();
|
||||
args += " -r " + rule.getDstIp();
|
||||
args += " -d " + rule.getStringDstPortRange().replace(":", "-");
|
||||
|
||||
cfg.add(new ScriptConfigItem(VRScripts.VPC_PORTFORWARDING, args));
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(SetStaticRouteCommand cmd) {
|
||||
LinkedList<ConfigItem> cfg = new LinkedList<>();
|
||||
|
||||
@ -612,6 +594,9 @@ public class ConfigHelper {
|
||||
String destinationFile;
|
||||
|
||||
switch (configuration.getType()) {
|
||||
case ConfigBase.FORWARDING_RULES:
|
||||
destinationFile = VRScripts.FORWARDING_RULES_CONFIG;
|
||||
break;
|
||||
case ConfigBase.GUEST_NETWORK:
|
||||
destinationFile = VRScripts.GUEST_NETWORK_CONFIG;
|
||||
break;
|
||||
|
||||
@ -27,6 +27,7 @@ public class VRScripts {
|
||||
protected final static String VM_METADATA_CONFIG = "vm_metadata.json";
|
||||
protected final static String VM_DHCP_CONFIG = "vm_dhcp_entry.json";
|
||||
protected final static String VM_PASSWORD_CONFIG = "vm_password.json";
|
||||
protected static final String FORWARDING_RULES_CONFIG = "forwarding_rules.json";
|
||||
|
||||
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
|
||||
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds
|
||||
|
||||
@ -27,9 +27,18 @@ public abstract class ConfigBase {
|
||||
public static final String NETWORK_ACL = "networkacl";
|
||||
public static final String VM_METADATA = "vmdata";
|
||||
public static final String VM_PASSWORD = "vmpassword";
|
||||
public static final String FORWARDING_RULES = "forwardrules";
|
||||
|
||||
private String type = UNKNOWN;
|
||||
|
||||
private ConfigBase() {
|
||||
// Empty constructor for (de)serialization
|
||||
}
|
||||
|
||||
protected ConfigBase(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
//
|
||||
// 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 ForwardingRule {
|
||||
private boolean revoke;
|
||||
private String protocol;
|
||||
private String sourceIpAddress;
|
||||
private String sourcePortRange;
|
||||
private String destinationIpAddress;
|
||||
private String destinationPortRange;
|
||||
|
||||
public ForwardingRule() {
|
||||
// Empty constructor for (de)serialization
|
||||
}
|
||||
|
||||
public ForwardingRule(boolean revoke, String protocol, String sourceIpAddress, String sourcePortRange, String destinationIpAddress, String destinationPortRange) {
|
||||
this.revoke = revoke;
|
||||
this.protocol = protocol;
|
||||
this.sourceIpAddress = sourceIpAddress;
|
||||
this.sourcePortRange = sourcePortRange;
|
||||
this.destinationIpAddress = destinationIpAddress;
|
||||
this.destinationPortRange = destinationPortRange;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public String getDestinationPortRange() {
|
||||
return destinationPortRange;
|
||||
}
|
||||
|
||||
public void setDestinationPortRange(String destinationPortRange) {
|
||||
this.destinationPortRange = destinationPortRange;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
//
|
||||
// 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 ForwardingRules extends ConfigBase {
|
||||
ForwardingRule[] rules;
|
||||
|
||||
public ForwardingRules() {
|
||||
super(ConfigBase.FORWARDING_RULES);
|
||||
}
|
||||
|
||||
public ForwardingRules(ForwardingRule[] rules) {
|
||||
super(ConfigBase.FORWARDING_RULES);
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
public ForwardingRule[] getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public void setRules(ForwardingRule[] rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
}
|
||||
@ -31,13 +31,12 @@ public class GuestNetwork extends ConfigBase {
|
||||
private String domainName;
|
||||
|
||||
public GuestNetwork() {
|
||||
// Empty constructor for (de)serialization
|
||||
setType(ConfigBase.GUEST_NETWORK);
|
||||
super(ConfigBase.GUEST_NETWORK);
|
||||
}
|
||||
|
||||
public GuestNetwork(boolean add, String macAddress, String device, String routerGuestIp, String routerGuestNetmask, String routerGuestGateway, String cidr, String dns,
|
||||
String domainName) {
|
||||
setType(ConfigBase.GUEST_NETWORK);
|
||||
super(ConfigBase.GUEST_NETWORK);
|
||||
this.add = add;
|
||||
this.macAddress = macAddress;
|
||||
this.device = device;
|
||||
|
||||
@ -23,11 +23,11 @@ public class IpAssociation extends ConfigBase {
|
||||
private IpAddress[] ipAddress;
|
||||
|
||||
public IpAssociation() {
|
||||
setType(IP_ASSOCIATION);
|
||||
super(IP_ASSOCIATION);
|
||||
}
|
||||
|
||||
public IpAssociation(IpAddress[] ipAddress) {
|
||||
setType(IP_ASSOCIATION);
|
||||
super(IP_ASSOCIATION);
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
|
||||
@ -29,11 +29,11 @@ public class NetworkACL extends ConfigBase {
|
||||
private AclRule[] egressRules;
|
||||
|
||||
public NetworkACL() {
|
||||
setType(ConfigBase.NETWORK_ACL);
|
||||
super(ConfigBase.NETWORK_ACL);
|
||||
}
|
||||
|
||||
public NetworkACL(String device, String macAddress, boolean privateGatewayAcl, String nicIp, String nicNetmask, AclRule[] ingressRules, AclRule[] egressRules) {
|
||||
setType(ConfigBase.NETWORK_ACL);
|
||||
super(ConfigBase.NETWORK_ACL);
|
||||
this.device = device;
|
||||
this.macAddress = macAddress;
|
||||
this.privateGatewayAcl = privateGatewayAcl;
|
||||
|
||||
@ -26,11 +26,11 @@ public class VmData extends ConfigBase {
|
||||
private List<String[]> vmMetadata;
|
||||
|
||||
public VmData() {
|
||||
setType(ConfigBase.VM_METADATA);
|
||||
super(ConfigBase.VM_METADATA);
|
||||
}
|
||||
|
||||
public VmData(String vmIpAddress, List<String[]> vmMetadata) {
|
||||
setType(ConfigBase.VM_METADATA);
|
||||
super(ConfigBase.VM_METADATA);
|
||||
this.vmIpAddress = vmIpAddress;
|
||||
this.vmMetadata = vmMetadata;
|
||||
}
|
||||
|
||||
@ -31,12 +31,12 @@ public class VmDhcpConfig extends ConfigBase {
|
||||
private boolean defaultEntry;
|
||||
|
||||
public VmDhcpConfig() {
|
||||
setType(VM_DHCP);
|
||||
super(VM_DHCP);
|
||||
}
|
||||
|
||||
public VmDhcpConfig(String hostName, String macAddress, String ipv4Adress, String ipv6Address, String ipv6Duid, String dnsAdresses, String defaultGateway,
|
||||
String staticRoutes, boolean defaultEntry) {
|
||||
setType(VM_DHCP);
|
||||
super(VM_DHCP);
|
||||
this.hostName = hostName;
|
||||
this.macAddress = macAddress;
|
||||
this.ipv4Adress = ipv4Adress;
|
||||
|
||||
@ -24,11 +24,11 @@ public class VmPassword extends ConfigBase {
|
||||
private String password;
|
||||
|
||||
public VmPassword() {
|
||||
setType(ConfigBase.VM_PASSWORD);
|
||||
super(ConfigBase.VM_PASSWORD);
|
||||
}
|
||||
|
||||
public VmPassword(String ipAddress, String password) {
|
||||
setType(ConfigBase.VM_PASSWORD);
|
||||
super(ConfigBase.VM_PASSWORD);
|
||||
this.ipAddress = ipAddress;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user