Skip to content

Commit 27a790b

Browse files
author
Alena Prokharchyk
committed
DisplayFlag update support for PF/Firewall/EgressFirewall rules
1 parent 8ec0190 commit 27a790b

19 files changed

Lines changed: 153 additions & 32 deletions

File tree

api/src/com/cloud/network/firewall/FirewallService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public interface FirewallService {
5050

5151
boolean revokeRelatedFirewallRule(long ruleId, boolean apply);
5252

53-
FirewallRule updateFirewallRule(long ruleId, String customId);
53+
FirewallRule updateFirewallRule(long ruleId, String customId, Boolean forDisplay);
5454

5555
}

api/src/com/cloud/network/rules/FirewallRule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,6 @@ enum TrafficType {
8787
*/
8888
TrafficType getTrafficType();
8989

90+
boolean isDisplay();
91+
9092
}

api/src/com/cloud/network/rules/RulesService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ Pair<List<? extends FirewallRule>, Integer> searchStaticNatRules(Long ipId, Long
4141
* vm to be linked to. If specified the destination ip address is ignored.
4242
* @param openFirewall
4343
* TODO
44+
* @param forDisplay TODO
4445
* @return PortForwardingRule if created.
4546
* @throws NetworkRuleConflictException
4647
* if conflicts in the network rules are detected.
4748
*/
48-
PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, Ip vmIp, boolean openFirewall) throws NetworkRuleConflictException;
49+
PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId, Ip vmIp, boolean openFirewall, Boolean forDisplay) throws NetworkRuleConflictException;
4950

