use of com.cloud.api.response.FirewallRuleResponse in project CloudStack-archive by CloudStack-extras.
the class CreatePortForwardingRuleCmd method execute.
@Override
public void execute() throws ResourceUnavailableException {
UserContext callerContext = UserContext.current();
boolean success = true;
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();
if (rule != null) {
fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);
setResponseObject(fwResponse);
}
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");
}
}
}
use of com.cloud.api.response.FirewallRuleResponse in project CloudStack-archive by CloudStack-extras.
the class ListPortForwardingRulesCmd method execute.
@Override
public void execute() {
List<? extends PortForwardingRule> result = _rulesService.listPortForwardingRules(this);
ListResponse<FirewallRuleResponse> response = new ListResponse<FirewallRuleResponse>();
List<FirewallRuleResponse> fwResponses = new ArrayList<FirewallRuleResponse>();
for (PortForwardingRule fwRule : result) {
FirewallRuleResponse ruleData = _responseGenerator.createPortForwardingRuleResponse(fwRule);
ruleData.setObjectName("portforwardingrule");
fwResponses.add(ruleData);
}
response.setResponses(fwResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
Aggregations