use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.
the class CreateFirewallRuleCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException {
final CallContext callerContext = CallContext.current();
boolean success = false;
FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId());
try {
CallContext.current().setEventDetails("Rule ID: " + getEntityId());
success = _firewallService.applyIngressFwRules(rule.getSourceIpAddressId(), callerContext.getCallingAccount());
// State is different after the rule is applied, so get new object here
rule = _entityMgr.findById(FirewallRule.class, getEntityId());
FirewallResponse fwResponse = new FirewallResponse();
if (rule != null) {
fwResponse = _responseGenerator.createFirewallResponse(rule);
setResponseObject(fwResponse);
}
fwResponse.setResponseName(getCommandName());
} finally {
if (!success || rule == null) {
_firewallService.revokeIngressFwRule(getEntityId(), true);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create firewall rule");
}
}
}
use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.
the class CreateFirewallRuleCmd method create.
@Override
public void create() {
if (getSourceCidrList() != null) {
for (final String cidr : getSourceCidrList()) {
if (!NetUtils.isValidIp4Cidr(cidr)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Source CIDRs formatting error " + cidr);
}
}
}
try {
final FirewallRule result = _firewallService.createIngressFirewallRule(this);
if (result != null) {
setEntityId(result.getId());
setEntityUuid(result.getUuid());
}
} 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());
}
}
use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.
the class ListEgressFirewallRulesCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final Pair<List<? extends FirewallRule>, Integer> result = _firewallService.listFirewallRules(this);
final ListResponse<FirewallResponse> response = new ListResponse<>();
final List<FirewallResponse> fwResponses = new ArrayList<>();
if (result != null) {
for (final FirewallRule fwRule : result.first()) {
final FirewallResponse ruleData = _responseGenerator.createFirewallResponse(fwRule);
ruleData.setObjectName("firewallrule");
fwResponses.add(ruleData);
}
response.setResponses(fwResponses, result.second());
}
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.
the class ListFirewallRulesCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final Pair<List<? extends FirewallRule>, Integer> result = _firewallService.listFirewallRules(this);
final ListResponse<FirewallResponse> response = new ListResponse<>();
final List<FirewallResponse> fwResponses = new ArrayList<>();
for (final FirewallRule fwRule : result.first()) {
final FirewallResponse ruleData = _responseGenerator.createFirewallResponse(fwRule);
ruleData.setObjectName("firewallrule");
fwResponses.add(ruleData);
}
response.setResponses(fwResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.legacymodel.network.FirewallRule in project cosmic by MissionCriticalCloud.
the class UpdateEgressFirewallRuleCmd method execute.
@Override
public void execute() throws ResourceUnavailableException {
CallContext.current().setEventDetails("Rule Id: " + id);
final FirewallRule rule = _firewallService.updateEgressFirewallRule(id, this.getCustomId(), getDisplay());
FirewallResponse fwResponse = new FirewallResponse();
if (rule != null) {
fwResponse = _responseGenerator.createFirewallResponse(rule);
setResponseObject(fwResponse);
}
fwResponse.setResponseName(getCommandName());
}
Aggregations