@Override public void execute() throws ResourceUnavailableException { boolean result = true; FirewallRule rule = null; try { CallContext.current().setEventDetails("Rule ID: " + getEntityId()); if (getOpenFirewall()) { result = result && _firewallService.applyIngressFirewallRules(ipAddressId, CallContext.current().getCallingAccount()); } result = result && _rulesService.applyStaticNatRules(ipAddressId, CallContext.current().getCallingAccount()); rule = _entityMgr.findById(FirewallRule.class, getEntityId()); StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false); IpForwardingRuleResponse fwResponse = _responseGenerator.createIpForwardingRuleResponse(staticNatRule); fwResponse.setResponseName(getCommandName()); setResponseObject(fwResponse); } finally { if (!result || rule == null) { if (getOpenFirewall()) { _firewallService.revokeRelatedFirewallRule(getEntityId(), true); } _rulesService.revokeStaticNatRule(getEntityId(), true); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Error in creating IP forwarding rule on the domr"); } } }
@Override public void create() { // cidr list parameter is deprecated 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"); } Ip privateIp = getVmSecondaryIp(); if (privateIp != null) { if (!NetUtils.isValidIp4(privateIp.toString())) { throw new InvalidParameterValueException("Invalid vm ip address"); } } try { PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, privateIp, getOpenFirewall(), isDisplay()); setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException ex) { s_logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage(), ex); } }
@Override public void create() { //cidr list parameter is deprecated 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 { StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall()); setEntityId(rule.getId()); setEntityUuid(rule.getUuid()); } catch (NetworkRuleConflictException e) { s_logger.info("Unable to create static NAT rule due to ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } }
@Override public void execute() { Pair<List<? extends FirewallRule>, Integer> result = _rulesService.searchStaticNatRules(publicIpAddressId, id, vmId, this.getStartIndex(), this.getPageSizeVal(), this.getAccountName(), this.getDomainId(), this.getProjectId(), this.isRecursive(), this.listAll()); ListResponse<IpForwardingRuleResponse> response = new ListResponse<IpForwardingRuleResponse>(); List<IpForwardingRuleResponse> ipForwardingResponses = new ArrayList<IpForwardingRuleResponse>(); for (FirewallRule rule : result.first()) { StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false); IpForwardingRuleResponse resp = _responseGenerator.createIpForwardingRuleResponse(staticNatRule); if (resp != null) { ipForwardingResponses.add(resp); } } response.setResponses(ipForwardingResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); }
success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCallingAccount()); _rulesService.revokePortForwardingRule(getEntityId(), true); } catch (Exception ex) {
@Override public void execute() { CallContext.current().setEventDetails("Rule ID: " + id); boolean result = _firewallService.revokeRelatedFirewallRule(id, true); result = result && _rulesService.revokeStaticNatRule(id, true); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete IP forwarding rule"); } }
@Override public void execute() throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException { boolean result = _rulesService.disableStaticNat(ipAddressId); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disable static NAT"); } }
@Override public void execute() { CallContext.current().setEventDetails("Rule ID: " + id); //revoke corresponding firewall rule first boolean result = _firewallService.revokeRelatedFirewallRule(id, true); result = result && _rulesService.revokePortForwardingRule(id, true); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete port forwarding rule"); } }
@Override public void execute() throws ResourceUnavailableException { try { boolean result = _rulesService.enableStaticNat(ipAddressId, virtualMachineId, getNetworkId(), getVmSecondaryIp()); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable static NAT"); } } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } }
@Override public void execute() { Pair<List<? extends PortForwardingRule>, Integer> result = _rulesService.listPortForwardingRules(this); ListResponse<FirewallRuleResponse> response = new ListResponse<FirewallRuleResponse>(); List<FirewallRuleResponse> fwResponses = new ArrayList<FirewallRuleResponse>(); for (PortForwardingRule fwRule : result.first()) { FirewallRuleResponse ruleData = _responseGenerator.createPortForwardingRuleResponse(fwRule); ruleData.setObjectName("portforwardingrule"); fwResponses.add(ruleData); } response.setResponses(fwResponses, result.second()); response.setResponseName(getCommandName()); setResponseObject(response); } }
@Override public void execute() { final Pair<List<? extends FirewallRule>, Integer> result = _rulesService.searchStaticNatRules(publicIpAddressId, id, vmId, this.getStartIndex(), this.getPageSizeVal(), this.getAccountName(), this.getDomainId(), this.getProjectId(), this.isRecursive(), this.listAll()); final ListResponse<IpForwardingRuleResponse> response = new ListResponse<>(); final List<IpForwardingRuleResponse> ipForwardingResponses = new ArrayList<>(); for (final FirewallRule rule : result.first()) { final StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false); final IpForwardingRuleResponse resp = _responseGenerator.createIpForwardingRuleResponse(staticNatRule); if (resp != null) { ipForwardingResponses.add(resp); } } response.setResponses(ipForwardingResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); }
success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCallingAccount()); _rulesService.revokePortForwardingRule(getEntityId(), true); } catch (final Exception ex) {
@Override public void execute() { CallContext.current().setEventDetails("Rule ID: " + id); boolean result = _firewallService.revokeRelatedFirewallRule(id, true); result = result && _rulesService.revokeStaticNatRule(id, true); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete IP forwarding rule"); } }
@Override public void execute() throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException { final boolean result = _rulesService.disableStaticNat(ipAddressId); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to disable static NAT"); } }
@Override public void execute() { CallContext.current().setEventDetails("Rule ID: " + id); //revoke corresponding firewall rule first boolean result = _firewallService.revokeRelatedFirewallRule(id, true); result = result && _rulesService.revokePortForwardingRule(id, true); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete port forwarding rule"); } }
@Override public void execute() throws ResourceUnavailableException { try { final boolean result = _rulesService.enableStaticNat(ipAddressId, virtualMachineId, getNetworkId(), getVmSecondaryIp()); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable static NAT"); } } catch (final NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } }
@Override public void execute() { final Pair<List<? extends PortForwardingRule>, Integer> result = _rulesService.listPortForwardingRules(this); final ListResponse<FirewallRuleResponse> response = new ListResponse<>(); final List<FirewallRuleResponse> fwResponses = new ArrayList<>(); for (final PortForwardingRule fwRule : result.first()) { final FirewallRuleResponse ruleData = _responseGenerator.createPortForwardingRuleResponse(fwRule); ruleData.setObjectName("portforwardingrule"); fwResponses.add(ruleData); } response.setResponses(fwResponses, result.second()); response.setResponseName(getCommandName()); setResponseObject(response); }
@Override public void execute() throws ResourceUnavailableException { boolean result = true; FirewallRule rule = null; try { CallContext.current().setEventDetails("Rule ID: " + getEntityId()); if (getOpenFirewall()) { result = result && _firewallService.applyIngressFirewallRules(ipAddressId, CallContext.current().getCallingAccount()); } result = result && _rulesService.applyStaticNatRules(ipAddressId, CallContext.current().getCallingAccount()); rule = _entityMgr.findById(FirewallRule.class, getEntityId()); final StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false); final IpForwardingRuleResponse fwResponse = _responseGenerator.createIpForwardingRuleResponse(staticNatRule); fwResponse.setResponseName(getCommandName()); setResponseObject(fwResponse); } finally { if (!result || rule == null) { if (getOpenFirewall()) { _firewallService.revokeRelatedFirewallRule(getEntityId(), true); } _rulesService.revokeStaticNatRule(getEntityId(), true); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Error in creating IP forwarding rule on the domr"); } } }
@Override public void create() { //cidr list parameter is deprecated 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 { final StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall()); setEntityId(rule.getId()); setEntityUuid(rule.getUuid()); } catch (final NetworkRuleConflictException e) { s_logger.info("Unable to create static NAT rule due to ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } }
@Override public void create() { // cidr list parameter is deprecated 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"); } final Ip privateIp = getVmSecondaryIp(); if (privateIp != null) { if (!NetUtils.isValidIp4(privateIp.toString())) { throw new InvalidParameterValueException("Invalid vm ip address"); } } try { final PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, privateIp, getOpenFirewall(), isDisplay()); setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (final NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: ", ex); s_logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } }