-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Public IP quarantine feature #7378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
308247a
Add IP quarantine feature
BryanMLima 7f1ee45
Small fixes
BryanMLima 6774f94
Fix unit tests
BryanMLima 1a08248
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima 366d5f7
Only add IP to quarantine if config is bigger than 0
BryanMLima 3ebaa1f
Change since version to 4.18
BryanMLima 1bd60dc
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima 2e2052b
Remove unecessary API_NAMES vars
BryanMLima c867384
Address code smells considering the PR scope
BryanMLima 4dcbd90
Fix checkstyles
BryanMLima 6ae190d
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima 287dace
Fix duplicate quarantine IP DB entry and address Daan review
BryanMLima 2be1f71
Fix duplicate quarantine IP DB entry and address Daan review
BryanMLima e4a134e
Change since version to 4.18.1.0
BryanMLima 7ca43db
Address code smells
BryanMLima 846e366
Change version to 4.19
BryanMLima 74194b0
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima a375327
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima 54b5f73
Fix unit tests
BryanMLima 611a298
Address reviews
BryanMLima 86b4506
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima b74bc51
Add missing newlines at the end of files
BryanMLima 4fd4a32
Merge branch 'ip-quarantine' of github.com:scclouds/cloudstack into i…
BryanMLima 2b0f94f
Merge branch 'main' into ip-quarantine
BryanMLima 5abbe57
Merge branch 'main' into ip-quarantine
BryanMLima ddbfac8
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima 5bb1cd0
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima ddce15a
Change quarantine unit from hours to minutes and add smoke tests
BryanMLima ebb75c1
Reset quarantine config on smoke test tear down
BryanMLima 998e3e0
Merge branch 'main' of github.com:apache/cloudstack into ip-quarantine
BryanMLima 5325f56
Allocate specified source NAT IP only if user informed
BryanMLima 00b28ca
Allow removing IP from quarantine informing its address as well as it…
BryanMLima 301b20f
Address NPE
BryanMLima 3fb9586
Allow updating IP quarantine informing its address as well as its ID
BryanMLima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
api/src/main/java/com/cloud/network/PublicIpQuarantine.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package com.cloud.network; | ||
|
|
||
| import org.apache.cloudstack.api.Identity; | ||
| import org.apache.cloudstack.api.InternalIdentity; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| public interface PublicIpQuarantine extends InternalIdentity, Identity { | ||
| Long getPublicIpAddressId(); | ||
|
|
||
| Long getPreviousOwnerId(); | ||
|
|
||
| Date getEndDate(); | ||
|
|
||
| String getRemovalReason(); | ||
|
|
||
| Date getRemoved(); | ||
|
|
||
| Date getCreated(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
api/src/main/java/org/apache/cloudstack/api/command/user/address/ListQuarantinedIpsCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.user.address; | ||
|
|
||
| import com.cloud.network.PublicIpQuarantine; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseListCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.IpQuarantineResponse; | ||
| import org.apache.cloudstack.api.response.ListResponse; | ||
|
|
||
| @APICommand(name = "listQuarantinedIps", responseObject = IpQuarantineResponse.class, description = "List public IP addresses in quarantine.", since = "4.18.0", | ||
| entityType = {PublicIpQuarantine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin}) | ||
| public class ListQuarantinedIpsCmd extends BaseListCmd { | ||
|
|
||
| @Parameter(name = ApiConstants.SHOW_REMOVED, type = CommandType.BOOLEAN, description = "Show IPs removed from quarantine.") | ||
| private boolean showRemoved = false; | ||
|
|
||
| @Parameter(name = ApiConstants.SHOW_INACTIVE, type = CommandType.BOOLEAN, description = "Show IPs that are no longer in quarantine.") | ||
| private boolean showInactive = false; | ||
|
|
||
| public boolean isShowRemoved() { | ||
| return showRemoved; | ||
| } | ||
| public boolean isShowInactive() { | ||
| return showInactive; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| ListResponse<IpQuarantineResponse> response = _queryService.listQuarantinedIps(this); | ||
| response.setResponseName(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
api/src/main/java/org/apache/cloudstack/api/command/user/address/RemoveQuarantinedIpCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.user.address; | ||
|
|
||
| import com.cloud.network.PublicIpQuarantine; | ||
| import com.cloud.user.Account; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.IpQuarantineResponse; | ||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
|
|
||
| @APICommand(name = "removeQuarantinedIp", responseObject = IpQuarantineResponse.class, description = "Removes a public IP address from quarantine. Only IPs in active " + | ||
| "quarantine can be removed.", | ||
| since = "4.18.0", entityType = {PublicIpQuarantine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, | ||
|
DaanHoogland marked this conversation as resolved.
Outdated
|
||
| authorized = {RoleType.Admin, RoleType.DomainAdmin}) | ||
| public class RemoveQuarantinedIpCmd extends BaseCmd { | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IpQuarantineResponse.class, required = true, description = "The ID of the public IP address in " + | ||
| "active quarantine.") | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.REMOVAL_REASON, type = CommandType.STRING, required = true, description = "The reason for removing the public IP address from quarantine " + | ||
| "prematurely.") | ||
| private String removalReason; | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getRemovalReason() { | ||
| return removalReason; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| _networkService.removePublicIpAddressFromQuarantine(this); | ||
| final SuccessResponse response = new SuccessResponse(); | ||
| response.setResponseName(getCommandName()); | ||
| response.setSuccess(true); | ||
| setResponseObject(response); | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
| } | ||
67 changes: 67 additions & 0 deletions
67
api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateQuarantinedIpCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.user.address; | ||
|
|
||
| import com.cloud.network.PublicIpQuarantine; | ||
| import com.cloud.user.Account; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.IpQuarantineResponse; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| @APICommand(name = "updateQuarantinedIp", responseObject = IpQuarantineResponse.class, description = "Updates the quarantine end date for the given public IP address.", | ||
| since = "4.18.0", entityType = {PublicIpQuarantine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, | ||
|
DaanHoogland marked this conversation as resolved.
Outdated
|
||
| authorized = {RoleType.Admin, RoleType.DomainAdmin}) | ||
| public class UpdateQuarantinedIpCmd extends BaseCmd { | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IpQuarantineResponse.class, required = true, description = "The ID of the public IP address in " + | ||
| "active quarantine.") | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.END_DATE, type = BaseCmd.CommandType.DATE, required = true, description = "The date when the quarantine will no longer be active.") | ||
| private Date endDate; | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Date getEndDate() { | ||
| return endDate; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| PublicIpQuarantine publicIpQuarantine = _networkService.updatePublicIpAddressInQuarantine(this); | ||
| if (publicIpQuarantine == null) { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update public IP quarantine."); | ||
| } | ||
| IpQuarantineResponse response = _responseGenerator.createQuarantinedIpsResponse(publicIpQuarantine); | ||
| response.setResponseName(getCommandName()); | ||
| this.setResponseObject(response); | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.