bug 7195: introduced search by forVirtualNetwork parameter in listVmsCmd. Added "forVirtualNetwork" param to responses for all VM's apis.

status 7195: resolved fixed
This commit is contained in:
alena 2010-11-17 14:11:16 -08:00
parent b6f15213e5
commit 2184dd1af2
4 changed files with 39 additions and 1 deletions

View File

@ -443,6 +443,7 @@ public class ApiResponseHelper {
userVmResponse.setCpuNumber(offering.getCpu());
userVmResponse.setCpuSpeed(offering.getSpeed());
userVmResponse.setMemory(offering.getRamSize());
userVmResponse.setForVirtualNetwork(offering.getGuestIpType().equals(GuestIpType.Virtualized));
VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId());
if (rootVolume != null) {

View File

@ -68,6 +68,9 @@ public class ListVMsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the availability zone ID")
private Long zoneId;
@Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise")
private Boolean forVirtualNetwork;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -108,11 +111,18 @@ public class ListVMsCmd extends BaseListCmd {
public Long getZoneId() {
return zoneId;
}
public Boolean getForVirtualNetwork() {
return forVirtualNetwork;
}
public void setForVirtualNetwork(Boolean forVirtualNetwork) {
this.forVirtualNetwork = forVirtualNetwork;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getName() {
return s_name;

View File

@ -98,6 +98,9 @@ public class UserVmResponse extends BaseResponse {
@SerializedName("serviceofferingname") @Param(description="the name of the service offering of the virtual machine")
private String serviceOfferingName;
@SerializedName("forvirtualnetwork") @Param(description="the virtual network for the service offering")
private Boolean forVirtualNetwork;
@SerializedName(ApiConstants.CPU_NUMBER) @Param(description="the number of cpu this virtual machine is running with")
private Integer cpuNumber;
@ -441,4 +444,12 @@ public class UserVmResponse extends BaseResponse {
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}
public Boolean getForVirtualNetwork() {
return forVirtualNetwork;
}
public void setForVirtualNetwork(Boolean forVirtualNetwork) {
this.forVirtualNetwork = forVirtualNetwork;
}
}

View File

@ -2425,6 +2425,7 @@ public class ManagementServerImpl implements ManagementServer {
c.addCriteria(Criteria.STATE, cmd.getState());
c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId());
c.addCriteria(Criteria.GROUPID, cmd.getGroupId());
c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork());
// ignore these search requests if it's not an admin
if (isAdmin == true) {
@ -2462,6 +2463,7 @@ public class ManagementServerImpl implements ManagementServer {
Object isAdmin = c.getCriteria(Criteria.ISADMIN);
Object ipAddress = c.getCriteria(Criteria.IPADDRESS);
Object groupId = c.getCriteria(Criteria.GROUPID);
Object useVirtualNetwork = c.getCriteria(Criteria.FOR_VIRTUAL_NETWORK);
sb.and("displayName", sb.entity().getDisplayName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
@ -2493,6 +2495,16 @@ public class ManagementServerImpl implements ManagementServer {
groupSearch.and("groupId", groupSearch.entity().getGroupId(), SearchCriteria.Op.EQ);
sb.join("groupSearch", groupSearch, sb.entity().getId(), groupSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
}
if (useVirtualNetwork != null) {
SearchBuilder<ServiceOfferingVO> serviceSearch = _offeringsDao.createSearchBuilder();
if ((Boolean)useVirtualNetwork){
serviceSearch.and("guestIpType", serviceSearch.entity().getGuestIpType(), SearchCriteria.Op.EQ);
} else {
serviceSearch.and("guestIpType", serviceSearch.entity().getGuestIpType(), SearchCriteria.Op.NEQ);
}
sb.join("serviceSearch", serviceSearch, sb.entity().getServiceOfferingId(), serviceSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
// populate the search criteria with the values passed in
SearchCriteria<UserVmVO> sc = sb.create();
@ -2502,6 +2514,10 @@ public class ManagementServerImpl implements ManagementServer {
} else if (groupId != null ) {
sc.setJoinParameters("groupSearch", "groupId", groupId);
}
if (useVirtualNetwork != null) {
sc.setJoinParameters("serviceSearch", "guestIpType", NetworkOffering.GuestIpType.Virtualized.toString());
}
if (keyword != null) {
SearchCriteria<UserVmVO> ssc = _userVmDao.createSearchCriteria();