mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
List VMs by Security Group & HA (#4397)
This commit is contained in:
parent
aab8df09aa
commit
2e32a3a94a
@ -21,6 +21,7 @@ import java.util.EnumSet;
|
||||
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;
|
||||
|
||||
@ -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 ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -212,6 +219,14 @@ public class ListVMsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
|
||||
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) {
|
||||
|
||||
@ -919,6 +919,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
||||
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;
|
||||
@ -948,6 +950,12 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
||||
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);
|
||||
}
|
||||
@ -968,10 +976,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
||||
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);
|
||||
}
|
||||
@ -980,6 +984,10 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
||||
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();
|
||||
|
||||
@ -1016,10 +1024,18 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
||||
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());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user