Skip to content

Commit d905c10

Browse files
author
Alena Prokharchyk
committed
listFirewallRules - added optional networkId parameter allowing to search for firewall rules by guest network id
1 parent 81949ec commit d905c10

5 files changed

Lines changed: 26 additions & 23 deletions

File tree

api/src/com/cloud/server/ResourceTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum ResourceObjectType {
3131
Snapshot (true, false),
3232
Network (true, true),
3333
Nic (false, true),
34-
LoadBalancer (true, false),
34+
LoadBalancer (true, true),
3535
PortForwardingRule (true, true),
3636
FirewallRule (true, true),
3737
SecurityGroup (true, false),

api/src/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import org.apache.cloudstack.api.ApiConstants;
2424
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
2525
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.BaseCmd.CommandType;
2627
import org.apache.cloudstack.api.response.FirewallResponse;
2728
import org.apache.cloudstack.api.response.FirewallRuleResponse;
2829
import org.apache.cloudstack.api.response.IPAddressResponse;
2930
import org.apache.cloudstack.api.response.ListResponse;
31+
import org.apache.cloudstack.api.response.NetworkResponse;
3032
import org.apache.log4j.Logger;
3133

3234
import com.cloud.network.rules.FirewallRule;
@@ -47,6 +49,10 @@ public class ListFirewallRulesCmd extends BaseListTaggedResourcesCmd {
4749
@Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.UUID, entityType = IPAddressResponse.class,
4850
description="the id of IP address of the firwall services")
4951
private Long ipAddressId;
52+
53+
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
54+
description="list firewall rules for ceratin network", since="4.3")
55+
private Long networkId;
5056

5157
/////////////////////////////////////////////////////
5258
/////////////////// Accessors ///////////////////////
@@ -63,6 +69,10 @@ public FirewallRule.TrafficType getTrafficType () {
6369
public Long getId() {
6470
return id;
6571
}
72+
73+
public Long getNetworkId() {
74+
return networkId;
75+
}
6676

6777
/////////////////////////////////////////////////////
6878
/////////////// API Implementation///////////////////

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,12 +2374,11 @@ public FirewallResponse createFirewallResponse(FirewallRule fwRule) {
23742374
IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
23752375
response.setPublicIpAddressId(ip.getUuid());
23762376
response.setPublicIpAddress(ip.getAddress().addr());
2377-
} else if (fwRule.getTrafficType() == FirewallRule.TrafficType.Egress) {
2378-
response.setPublicIpAddress(null);
2379-
Network network = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
2380-
response.setNetworkId(network.getUuid());
23812377
}
2382-
2378+
2379+
Network network = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
2380+
response.setNetworkId(network.getUuid());
2381+
23832382
FirewallRule.State state = fwRule.getState();
23842383
String stateToSet = state.toString();
23852384
if (state.equals(FirewallRule.State.Revoke)) {

server/src/com/cloud/metadata/ResourceMetaDataManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
9696
_daoMap.put(ResourceObjectType.FirewallRule, _firewallRuleDetailsDao);
9797
_daoMap.put(ResourceObjectType.PublicIpAddress, _userIpAddressDetailsDao);
9898
_daoMap.put(ResourceObjectType.PortForwardingRule, _firewallRuleDetailsDao);
99+
_daoMap.put(ResourceObjectType.LoadBalancer, _firewallRuleDetailsDao);
99100

100101
return true;
101102
}

server/src/com/cloud/network/firewall/FirewallManagerImpl.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30-
import org.apache.log4j.Logger;
31-
import org.springframework.stereotype.Component;
32-
import org.apache.cloudstack.api.command.user.firewall.ListEgressFirewallRulesCmd;
3330
import org.apache.cloudstack.api.command.user.firewall.ListFirewallRulesCmd;
3431
import org.apache.cloudstack.context.CallContext;
3532
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
3633
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
34+
import org.apache.log4j.Logger;
35+
import org.springframework.stereotype.Component;
3736

3837
import com.cloud.configuration.Config;
3938
import com.cloud.domain.dao.DomainDao;
@@ -70,7 +69,6 @@
7069
import com.cloud.network.rules.FirewallRuleVO;
7170
import com.cloud.network.rules.PortForwardingRule;
7271
import com.cloud.network.rules.PortForwardingRuleVO;
73-
import com.cloud.network.rules.StaticNat;
7472
import com.cloud.network.rules.dao.PortForwardingRulesDao;
7573
import com.cloud.network.vpc.VpcManager;
7674
import com.cloud.projects.Project.ListProjectResourcesCriteria;
@@ -88,11 +86,11 @@
8886
import com.cloud.utils.db.JoinBuilder;
8987
import com.cloud.utils.db.SearchBuilder;
9088
import com.cloud.utils.db.SearchCriteria;
89+
import com.cloud.utils.db.SearchCriteria.Op;
90+
import com.cloud.utils.db.Transaction;
9191
import com.cloud.utils.db.TransactionCallbackNoReturn;
9292
import com.cloud.utils.db.TransactionCallbackWithException;
9393
import com.cloud.utils.db.TransactionStatus;
94-
import com.cloud.utils.db.SearchCriteria.Op;
95-
import com.cloud.utils.db.Transaction;
9694
import com.cloud.utils.exception.CloudRuntimeException;
9795
import com.cloud.utils.net.NetUtils;
9896
import com.cloud.vm.UserVmVO;
@@ -256,7 +254,7 @@ public FirewallRuleVO doInTransaction(TransactionStatus status) throws NetworkRu
256254
public Pair<List<? extends FirewallRule>, Integer> listFirewallRules(ListFirewallRulesCmd cmd) {
257255
Long ipId = cmd.getIpAddressId();
258256
Long id = cmd.getId();
259-
Long networkId = null;
257+
Long networkId = cmd.getNetworkId();
260258
Map<String, String> tags = cmd.getTags();
261259
FirewallRule.TrafficType trafficType = cmd.getTrafficType();
262260

@@ -283,15 +281,10 @@ public Pair<List<? extends FirewallRule>, Integer> listFirewallRules(ListFirewal
283281

284282
sb.and("id", sb.entity().getId(), Op.EQ);
285283
sb.and("trafficType", sb.entity().getTrafficType(), Op.EQ);
286-
if (cmd instanceof ListEgressFirewallRulesCmd ) {
287-
networkId =((ListEgressFirewallRulesCmd)cmd).getNetworkId();
288-
sb.and("networkId", sb.entity().getNetworkId(), Op.EQ);
289-
} else {
284+
sb.and("networkId", sb.entity().getNetworkId(), Op.EQ);
290285
sb.and("ip", sb.entity().getSourceIpAddressId(), Op.EQ);
291-
}
292286
sb.and("purpose", sb.entity().getPurpose(), Op.EQ);
293287

294-
295288
if (tags != null && !tags.isEmpty()) {
296289
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
297290
for (int count=0; count < tags.size(); count++) {
@@ -323,10 +316,10 @@ public Pair<List<? extends FirewallRule>, Integer> listFirewallRules(ListFirewal
323316

324317
if (ipId != null) {
325318
sc.setParameters("ip", ipId);
326-
} else if (cmd instanceof ListEgressFirewallRulesCmd) {
327-
if (networkId != null) {
328-
sc.setParameters("networkId", networkId);
329-
}
319+
}
320+
321+
if (networkId != null) {
322+
sc.setParameters("networkId", networkId);
330323
}
331324

332325
sc.setParameters("purpose", Purpose.Firewall);

0 commit comments

Comments
 (0)