Revert "Removed port ranges from createPortForwardingRule API"

This reverts commit d04f0b4752.

Conflicts:

	api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java

Conflicts:

	api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
This commit is contained in:
Alena Prokharchyk 2012-09-14 10:39:53 -07:00
parent 82e57f8f40
commit 2c2178ce10
1 changed files with 30 additions and 22 deletions

View File

@ -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;