Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ public class ApiConstants {
public static final String VPC_OFF_NAME = "vpcofferingname";
public static final String VPC_OFFERING_CONSERVE_MODE = "vpcofferingconservemode";
public static final String NETWORK = "network";
public static final String VPC_ACCESS = "vpcaccess";
public static final String VPC_ID = "vpcid";
public static final String VPC_NAME = "vpcname";
public static final String VPC_GATEWAY_ID = "vpcgatewayid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void execute() {
private void updateNetworkResponse(List<NetworkResponse> response) {
for (NetworkResponse networkResponse : response) {
ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Network, networkResponse.getId());
if (resourceIcon == null && networkResponse.getVpcId() != null) {
if (resourceIcon == null && networkResponse.getVpcId() != null && networkResponse.getVpcAccess()) {
resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Vpc, networkResponse.getVpcId());
}
if (resourceIcon == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co
@Param(description = "Purpose of the IP address. In Acton this value is not null for IPs with isSystem=true, and can have either StaticNat or LB value")
private String purpose;

@SerializedName(ApiConstants.VPC_ACCESS)
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.21.0")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.21.0")
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.24.0")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.21.0")
@Param(description = "Whether the calling account has access to this network's VPC", since = "24.0")

actually (by now)

private boolean vpcAccess;

@SerializedName(ApiConstants.VPC_ID)
@Param(description = "VPC ID the IP belongs to")
private String vpcId;
Expand Down Expand Up @@ -301,6 +305,10 @@ public void setPurpose(String purpose) {
this.purpose = purpose;
}

public void setVpcAccess(boolean vpcAccess) {
this.vpcAccess = vpcAccess;
}

public void setVpcId(String vpcId) {
this.vpcId = vpcId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
@Param(description = "True if Network supports specifying IP ranges, false otherwise")
private Boolean specifyIpRanges;

@SerializedName(ApiConstants.VPC_ACCESS)

@shwstppr shwstppr Sep 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not get this information from network owner? I don't think these response params are needed and UI can probably get these values at runtime based on the caller and AI response data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is absolutely neede than I think better structure would be to return - vpcaccount or vpcaccountid and vpcdomainid

@Param(description = "Whether the calling account has access to this network's VPC", since = "4.21.0")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.21.0")
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.23.0")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Param(description = "Whether the calling account has access to this network's VPC", since = "4.21.0")
@Param(description = "Whether the calling account has access to this network's VPC", since = "24.0")

private Boolean vpcAccess;

@SerializedName(ApiConstants.VPC_ID)
@Param(description = "VPC the Network belongs to")
private String vpcId;
Expand Down Expand Up @@ -523,6 +527,14 @@ public void setSpecifyIpRanges(Boolean specifyIpRanges) {
this.specifyIpRanges = specifyIpRanges;
}

public void setVpcAccess(boolean vpcAccess) {
this.vpcAccess = vpcAccess;
}

public Boolean getVpcAccess() {
return vpcAccess;
}

public void setVpcId(String vpcId) {
this.vpcId = vpcId;
}
Expand Down
60 changes: 38 additions & 22 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ip
}


setVpcIdInResponse(ipAddr.getVpcId(), ipResponse::setVpcId, ipResponse::setVpcName);
setVpcIdInResponse(ipAddr.getVpcId(), ipResponse::setVpcId, ipResponse::setVpcName, ipResponse::setVpcAccess);


// Network id the ip is associated with (if associated networkId is
Expand Down Expand Up @@ -1242,20 +1242,43 @@ public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ip
return ipResponse;
}

protected void setVpcIdInResponse(Long vpcId, Consumer<String> vpcUuidSetter, Consumer<String> vpcNameSetter, Consumer<Boolean> vpcAccessSetter) {
if (vpcId == null) {
return;
}
Vpc vpc = ApiDBUtils.findVpcById(vpcId);
if (vpc == null) {
return;
}

private void setVpcIdInResponse(Long vpcId, Consumer<String> vpcUuidSetter, Consumer<String> vpcNameSetter) {
if (vpcId != null) {
Vpc vpc = ApiDBUtils.findVpcById(vpcId);
if (vpc != null) {
try {
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, false, vpc);
vpcUuidSetter.accept(vpc.getUuid());
} catch (PermissionDeniedException e) {
logger.debug("Not setting the vpcId to the response because the caller does not have access to the VPC");
}
vpcNameSetter.accept(vpc.getName());
}
try {
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, false, vpc);
vpcAccessSetter.accept(true);
} catch (PermissionDeniedException e) {
vpcAccessSetter.accept(false);
logger.debug("Setting [{}] as false because the caller does not have access to the VPC [{}].", ApiConstants.VPC_ACCESS, vpc);
}
vpcNameSetter.accept(vpc.getName());
vpcUuidSetter.accept(vpc.getUuid());
}

protected void setAclIdInResponse(Network network, NetworkResponse response) {
if (network.getNetworkACLId() == null) {
return;
}

NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
if (acl == null) {
return;
}

if (Boolean.FALSE.equals(response.getVpcAccess()) && acl.getVpcId() != 0) {
logger.debug("[{}] not set in response, since caller does not have access to it.", acl);
return;
}

response.setAclId(acl.getUuid());
response.setAclName(acl.getName());
}

private void showVmInfoForSharedNetworks(boolean forVirtualNetworks, IpAddress ipAddr, IPAddressResponse ipResponse) {
Expand Down Expand Up @@ -2799,7 +2822,8 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)

response.setSpecifyIpRanges(network.getSpecifyIpRanges());

setVpcIdInResponse(network.getVpcId(), response::setVpcId, response::setVpcName);
setVpcIdInResponse(network.getVpcId(), response::setVpcId, response::setVpcName, response::setVpcAccess);
setAclIdInResponse(network, response);

setResponseAssociatedNetworkInformation(response, network.getId());

Expand All @@ -2816,14 +2840,6 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
response.setHasAnnotation(annotationDao.hasAnnotations(network.getUuid(), AnnotationService.EntityType.NETWORK.name(),
_accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));

if (network.getNetworkACLId() != null) {
NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
if (acl != null) {
response.setAclId(acl.getUuid());
response.setAclName(acl.getName());
}
}

response.setStrechedL2Subnet(network.isStrechedL2Network());
if (network.isStrechedL2Network()) {
Set<String> networkSpannedZones = new HashSet<String>();
Expand Down
Loading
Loading