Skip to content

Commit ece08ff

Browse files
BryanMLimadhslove
authored andcommitted
Public IP quarantine feature (apache#7378)
1 parent a517f5e commit ece08ff

37 files changed

Lines changed: 1815 additions & 143 deletions

api/src/main/java/com/cloud/network/NetworkService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
2525
import org.apache.cloudstack.api.command.admin.network.ListGuestVlansCmd;
2626
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
27+
import org.apache.cloudstack.api.command.user.address.RemoveQuarantinedIpCmd;
28+
import org.apache.cloudstack.api.command.user.address.UpdateQuarantinedIpCmd;
2729
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
2830
import org.apache.cloudstack.api.command.user.network.CreateNetworkPermissionsCmd;
2931
import org.apache.cloudstack.api.command.user.network.ListNetworkPermissionsCmd;
@@ -246,4 +248,8 @@ Network createPrivateNetwork(String networkName, String displayText, long physic
246248
boolean resetNetworkPermissions(ResetNetworkPermissionsCmd resetNetworkPermissionsCmd);
247249

248250
void validateIfServiceOfferingIsActiveAndSystemVmTypeIsDomainRouter(final Long serviceOfferingId) throws InvalidParameterValueException;
251+
252+
PublicIpQuarantine updatePublicIpAddressInQuarantine(UpdateQuarantinedIpCmd cmd);
253+
254+
void removePublicIpAddressFromQuarantine(RemoveQuarantinedIpCmd cmd);
249255
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.network;
18+
19+
import org.apache.cloudstack.api.Identity;
20+
import org.apache.cloudstack.api.InternalIdentity;
21+
22+
import java.util.Date;
23+
24+
public interface PublicIpQuarantine extends InternalIdentity, Identity {
25+
Long getPublicIpAddressId();
26+
27+
Long getPreviousOwnerId();
28+
29+
Date getEndDate();
30+
31+
String getRemovalReason();
32+
33+
Date getRemoved();
34+
35+
Date getCreated();
36+
}

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ public class ApiConstants {
224224
public static final String INSTANCES_STATS_USER_ONLY = "instancesstatsuseronly";
225225
public static final String PREFIX = "prefix";
226226
public static final String PREVIOUS_ACL_RULE_ID = "previousaclruleid";
227+
public static final String PREVIOUS_OWNER_ID = "previousownerid";
228+
public static final String PREVIOUS_OWNER_NAME = "previousownername";
227229
public static final String NEXT_ACL_RULE_ID = "nextaclruleid";
228230
public static final String MOVE_ACL_CONSISTENCY_HASH = "aclconsistencyhash";
229231
public static final String IMAGE_PATH = "imagepath";
@@ -402,6 +404,7 @@ public class ApiConstants {
402404
public static final String SHOW_CAPACITIES = "showcapacities";
403405
public static final String SHOW_REMOVED = "showremoved";
404406
public static final String SHOW_RESOURCE_ICON = "showicon";
407+
public static final String SHOW_INACTIVE = "showinactive";
405408
public static final String SHOW_UNIQUE = "showunique";
406409
public static final String SIGNATURE = "signature";
407410
public static final String SIGNATURE_VERSION = "signatureversion";
@@ -794,6 +797,7 @@ public class ApiConstants {
794797
public static final String IPSEC_PSK = "ipsecpsk";
795798
public static final String GUEST_IP = "guestip";
796799
public static final String REMOVED = "removed";
800+
public static final String REMOVAL_REASON = "removalreason";
797801
public static final String COMPLETED = "completed";
798802
public static final String IKE_VERSION = "ikeversion";
799803
public static final String IKE_POLICY = "ikepolicy";

api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse;
6565
import org.apache.cloudstack.api.response.HypervisorGuestOsNamesResponse;
6666
import org.apache.cloudstack.api.response.IPAddressResponse;
67+
import org.apache.cloudstack.api.response.IpQuarantineResponse;
6768
import org.apache.cloudstack.api.response.ImageStoreResponse;
6869
import org.apache.cloudstack.api.response.InstanceGroupResponse;
6970
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
@@ -170,6 +171,7 @@
170171
import com.cloud.network.PhysicalNetwork;
171172
import com.cloud.network.PhysicalNetworkServiceProvider;
172173
import com.cloud.network.PhysicalNetworkTrafficType;
174+
import com.cloud.network.PublicIpQuarantine;
173175
import com.cloud.network.RemoteAccessVpn;
174176
import com.cloud.network.RouterHealthCheckResult;
175177
import com.cloud.network.Site2SiteCustomerGateway;
@@ -532,4 +534,6 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
532534
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateProvisionResponse(Long certificateId, Long hostId, Pair<Boolean, String> result);
533535

534536
FirewallResponse createIpv6FirewallRuleResponse(FirewallRule acl);
537+
538+
IpQuarantineResponse createQuarantinedIpsResponse(PublicIpQuarantine publicIp);
535539
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.address;
18+
19+
import com.cloud.network.PublicIpQuarantine;
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiConstants;
23+
import org.apache.cloudstack.api.BaseListCmd;
24+
import org.apache.cloudstack.api.Parameter;
25+
import org.apache.cloudstack.api.response.IpQuarantineResponse;
26+
import org.apache.cloudstack.api.response.ListResponse;
27+
28+
@APICommand(name = "listQuarantinedIps", responseObject = IpQuarantineResponse.class, description = "List public IP addresses in quarantine.", since = "4.19",
29+
entityType = {PublicIpQuarantine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin})
30+
public class ListQuarantinedIpsCmd extends BaseListCmd {
31+
32+
@Parameter(name = ApiConstants.SHOW_REMOVED, type = CommandType.BOOLEAN, description = "Show IPs removed from quarantine.")
33+
private boolean showRemoved = false;
34+
35+
@Parameter(name = ApiConstants.SHOW_INACTIVE, type = CommandType.BOOLEAN, description = "Show IPs that are no longer in quarantine.")
36+
private boolean showInactive = false;
37+
38+
public boolean isShowRemoved() {
39+
return showRemoved;
40+
}
41+
public boolean isShowInactive() {
42+
return showInactive;
43+
}
44+
45+
@Override
46+
public void execute() {
47+
ListResponse<IpQuarantineResponse> response = _queryService.listQuarantinedIps(this);
48+
response.setResponseName(getCommandName());
49+
this.setResponseObject(response);
50+
}
51+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.address;
18+
19+
import com.cloud.network.PublicIpQuarantine;
20+
import com.cloud.user.Account;
21+
import org.apache.cloudstack.acl.RoleType;
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.response.IpQuarantineResponse;
27+
import org.apache.cloudstack.api.response.SuccessResponse;
28+
29+
@APICommand(name = "removeQuarantinedIp", responseObject = IpQuarantineResponse.class, description = "Removes a public IP address from quarantine. Only IPs in active " +
30+
"quarantine can be removed.",
31+
since = "4.19", entityType = {PublicIpQuarantine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
32+
authorized = {RoleType.Admin, RoleType.DomainAdmin})
33+
public class RemoveQuarantinedIpCmd extends BaseCmd {
34+
35+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IpQuarantineResponse.class, description = "The ID of the public IP address in active quarantine. " +
36+
"Either the IP address is informed, or the ID of the IP address in quarantine.")
37+
private Long id;
38+
39+
@Parameter(name = ApiConstants.IP_ADDRESS, type = CommandType.STRING, description = "The public IP address in active quarantine. Either the IP address is informed, or the ID" +
40+
" of the IP address in quarantine.")
41+
private String ipAddress;
42+
43+
@Parameter(name = ApiConstants.REMOVAL_REASON, type = CommandType.STRING, required = true, description = "The reason for removing the public IP address from quarantine " +
44+
"prematurely.")
45+
private String removalReason;
46+
47+
public Long getId() {
48+
return id;
49+
}
50+
51+
public String getIpAddress() {
52+
return ipAddress;
53+
}
54+
55+
public String getRemovalReason() {
56+
return removalReason;
57+
}
58+
59+
@Override
60+
public void execute() {
61+
_networkService.removePublicIpAddressFromQuarantine(this);
62+
final SuccessResponse response = new SuccessResponse();
63+
response.setResponseName(getCommandName());
64+
response.setSuccess(true);
65+
setResponseObject(response);
66+
}
67+
68+
@Override
69+
public long getEntityOwnerId() {
70+
return Account.ACCOUNT_ID_SYSTEM;
71+
}
72+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.address;
18+
19+
import com.cloud.network.PublicIpQuarantine;
20+
import com.cloud.user.Account;
21+
import org.apache.cloudstack.acl.RoleType;
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.IpQuarantineResponse;
29+
30+
import java.util.Date;
31+
32+
@APICommand(name = "updateQuarantinedIp", responseObject = IpQuarantineResponse.class, description = "Updates the quarantine end date for the given public IP address.",
33+
since = "4.19", entityType = {PublicIpQuarantine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
34+
authorized = {RoleType.Admin, RoleType.DomainAdmin})
35+
public class UpdateQuarantinedIpCmd extends BaseCmd {
36+
37+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IpQuarantineResponse.class, description = "The ID of the public IP address in " +
38+
"active quarantine.")
39+
private Long id;
40+
41+
@Parameter(name = ApiConstants.IP_ADDRESS, type = CommandType.STRING, description = "The public IP address in active quarantine. Either the IP address is informed, or the ID" +
42+
" of the IP address in quarantine.")
43+
private String ipAddress;
44+
45+
@Parameter(name = ApiConstants.END_DATE, type = BaseCmd.CommandType.DATE, required = true, description = "The date when the quarantine will no longer be active.")
46+
private Date endDate;
47+
48+
public Long getId() {
49+
return id;
50+
}
51+
52+
public String getIpAddress() {
53+
return ipAddress;
54+
}
55+
56+
public Date getEndDate() {
57+
return endDate;
58+
}
59+
60+
@Override
61+
public void execute() {
62+
PublicIpQuarantine publicIpQuarantine = _networkService.updatePublicIpAddressInQuarantine(this);
63+
if (publicIpQuarantine == null) {
64+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update public IP quarantine.");
65+
}
66+
IpQuarantineResponse response = _responseGenerator.createQuarantinedIpsResponse(publicIpQuarantine);
67+
response.setResponseName(getCommandName());
68+
this.setResponseObject(response);
69+
}
70+
71+
@Override
72+
public long getEntityOwnerId() {
73+
return Account.ACCOUNT_ID_SYSTEM;
74+
}
75+
}

0 commit comments

Comments
 (0)