Revert "Removed port ranges from createPortForwardingRule API"
This reverts commit d04f0b475285e45ae5a466626fb11704fe46fa99.
Conflicts:
api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
Conflicts:
api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/2392f655
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/2392f655
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/2392f655
Branch: refs/heads/4.0
Commit: 2392f655b01b1e3cc507af4b43d88a34d7c1a7f3
Parents: f57095a
Author: Alena Prokharchyk <[email protected]>
Authored: Fri Sep 14 10:39:53 2012 -0700
Committer: Edison Su <[email protected]>
Committed: Thu Sep 27 17:20:33 2012 -0700
----------------------------------------------------------------------
.../api/commands/CreatePortForwardingRuleCmd.java | 52 ++++++++------
1 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2392f655/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
index 6666114..55f0b23 100644
--- a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
+++ b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
@@ -63,9 +63,16 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
description = "the protocol for the port fowarding rule. Valid
values are TCP or UDP.")
private String protocol;
+ @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.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;
@IdentityMapper(entityTableName = "vm_instance")
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type =
CommandType.LONG, required = true,
@@ -93,7 +100,7 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
// ///////////////////////////////////////////////////
public String getEntityTable() {
- return "firewall_rules";
+ return "firewall_rules";
}
public Long getIpAddressId() {
@@ -117,7 +124,7 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
}
return null;
}
-
+
public Boolean getOpenFirewall() {
boolean isVpc = getVpcId() == null ? false : true;
if (openFirewall != null) {
@@ -154,6 +161,7 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
return s_name;
}
+
@Override
public void execute() throws ResourceUnavailableException {
UserContext callerContext = UserContext.current();
@@ -161,16 +169,16 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
PortForwardingRule rule = null;
try {
UserContext.current().setEventDetails("Rule Id: " + getEntityId());
-
+
if (getOpenFirewall()) {
success = success &&
_firewallService.applyFirewallRules(ipAddressId, callerContext.getCaller());
}
-
+
success = success &&
_rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCaller());
// State is different after the rule is applied, so get new object
here
rule = _entityMgr.findById(PortForwardingRule.class,
getEntityId());
- FirewallRuleResponse fwResponse = new FirewallRuleResponse();
+ FirewallRuleResponse fwResponse = new FirewallRuleResponse();
if (rule != null) {
fwResponse =
_responseGenerator.createPortForwardingRuleResponse(rule);
setResponseObject(fwResponse);
@@ -178,13 +186,13 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
fwResponse.setResponseName(getCommandName());
} finally {
if (!success || rule == null) {
-
+
if (getOpenFirewall()) {
_firewallService.revokeRelatedFirewallRule(getEntityId(),
true);
}
-
+
_rulesService.revokePortForwardingRule(getEntityId(), true);
-
+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed
to apply port forwarding rule");
}
}
@@ -213,7 +221,7 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
@Override
public Integer getSourcePortEnd() {
- return publicStartPort.intValue();
+ return (publicEndPort == null)? publicStartPort.intValue() :
publicEndPort.intValue();
}
@Override
@@ -265,10 +273,10 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
public Ip getDestinationIpAddress() {
return null;
}
-
+
@Override
public void setDestinationIpAddress(Ip destinationIpAddress) {
- return;
+ return;
}
@Override
@@ -278,7 +286,7 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
@Override
public int getDestinationPortEnd() {
- return privateStartPort.intValue();
+ return (privateEndPort == null)? privateStartPort.intValue() :
privateEndPort.intValue();
}
@Override
@@ -287,12 +295,12 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
if (cidrlist != null) {
throw new InvalidParameterValueException("Parameter cidrList is
deprecated; if you need to open firewall rule for the specific cidr, please
refer to createFirewallRule command");
}
-
+
try {
PortForwardingRule result =
_rulesService.createPortForwardingRule(this, virtualMachineId,
getOpenFirewall());
setEntityId(result.getId());
} catch (NetworkRuleConflictException ex) {
- s_logger.info("Network rule conflict: ", ex);
+ s_logger.info("Network rule conflict: " , ex);
s_logger.trace("Network Rule Conflict: ", ex);
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR,
ex.getMessage());
}
@@ -332,27 +340,27 @@ public class CreatePortForwardingRuleCmd extends
BaseAsyncCreateCmd implements P
}
return ip;
}
-
+
@Override
public Integer getIcmpCode() {
return null;
}
-
+
@Override
public Integer getIcmpType() {
return null;
}
-
+
@Override
public Long getRelated() {
return null;
}
- @Override
- public FirewallRuleType getType() {
- return FirewallRuleType.User;
- }
-
+ @Override
+ public FirewallRuleType getType() {
+ return FirewallRuleType.User;
+ }
+
@Override
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.FirewallRule;