Skip to content
Merged
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 @@ -21,6 +21,7 @@
import java.util.List;

import org.apache.cloudstack.api.command.user.UserCmd;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -134,6 +135,12 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
@Parameter(name = ApiConstants.USER_ID, type = CommandType.UUID, entityType = UserResponse.class, required = false, description = "the user ID that created the VM and is under the account that owns the VM")
private Long userId;

@Parameter(name = ApiConstants.SECURITY_GROUP_ID, type = CommandType.UUID, entityType = SecurityGroupResponse.class, description = "the security group ID", since = "4.15")
private Long securityGroupId;

@Parameter(name = ApiConstants.HA_ENABLE, type = CommandType.BOOLEAN, description = "list by the High Availability offering; true if filtering VMs with HA enabled; false for VMs with HA disabled", since = "4.15")
private Boolean haEnabled;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -212,6 +219,14 @@ public Long getStorageId() {
return storageId;
}

public Long getSecurityGroupId() {
return securityGroupId;
}

public Boolean getHaEnabled() {
return haEnabled;
}

public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
EnumSet<VMDetails> dv;
if (viewDetails == null || viewDetails.size() <= 0) {
Expand Down
24 changes: 20 additions & 4 deletions server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
Object affinityGroupId = cmd.getAffinityGroupId();
Object keyPairName = cmd.getKeyPairName();
Object serviceOffId = cmd.getServiceOfferingId();
Object securityGroupId = cmd.getSecurityGroupId();
Object isHaEnabled = cmd.getHaEnabled();
Object pod = null;
Object hostId = null;
Object storageId = null;
Expand Down Expand Up @@ -948,6 +950,12 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
if (display != null) {
sb.and("display", sb.entity().isDisplayVm(), SearchCriteria.Op.EQ);
}

if (isHaEnabled != null) {
sb.and("haEnabled", sb.entity().isHaEnabled(), SearchCriteria.Op.EQ);
}


if (groupId != null && (Long)groupId != -1) {
sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ);
}
Expand All @@ -968,10 +976,6 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
sb.and("poolId", sb.entity().getPoolId(), SearchCriteria.Op.EQ);
}

if (affinityGroupId != null) {
sb.and("affinityGroupId", sb.entity().getAffinityGroupId(), SearchCriteria.Op.EQ);
}

if (keyPairName != null) {
sb.and("keyPairName", sb.entity().getKeypairName(), SearchCriteria.Op.EQ);
}
Expand All @@ -980,6 +984,10 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
sb.and("displayVm", sb.entity().isDisplayVm(), SearchCriteria.Op.EQ);
}

if (securityGroupId != null) {
sb.and("securityGroupId", sb.entity().getSecurityGroupId(), SearchCriteria.Op.EQ);
}

// populate the search criteria with the values passed in
SearchCriteria<UserVmJoinVO> sc = sb.create();

Expand Down Expand Up @@ -1016,10 +1024,18 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
sc.setParameters("serviceOfferingId", serviceOffId);
}

if (securityGroupId != null) {
sc.setParameters("securityGroupId", securityGroupId);
}

if (display != null) {
sc.setParameters("display", display);
}

if (isHaEnabled != null) {
sc.setParameters("haEnabled", isHaEnabled);
}

if (ids != null && !ids.isEmpty()) {
sc.setParameters("idIN", ids.toArray());
}
Expand Down