mirror of https://github.com/apache/cloudstack.git
bug 7194:New API for adding range of public & private ports in port forwarding rule addition
adding support for port ranges in port forwarding rules.
This commit is contained in:
parent
6bd8cece48
commit
5769fde46b
|
|
@ -126,12 +126,16 @@ public class ApiConstants {
|
|||
public static final String PRIVATE_INTERFACE = "privateinterface";
|
||||
public static final String PRIVATE_IP = "privateip";
|
||||
public static final String PRIVATE_PORT = "privateport";
|
||||
public static final String PRIVATE_START_PORT = "privateport";
|
||||
public static final String PRIVATE_END_PORT = "privateendport";
|
||||
public static final String PRIVATE_ZONE = "privatezone";
|
||||
public static final String PROTOCOL = "protocol";
|
||||
public static final String PUBLIC_INTERFACE = "publicinterface";
|
||||
public static final String PUBLIC_IP_ID = "publicipid";
|
||||
public static final String PUBLIC_IP = "publicip";
|
||||
public static final String PUBLIC_PORT = "publicport";
|
||||
public static final String PUBLIC_START_PORT = "publicport";
|
||||
public static final String PUBLIC_END_PORT = "publicendport";
|
||||
public static final String PUBLIC_ZONE = "publiczone";
|
||||
public static final String RECEIVED_BYTES = "receivedbytes";
|
||||
public static final String REQUIRES_HVM = "requireshvm";
|
||||
|
|
|
|||
|
|
@ -55,14 +55,20 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
|
|||
@Parameter(name = ApiConstants.IP_ADDRESS_ID, type = CommandType.LONG, required = true, description = "the IP address id of the port forwarding rule")
|
||||
private Long ipAddressId;
|
||||
|
||||
@Parameter(name = ApiConstants.PRIVATE_PORT, type = CommandType.INTEGER, required = true, description = "the private port of the port forwarding rule")
|
||||
private Integer privatePort;
|
||||
@Parameter(name = ApiConstants.PRIVATE_START_PORT, type = CommandType.INTEGER, required = true, description = "the starting port of port forwarding rule's private port range")
|
||||
private Integer privateStartPort;
|
||||
|
||||
@Parameter(name = ApiConstants.PRIVATE_END_PORT, type = CommandType.INTEGER, required = false, description = "the ending port of port forwarding rule's private port range")
|
||||
private Integer privateEndPort;
|
||||
|
||||
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description = "the protocol for the port fowarding rule. Valid values are TCP or UDP.")
|
||||
private String protocol;
|
||||
|
||||
@Parameter(name = ApiConstants.PUBLIC_PORT, type = CommandType.INTEGER, required = true, description = "the public port of the port forwarding rule")
|
||||
private Integer publicPort;
|
||||
@Parameter(name = ApiConstants.PUBLIC_START_PORT, type = CommandType.INTEGER, required = true, description = "the starting port of port forwarding rule's public port range")
|
||||
private Integer publicStartPort;
|
||||
|
||||
@Parameter(name = ApiConstants.PUBLIC_END_PORT, type = CommandType.INTEGER, required = false, description = "the ending port of port forwarding rule's private port range")
|
||||
private Integer publicEndPort;
|
||||
|
||||
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.LONG, required = true, description = "the ID of the virtual machine for the port forwarding rule")
|
||||
private Long virtualMachineId;
|
||||
|
|
@ -70,7 +76,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
|
|||
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
|
||||
private List<String> cidrlist;
|
||||
|
||||
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////////// Accessors ///////////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
|
@ -79,19 +85,11 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
|
|||
return ipAddressId;
|
||||
}
|
||||
|
||||
public Integer getPrivatePort() {
|
||||
return privatePort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocol() {
|
||||
return protocol.trim();
|
||||
}
|
||||
|
||||
public Integer getPublicPort() {
|
||||
return publicPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVirtualMachineId() {
|
||||
return virtualMachineId;
|
||||
|
|
@ -158,12 +156,12 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
|
|||
|
||||
@Override
|
||||
public int getSourcePortStart() {
|
||||
return publicPort.intValue();
|
||||
return publicStartPort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourcePortEnd() {
|
||||
return publicPort.intValue();
|
||||
return (publicEndPort == null)? publicStartPort.intValue() : publicEndPort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -205,12 +203,12 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
|
|||
|
||||
@Override
|
||||
public int getDestinationPortStart() {
|
||||
return privatePort.intValue();
|
||||
return privateStartPort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDestinationPortEnd() {
|
||||
return privatePort.intValue();
|
||||
return (privateEndPort == null)? privateStartPort.intValue() : privateEndPort.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
package com.cloud.api.response;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
|
@ -25,14 +27,20 @@ public class FirewallRuleResponse extends BaseResponse {
|
|||
@SerializedName(ApiConstants.ID) @Param(description="the ID of the port forwarding rule")
|
||||
private Long id;
|
||||
|
||||
@SerializedName(ApiConstants.PRIVATE_PORT) @Param(description="the private port for the port forwarding rule")
|
||||
private String privatePort;
|
||||
@SerializedName(ApiConstants.PRIVATE_START_PORT) @Param(description = "the starting port of port forwarding rule's private port range")
|
||||
private String privateStartPort;
|
||||
|
||||
@SerializedName(ApiConstants.PRIVATE_END_PORT) @Param(description = "the ending port of port forwarding rule's private port range")
|
||||
private String privateEndPort;
|
||||
|
||||
@SerializedName(ApiConstants.PROTOCOL) @Param(description="the protocol of the port forwarding rule")
|
||||
private String protocol;
|
||||
|
||||
@SerializedName(ApiConstants.PUBLIC_PORT) @Param(description="the public port for the port forwarding rule")
|
||||
private String publicPort;
|
||||
@SerializedName(ApiConstants.PUBLIC_START_PORT) @Param(description="the starting port of port forwarding rule's public port range")
|
||||
private String publicStartPort;
|
||||
|
||||
@SerializedName(ApiConstants.PUBLIC_END_PORT) @Param(description = "the ending port of port forwarding rule's private port range")
|
||||
private String publicEndPort;
|
||||
|
||||
@SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description="the VM ID for the port forwarding rule")
|
||||
private Long virtualMachineId;
|
||||
|
|
@ -60,14 +68,22 @@ public class FirewallRuleResponse extends BaseResponse {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPrivatePort() {
|
||||
return privatePort;
|
||||
public String getPrivateStartPort() {
|
||||
return privateStartPort;
|
||||
}
|
||||
|
||||
public void setPrivatePort(String privatePort) {
|
||||
this.privatePort = privatePort;
|
||||
public String getPrivateEndPort() {
|
||||
return privateEndPort;
|
||||
}
|
||||
|
||||
public void setPrivateStartPort(String privatePort) {
|
||||
this.privateStartPort = privatePort;
|
||||
}
|
||||
|
||||
public void setPrivateEndPort(String privatePort) {
|
||||
this.privateEndPort = privatePort;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
|
@ -76,12 +92,20 @@ public class FirewallRuleResponse extends BaseResponse {
|
|||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getPublicPort() {
|
||||
return publicPort;
|
||||
public String getPublicStartPort() {
|
||||
return publicStartPort;
|
||||
}
|
||||
|
||||
public void setPublicPort(String publicPort) {
|
||||
this.publicPort = publicPort;
|
||||
public String getPublicEndPort() {
|
||||
return publicEndPort;
|
||||
}
|
||||
|
||||
public void setPublicStartPort(String publicPort) {
|
||||
this.publicStartPort = publicPort;
|
||||
}
|
||||
|
||||
public void setPublicEndPort(String publicPort) {
|
||||
this.publicEndPort = publicPort;
|
||||
}
|
||||
|
||||
public Long getVirtualMachineId() {
|
||||
|
|
|
|||
|
|
@ -952,9 +952,11 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
public FirewallRuleResponse createFirewallRuleResponse(PortForwardingRule fwRule) {
|
||||
FirewallRuleResponse response = new FirewallRuleResponse();
|
||||
response.setId(fwRule.getId());
|
||||
response.setPrivatePort(Integer.toString(fwRule.getDestinationPortStart()));
|
||||
response.setPrivateStartPort(Integer.toString(fwRule.getDestinationPortStart()));
|
||||
response.setPrivateEndPort(Integer.toString(fwRule.getDestinationPortEnd()));
|
||||
response.setProtocol(fwRule.getProtocol());
|
||||
response.setPublicPort(Integer.toString(fwRule.getSourcePortStart()));
|
||||
response.setPublicStartPort(Integer.toString(fwRule.getSourcePortStart()));
|
||||
response.setPublicEndPort(Integer.toString(fwRule.getSourcePortEnd()));
|
||||
|
||||
IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
|
||||
response.setPublicIpAddressId(ip.getId());
|
||||
|
|
|
|||
|
|
@ -224,6 +224,11 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
if (rule.getDestinationPortStart() > rule.getDestinationPortEnd() || rule.getSourcePortStart() > rule.getSourcePortEnd()) {
|
||||
throw new InvalidParameterValueException("Start port can't be bigger than end port");
|
||||
}
|
||||
|
||||
// check that the port ranges are of equal size
|
||||
if ((rule.getDestinationPortEnd() - rule.getDestinationPortStart()) != (rule.getSourcePortEnd() - rule.getSourcePortStart())) {
|
||||
throw new InvalidParameterValueException("Source port and destination port ranges should be of equal sizes.");
|
||||
}
|
||||
|
||||
Network network = _networkMgr.getNetwork(networkId);
|
||||
assert network != null : "Can't create port forwarding rule as network associated with public ip address is null...how is it possible?";
|
||||
|
|
|
|||
Loading…
Reference in New Issue