5051
/**
5152
* Revokes a port forwarding rule
@@ -80,6 +81,6 @@ Pair<List<? extends FirewallRule>, Integer> searchStaticNatRules(Long ipId, Long
8081

8182
boolean disableStaticNat(long ipId) throws ResourceUnavailableException, NetworkRuleConflictException, InsufficientAddressCapacityException;
8283

83-
PortForwardingRule updatePortForwardingRule(long id, String customId);
84+
PortForwardingRule updatePortForwardingRule(long id, String customId, Boolean forDisplay);
8485

8586
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222

23-
import org.apache.log4j.Logger;
24-
23+
import org.apache.cloudstack.acl.RoleType;
2524
import org.apache.cloudstack.api.APICommand;
2625
import org.apache.cloudstack.api.ApiCommandJobType;
2726
import org.apache.cloudstack.api.ApiConstants;
@@ -33,6 +32,7 @@
3332
import org.apache.cloudstack.api.response.FirewallResponse;
3433
import org.apache.cloudstack.api.response.NetworkResponse;
3534
import org.apache.cloudstack.context.CallContext;
35+
import org.apache.log4j.Logger;
3636

3737
import com.cloud.event.EventTypes;
3838
import com.cloud.exception.InvalidParameterValueException;
@@ -84,6 +84,9 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F
8484
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "type of firewallrule: system/user")
8585
private String type;
8686

87+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
88+
private Boolean display;
89+
8790
// ///////////////////////////////////////////////////
8891
// ///////////////// Accessors ///////////////////////
8992
// ///////////////////////////////////////////////////
@@ -341,4 +344,13 @@ public String getUuid() {
341344
return null;
342345
}
343346

347+
@Override
348+
public boolean isDisplay() {
349+
if (display != null) {
350+
return display;
351+
} else {
352+
return true;
353+
}
354+
}
355+
344356
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.apache.log4j.Logger;
23-
22+
import org.apache.cloudstack.acl.RoleType;
2423
import org.apache.cloudstack.api.APICommand;
2524
import org.apache.cloudstack.api.ApiCommandJobType;
2625
import org.apache.cloudstack.api.ApiConstants;
@@ -32,6 +31,7 @@
3231
import org.apache.cloudstack.api.response.FirewallResponse;
3332
import org.apache.cloudstack.api.response.IPAddressResponse;
3433
import org.apache.cloudstack.context.CallContext;
34+
import org.apache.log4j.Logger;
3535

3636
import com.cloud.event.EventTypes;
3737
import com.cloud.exception.InvalidParameterValueException;
@@ -83,6 +83,9 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
8383
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "type of firewallrule: system/user")
8484
private String type;
8585

86+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
87+
private Boolean display;
88+
8689
// ///////////////////////////////////////////////////
8790
// ///////////////// Accessors ///////////////////////
8891
// ///////////////////////////////////////////////////
@@ -333,4 +336,12 @@ public TrafficType getTrafficType() {
333336
return FirewallRule.TrafficType.Ingress;
334337
}
335338

339+
@Override
340+
public boolean isDisplay() {
341+
if (display != null) {
342+
return display;
343+
} else {
344+
return true;
345+
}
346+
}
336347
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
import java.util.List;
2020

21-
import com.cloud.utils.net.NetUtils;
22-
import org.apache.log4j.Logger;
23-
21+
import org.apache.cloudstack.acl.RoleType;
2422
import org.apache.cloudstack.api.APICommand;
2523
import org.apache.cloudstack.api.ApiCommandJobType;
2624
import org.apache.cloudstack.api.ApiConstants;
@@ -34,6 +32,7 @@
3432
import org.apache.cloudstack.api.response.NetworkResponse;
3533
import org.apache.cloudstack.api.response.UserVmResponse;
3634
import org.apache.cloudstack.context.CallContext;
35+
import org.apache.log4j.Logger;
3736

3837
import com.cloud.event.EventTypes;
3938
import com.cloud.exception.InvalidParameterValueException;
@@ -43,6 +42,7 @@
4342
import com.cloud.network.rules.PortForwardingRule;
4443
import com.cloud.user.Account;
4544
import com.cloud.utils.net.Ip;
45+
import com.cloud.utils.net.NetUtils;
4646

4747
@APICommand(name = "createPortForwardingRule", description = "Creates a port forwarding rule", responseObject = FirewallRuleResponse.class)
4848
public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
@@ -118,6 +118,9 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P
118118
description = "VM guest nic Secondary ip address for the port forwarding rule")
119119
private String vmSecondaryIp;
120120

121+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
122+
private Boolean display;
123+
121124
// ///////////////////////////////////////////////////
122125
// ///////////////// Accessors ///////////////////////
123126
// ///////////////////////////////////////////////////
@@ -341,7 +344,7 @@ public void create() {
341344
}
342345

343346
try {
344-
PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, privateIp, getOpenFirewall());
347+
PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, privateIp, getOpenFirewall(), isDisplay());
345348
setEntityId(result.getId());
346349
setEntityUuid(result.getUuid());
347350
} catch (NetworkRuleConflictException ex) {
@@ -416,4 +419,12 @@ public TrafficType getTrafficType() {
416419
return null;
417420
}
418421

422+
@Override
423+
public boolean isDisplay() {
424+
if (display != null) {
425+
return display;
426+
} else {
427+
return true;
428+
}
429+
}
419430
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.cloudstack.api.command.user.firewall;
1919

20+
import org.apache.cloudstack.acl.RoleType;
2021
import org.apache.cloudstack.api.APICommand;
2122
import org.apache.cloudstack.api.ApiConstants;
2223
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
@@ -50,13 +51,20 @@ public class UpdateEgressFirewallRuleCmd extends BaseAsyncCustomIdCmd {
5051
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
5152
private Long ownerId;
5253

54+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
55+
private Boolean display;
56+
5357
// ///////////////////////////////////////////////////
5458
// ///////////////// Accessors ///////////////////////
5559
// ///////////////////////////////////////////////////
5660

5761
public Long getId() {
5862
return id;
5963
}
64+
65+
public Boolean getDisplay() {
66+
return display;
67+
}
6068
// ///////////////////////////////////////////////////
6169
// ///////////// API Implementation///////////////////
6270
// ///////////////////////////////////////////////////
@@ -69,7 +77,7 @@ public String getCommandName() {
6977
@Override
7078
public void execute() throws ResourceUnavailableException {
7179
CallContext.current().setEventDetails("Rule Id: " + id);
72-
FirewallRule rule = _firewallService.updateFirewallRule(id, this.getCustomId());
80+
FirewallRule rule = _firewallService.updateFirewallRule(id, this.getCustomId(), getDisplay());
7381

7482
FirewallResponse fwResponse = new FirewallResponse();
7583
if (rule != null) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.cloudstack.api.command.user.firewall;
1919

20+
import org.apache.cloudstack.acl.RoleType;
2021
import org.apache.cloudstack.api.APICommand;
2122
import org.apache.cloudstack.api.ApiConstants;
2223
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
@@ -50,6 +51,9 @@ public class UpdateFirewallRuleCmd extends BaseAsyncCustomIdCmd {
5051
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, expose = false)
5152
private Long ownerId;
5253

54+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
55+
private Boolean display;
56+
5357
// ///////////////////////////////////////////////////
5458
// ///////////////// Accessors ///////////////////////
5559
// ///////////////////////////////////////////////////
@@ -58,6 +62,10 @@ public Long getId() {
5862
return id;
5963
}
6064

65+
public Boolean getDisplay() {
66+
return display;
67+
}
68+
6169
// ///////////////////////////////////////////////////
6270
// ///////////// API Implementation///////////////////
6371
// ///////////////////////////////////////////////////
@@ -70,7 +78,7 @@ public String getCommandName() {
7078
@Override
7179
public void execute() throws ResourceUnavailableException {
7280
CallContext.current().setEventDetails("Rule Id: " + id);
73-
FirewallRule rule = _firewallService.updateFirewallRule(id, this.getCustomId());
81+
FirewallRule rule = _firewallService.updateFirewallRule(id, this.getCustomId(), getDisplay());
7482

7583
FirewallResponse fwResponse = new FirewallResponse();
7684
if (rule != null) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.firewall;
1818

19+
import org.apache.cloudstack.acl.RoleType;
1920
import org.apache.cloudstack.api.APICommand;
2021
import org.apache.cloudstack.api.ApiConstants;
2122
import org.apache.cloudstack.api.BaseAsyncCmd;
@@ -72,6 +73,9 @@ public class UpdatePortForwardingRuleCmd extends BaseAsyncCustomIdCmd {
7273
description = "the ID of the virtual machine for the port forwarding rule")
7374
private Long virtualMachineId;
7475

76+
@Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the rule to the end user or not", since = "4.4", authorized = {RoleType.Admin})
77+
private Boolean display;
78+
7579
/////////////////////////////////////////////////////
7680
/////////////////// Accessors ///////////////////////
7781
/////////////////////////////////////////////////////
@@ -100,6 +104,10 @@ public Long getVirtualMachineId() {
100104
return virtualMachineId;
101105
}
102106

107+
public Boolean getDisplay() {
108+
return display;
109+
}
110+
103111
/////////////////////////////////////////////////////
104112
/////////////// API Implementation///////////////////
105113
/////////////////////////////////////////////////////
@@ -139,7 +147,7 @@ public void checkUuid() {
139147

140148
@Override
141149
public void execute() {
142-
PortForwardingRule rule = _rulesService.updatePortForwardingRule(id, this.getCustomId());
150+
PortForwardingRule rule = _rulesService.updatePortForwardingRule(id, this.getCustomId(), getDisplay());
143151
FirewallRuleResponse fwResponse = new FirewallRuleResponse();
144152
if (rule != null) {
145153
fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);

api/src/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import org.apache.log4j.Logger;
22-
2321
import org.apache.cloudstack.api.APICommand;
2422
import org.apache.cloudstack.api.ApiCommandJobType;
2523
import org.apache.cloudstack.api.ApiConstants;
@@ -32,6 +30,7 @@
3230
import org.apache.cloudstack.api.response.IPAddressResponse;
3331
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
3432
import org.apache.cloudstack.context.CallContext;
33+
import org.apache.log4j.Logger;
3534

3635
import com.cloud.event.EventTypes;
3736
import com.cloud.exception.InvalidParameterValueException;
@@ -317,4 +316,8 @@ public TrafficType getTrafficType() {
317316
return null;
318317
}
319318

319+
@Override
320+
public boolean isDisplay() {
321+
return true;
322+
}
320323
}

0 commit comments

Comments
 (0)