mirror of https://github.com/apache/cloudstack.git
Refactor listVMs to new API framework.
This commit is contained in:
parent
88f5b73682
commit
b144be4613
|
|
@ -80,6 +80,7 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
|
|||
userVmResponse.setId(instance.getId());
|
||||
userVmResponse.setName(instance.getName());
|
||||
userVmResponse.setDisplayName(instance.getDisplayName());
|
||||
userVmResponse.setPrivateIp(instance.getPrivateIpAddress());
|
||||
|
||||
// TODO: implement
|
||||
Account accountTemp = getManagementServer().findAccountById(instance.getAccountId());
|
||||
|
|
|
|||
|
|
@ -15,52 +15,32 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.UserVmResponse;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.server.Criteria;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VmStats;
|
||||
|
||||
public class ListVMsCmd extends BaseCmd {
|
||||
@Implementation(method="searchForUserVMs")
|
||||
public class ListVMsCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listvirtualmachinesresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.DOMAIN_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.HOST_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.NAME, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.POD_ID, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.STATE, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ZONE_ID, Boolean.FALSE));
|
||||
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.KEYWORD, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGE, Boolean.FALSE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.PAGESIZE, Boolean.FALSE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -134,210 +114,111 @@ public class ListVMsCmd extends BaseCmd {
|
|||
public String getName() {
|
||||
return s_name;
|
||||
}
|
||||
@Override
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
|
||||
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
|
||||
String name = (String) params.get(BaseCmd.Properties.NAME.getName());
|
||||
String state = (String) params.get(BaseCmd.Properties.STATE.getName());
|
||||
Long zoneId = (Long)params.get(BaseCmd.Properties.ZONE_ID.getName());
|
||||
Long podId = (Long)params.get(BaseCmd.Properties.POD_ID.getName());
|
||||
Long hostId = (Long)params.get(BaseCmd.Properties.HOST_ID.getName());
|
||||
String keyword = (String)params.get(BaseCmd.Properties.KEYWORD.getName());
|
||||
Integer page = (Integer)params.get(BaseCmd.Properties.PAGE.getName());
|
||||
Integer pageSize = (Integer)params.get(BaseCmd.Properties.PAGESIZE.getName());
|
||||
Long accountId = null;
|
||||
Boolean isAdmin = false;
|
||||
@Override @SuppressWarnings("unchecked")
|
||||
public String getResponse() {
|
||||
List<UserVmVO> userVms = (List<UserVmVO>)getResponseObject();
|
||||
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
isAdmin = true;
|
||||
if (domainId != null) {
|
||||
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), domainId)) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Invalid domain id (" + domainId + ") given, unable to list virtual machines.");
|
||||
}
|
||||
|
||||
if (accountName != null) {
|
||||
account = getManagementServer().findActiveAccount(accountName, domainId);
|
||||
if (account == null) {
|
||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to find account " + accountName + " in domain " + domainId);
|
||||
}
|
||||
accountId = account.getId();
|
||||
}
|
||||
} else {
|
||||
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
|
||||
}
|
||||
} else {
|
||||
accountName = account.getAccountName();
|
||||
accountId = account.getId();
|
||||
domainId = account.getDomainId();
|
||||
}
|
||||
|
||||
Long[] accountIds = null;
|
||||
if (accountId != null) {
|
||||
accountIds = new Long[1];
|
||||
accountIds[0] = accountId;
|
||||
}
|
||||
|
||||
Long startIndex = Long.valueOf(0);
|
||||
int pageSizeNum = 50;
|
||||
if (pageSize != null) {
|
||||
pageSizeNum = pageSize.intValue();
|
||||
}
|
||||
if (page != null) {
|
||||
int pageNum = page.intValue();
|
||||
if (pageNum > 0) {
|
||||
startIndex = Long.valueOf(pageSizeNum * (pageNum-1));
|
||||
}
|
||||
}
|
||||
Criteria c = new Criteria("id", Boolean.TRUE, startIndex, Long.valueOf(pageSizeNum));
|
||||
|
||||
if (keyword != null) {
|
||||
c.addCriteria(Criteria.KEYWORD, keyword);
|
||||
} else {
|
||||
c.addCriteria(Criteria.ID, id);
|
||||
c.addCriteria(Criteria.NAME, name);
|
||||
c.addCriteria(Criteria.STATE, state);
|
||||
|
||||
if(zoneId != null)
|
||||
c.addCriteria(Criteria.DATACENTERID, zoneId);
|
||||
|
||||
// ignore these search requests if it's not an admin
|
||||
if (isAdmin == true) {
|
||||
c.addCriteria(Criteria.DOMAINID, domainId);
|
||||
|
||||
if(podId != null)
|
||||
c.addCriteria(Criteria.PODID, podId);
|
||||
c.addCriteria(Criteria.HOSTID, hostId);
|
||||
}
|
||||
}
|
||||
|
||||
c.addCriteria(Criteria.ACCOUNTID, accountIds);
|
||||
c.addCriteria(Criteria.ISADMIN, isAdmin);
|
||||
|
||||
List<? extends UserVm> virtualMachines = getManagementServer().searchForUserVMs(c);
|
||||
|
||||
if (virtualMachines == null) {
|
||||
throw new ServerApiException(BaseCmd.VM_LIST_ERROR, "unable to find virtual machines for account id " + accountName.toString());
|
||||
}
|
||||
|
||||
Object[] vmTag = new Object[virtualMachines.size()];
|
||||
int i = 0;
|
||||
|
||||
HashMap<Long, HostVO> hostMap = new HashMap<Long, HostVO>();
|
||||
List<HostVO> hostList = getManagementServer().listAllActiveHosts();
|
||||
for (HostVO hostVO : hostList) {
|
||||
hostMap.put(hostVO.getId(), hostVO);
|
||||
}
|
||||
|
||||
for (UserVm vmInstance : virtualMachines) {
|
||||
List<Pair<String, Object>> vmData = new ArrayList<Pair<String, Object>>();
|
||||
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob("vm_instance", vmInstance.getId());
|
||||
if(asyncJob != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), asyncJob.getId().toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.JOB_STATUS.getName(), String.valueOf(asyncJob.getStatus())));
|
||||
List<UserVmResponse> response = new ArrayList<UserVmResponse>();
|
||||
for (UserVmVO userVm : userVms) {
|
||||
UserVmResponse userVmResponse = new UserVmResponse();
|
||||
userVmResponse.setId(userVm.getId());
|
||||
AsyncJobVO asyncJob = getManagementServer().findInstancePendingAsyncJob("vm_instance", userVm.getId());
|
||||
if (asyncJob != null) {
|
||||
userVmResponse.setJobId(asyncJob.getId());
|
||||
userVmResponse.setJobStatus(asyncJob.getStatus());
|
||||
}
|
||||
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ID.getName(), Long.toString(vmInstance.getId())));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NAME.getName(), vmInstance.getName()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CREATED.getName(), getDateString(vmInstance.getCreated())));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.IP_ADDRESS.getName(), vmInstance.getPrivateIpAddress()));
|
||||
if (vmInstance.getState() != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.STATE.getName(), vmInstance.getState().toString()));
|
||||
userVmResponse.setName(userVm.getName());
|
||||
userVmResponse.setCreated(userVm.getCreated());
|
||||
userVmResponse.setPrivateIp(userVm.getPrivateIpAddress());
|
||||
if (userVm.getState() != null) {
|
||||
userVmResponse.setState(userVm.getState().toString());
|
||||
}
|
||||
|
||||
Account acct = getManagementServer().findAccountById(Long.valueOf(vmInstance.getAccountId()));
|
||||
Account acct = getManagementServer().findAccountById(Long.valueOf(userVm.getAccountId()));
|
||||
if (acct != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ACCOUNT.getName(), acct.getAccountName()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN_ID.getName(), acct.getDomainId().toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DOMAIN.getName(), getManagementServer().findDomainIdById(acct.getDomainId()).getName()));
|
||||
}
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.HA_ENABLE.getName(), Boolean.valueOf(vmInstance.isHaEnabled()).toString()));
|
||||
|
||||
if (vmInstance.getDisplayName() != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_NAME.getName(), vmInstance.getDisplayName()));
|
||||
}
|
||||
else {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.DISPLAY_NAME.getName(), vmInstance.getName()));
|
||||
userVmResponse.setAccountName(acct.getAccountName());
|
||||
userVmResponse.setDomainId(acct.getDomainId());
|
||||
userVmResponse.setDomainName(getManagementServer().findDomainIdById(acct.getDomainId()).getName());
|
||||
}
|
||||
|
||||
if (vmInstance.getGroup() != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.GROUP.getName(), vmInstance.getGroup()));
|
||||
}
|
||||
userVmResponse.setHaEnable(userVm.isHaEnabled());
|
||||
|
||||
if (userVm.getDisplayName() != null) {
|
||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||
} else {
|
||||
userVmResponse.setDisplayName(userVm.getName());
|
||||
}
|
||||
|
||||
userVmResponse.setGroup(userVm.getGroup());
|
||||
|
||||
// Data Center Info
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_ID.getName(), Long.valueOf(vmInstance.getDataCenterId()).toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ZONE_NAME.getName(), getManagementServer().findDataCenterById(vmInstance.getDataCenterId()).getName()));
|
||||
userVmResponse.setZoneId(userVm.getDataCenterId());
|
||||
userVmResponse.setZoneName(getManagementServer().findDataCenterById(userVm.getDataCenterId()).getName());
|
||||
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
//if user is an admin, display host id
|
||||
if ( (isAdmin == true) && (vmInstance.getHostId() != null)) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_ID.getName(), vmInstance.getHostId().toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.HOST_NAME.getName(), getManagementServer().getHostBy(vmInstance.getHostId()).getName()));
|
||||
if (((account == null) || isAdmin(account.getType())) && (userVm.getHostId() != null)) {
|
||||
userVmResponse.setHostId(userVm.getHostId());
|
||||
userVmResponse.setHostName(getManagementServer().getHostBy(userVm.getHostId()).getName());
|
||||
}
|
||||
|
||||
// Template Info
|
||||
VMTemplateVO template = getManagementServer().findTemplateById(vmInstance.getTemplateId());
|
||||
VMTemplateVO template = getManagementServer().findTemplateById(userVm.getTemplateId());
|
||||
if (template != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), Long.valueOf(vmInstance.getTemplateId()).toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_NAME.getName(), template.getName()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_DISPLAY_TEXT.getName(), template.getDisplayText()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), template.getEnablePassword()));
|
||||
userVmResponse.setTemplateId(userVm.getTemplateId());
|
||||
userVmResponse.setTemplateName(template.getName());
|
||||
userVmResponse.setTemplateDisplayText(template.getDisplayText());
|
||||
userVmResponse.setPasswordEnabled(template.getEnablePassword());
|
||||
} else {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_ID.getName(), "-1"));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_NAME.getName(), "ISO Boot"));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.TEMPLATE_DISPLAY_TEXT.getName(), "ISO Boot"));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.PASSWORD_ENABLED.getName(), false));
|
||||
userVmResponse.setTemplateId(-1L);
|
||||
userVmResponse.setTemplateName("ISO Boot");
|
||||
userVmResponse.setTemplateDisplayText("ISO Boot");
|
||||
userVmResponse.setPasswordEnabled(false);
|
||||
}
|
||||
|
||||
// ISO Info
|
||||
if (vmInstance.getIsoId() != null) {
|
||||
VMTemplateVO iso = getManagementServer().findTemplateById(vmInstance.getIsoId().longValue());
|
||||
if (userVm.getIsoId() != null) {
|
||||
VMTemplateVO iso = getManagementServer().findTemplateById(userVm.getIsoId().longValue());
|
||||
if (iso != null) {
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ISO_ID.getName(), Long.valueOf(vmInstance.getIsoId()).toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.ISO_NAME.getName(), iso.getName()));
|
||||
userVmResponse.setIsoId(userVm.getIsoId());
|
||||
userVmResponse.setIsoName(iso.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Service Offering Info
|
||||
ServiceOfferingVO offering = getManagementServer().findServiceOfferingById(vmInstance.getServiceOfferingId());
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.SERVICE_OFFERING_ID.getName(), Long.valueOf(vmInstance.getServiceOfferingId()).toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.SERVICE_OFFERING_NAME.getName(), offering.getName()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CPU_NUMBER.getName(), Integer.valueOf(offering.getCpu()).toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CPU_SPEED.getName(), Integer.valueOf(offering.getSpeed()).toString()));
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.MEMORY.getName(), Integer.valueOf(offering.getRamSize()).toString()));
|
||||
userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId());
|
||||
userVmResponse.setServiceOfferingName(offering.getName());
|
||||
userVmResponse.setCpuNumber(offering.getCpu());
|
||||
userVmResponse.setCpuSpeed(offering.getSpeed());
|
||||
userVmResponse.setMemory(offering.getRamSize());
|
||||
|
||||
//stats calculation
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
String cpuUsed = null;
|
||||
VmStats vmStats = getManagementServer().getVmStatistics(vmInstance.getId());
|
||||
if (vmStats != null)
|
||||
{
|
||||
VmStats vmStats = getManagementServer().getVmStatistics(userVm.getId());
|
||||
if (vmStats != null) {
|
||||
float cpuUtil = (float) vmStats.getCPUUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.CPU_USED.getName(), cpuUsed));
|
||||
|
||||
userVmResponse.setCpuUsed(cpuUsed);
|
||||
|
||||
long networkKbRead = (long)vmStats.getNetworkReadKBs();
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_KB_READ.getName(), networkKbRead));
|
||||
userVmResponse.setNetworkKbsRead(networkKbRead);
|
||||
|
||||
long networkKbWrite = (long)vmStats.getNetworkWriteKBs();
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_KB_WRITE.getName(), networkKbWrite));
|
||||
userVmResponse.setNetworkKbsWrite(networkKbWrite);
|
||||
}
|
||||
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.OS_TYPE_ID.getName(),vmInstance.getGuestOSId()));
|
||||
userVmResponse.setOsTypeId(userVm.getGuestOSId());
|
||||
|
||||
//network groups
|
||||
vmData.add(new Pair<String, Object>(BaseCmd.Properties.NETWORK_GROUP_LIST.getName(), getManagementServer().getNetworkGroupsNamesForVm(vmInstance.getId())));
|
||||
|
||||
vmTag[i++] = vmData;
|
||||
userVmResponse.setNetworkGroupList(getManagementServer().getNetworkGroupsNamesForVm(userVm.getId()));
|
||||
|
||||
response.add(userVmResponse);
|
||||
}
|
||||
List<Pair<String, Object>> returnTags = new ArrayList<Pair<String, Object>>();
|
||||
Pair<String, Object> vmTags = new Pair<String, Object>("virtualmachine", vmTag);
|
||||
returnTags.add(vmTags);
|
||||
return returnTags;
|
||||
|
||||
return SerializerHelper.toSerializedString(response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package com.cloud.api.response;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.cloud.api.ResponseObject;
|
||||
import com.cloud.serializer.Param;
|
||||
|
||||
|
|
@ -42,6 +44,84 @@ public class UserVmResponse implements ResponseObject {
|
|||
@Param(name="domain")
|
||||
private String domainName;
|
||||
|
||||
@Param(name="created")
|
||||
private Date created;
|
||||
|
||||
@Param(name="state")
|
||||
private String state;
|
||||
|
||||
@Param(name="haenable")
|
||||
private Boolean haEnable;
|
||||
|
||||
@Param(name="group")
|
||||
private String group;
|
||||
|
||||
@Param(name="zoneid")
|
||||
private Long zoneId;
|
||||
|
||||
@Param(name="zonename")
|
||||
private String zoneName;
|
||||
|
||||
@Param(name="hostid")
|
||||
private Long hostId;
|
||||
|
||||
@Param(name="hostname")
|
||||
private String hostName;
|
||||
|
||||
@Param(name="templateid")
|
||||
private Long templateId;
|
||||
|
||||
@Param(name="templatename")
|
||||
private String templateName;
|
||||
|
||||
@Param(name="templatedisplaytext")
|
||||
private String templateDisplayText;
|
||||
|
||||
@Param(name="passwordenabled")
|
||||
private Boolean passwordEnabled;
|
||||
|
||||
@Param(name="isoid")
|
||||
private Long isoId;
|
||||
|
||||
@Param(name="isoname")
|
||||
private String isoName;
|
||||
|
||||
@Param(name="serviceofferingid")
|
||||
private Long serviceOfferingId;
|
||||
|
||||
@Param(name="serviceofferingname")
|
||||
private String serviceOfferingName;
|
||||
|
||||
@Param(name="cpunumber")
|
||||
private Integer cpuNumber;
|
||||
|
||||
@Param(name="cpuspeed")
|
||||
private Integer cpuSpeed;
|
||||
|
||||
@Param(name="memory")
|
||||
private Integer memory;
|
||||
|
||||
@Param(name="cpuused")
|
||||
private String cpuUsed;
|
||||
|
||||
@Param(name="networkkbsread")
|
||||
private Long networkKbsRead;
|
||||
|
||||
@Param(name="networkkbswrite")
|
||||
private Long networkKbsWrite;
|
||||
|
||||
@Param(name="ostypeid")
|
||||
private Long osTypeId;
|
||||
|
||||
@Param(name="networkgrouplist")
|
||||
private String networkGroupList;
|
||||
|
||||
@Param(name="jobid")
|
||||
private Long jobId;
|
||||
|
||||
@Param(name="jobstatus")
|
||||
private Integer jobStatus;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -97,4 +177,212 @@ public class UserVmResponse implements ResponseObject {
|
|||
public void setDomainName(String domainName) {
|
||||
this.domainName = domainName;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Boolean getHaEnable() {
|
||||
return haEnable;
|
||||
}
|
||||
|
||||
public void setHaEnable(Boolean haEnable) {
|
||||
this.haEnable = haEnable;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public void setZoneId(Long zoneId) {
|
||||
this.zoneId = zoneId;
|
||||
}
|
||||
|
||||
public String getZoneName() {
|
||||
return zoneName;
|
||||
}
|
||||
|
||||
public void setZoneName(String zoneName) {
|
||||
this.zoneName = zoneName;
|
||||
}
|
||||
|
||||
public Long getHostId() {
|
||||
return hostId;
|
||||
}
|
||||
|
||||
public void setHostId(Long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
||||
public void setHostName(String hostName) {
|
||||
this.hostName = hostName;
|
||||
}
|
||||
|
||||
public Long getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
public void setTemplateId(Long templateId) {
|
||||
this.templateId = templateId;
|
||||
}
|
||||
|
||||
public String getTemplateName() {
|
||||
return templateName;
|
||||
}
|
||||
|
||||
public void setTemplateName(String templateName) {
|
||||
this.templateName = templateName;
|
||||
}
|
||||
|
||||
public String getTemplateDisplayText() {
|
||||
return templateDisplayText;
|
||||
}
|
||||
|
||||
public void setTemplateDisplayText(String templateDisplayText) {
|
||||
this.templateDisplayText = templateDisplayText;
|
||||
}
|
||||
|
||||
public Boolean getPasswordEnabled() {
|
||||
return passwordEnabled;
|
||||
}
|
||||
|
||||
public void setPasswordEnabled(Boolean passwordEnabled) {
|
||||
this.passwordEnabled = passwordEnabled;
|
||||
}
|
||||
|
||||
public Long getIsoId() {
|
||||
return isoId;
|
||||
}
|
||||
|
||||
public void setIsoId(Long isoId) {
|
||||
this.isoId = isoId;
|
||||
}
|
||||
|
||||
public String getIsoName() {
|
||||
return isoName;
|
||||
}
|
||||
|
||||
public void setIsoName(String isoName) {
|
||||
this.isoName = isoName;
|
||||
}
|
||||
|
||||
public Long getServiceOfferingId() {
|
||||
return serviceOfferingId;
|
||||
}
|
||||
|
||||
public void setServiceOfferingId(Long serviceOfferingId) {
|
||||
this.serviceOfferingId = serviceOfferingId;
|
||||
}
|
||||
|
||||
public String getServiceOfferingName() {
|
||||
return serviceOfferingName;
|
||||
}
|
||||
|
||||
public void setServiceOfferingName(String serviceOfferingName) {
|
||||
this.serviceOfferingName = serviceOfferingName;
|
||||
}
|
||||
|
||||
public Integer getCpuNumber() {
|
||||
return cpuNumber;
|
||||
}
|
||||
|
||||
public void setCpuNumber(Integer cpuNumber) {
|
||||
this.cpuNumber = cpuNumber;
|
||||
}
|
||||
|
||||
public Integer getCpuSpeed() {
|
||||
return cpuSpeed;
|
||||
}
|
||||
|
||||
public void setCpuSpeed(Integer cpuSpeed) {
|
||||
this.cpuSpeed = cpuSpeed;
|
||||
}
|
||||
|
||||
public Integer getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
public void setMemory(Integer memory) {
|
||||
this.memory = memory;
|
||||
}
|
||||
|
||||
public String getCpuUsed() {
|
||||
return cpuUsed;
|
||||
}
|
||||
|
||||
public void setCpuUsed(String cpuUsed) {
|
||||
this.cpuUsed = cpuUsed;
|
||||
}
|
||||
|
||||
public Long getNetworkKbsRead() {
|
||||
return networkKbsRead;
|
||||
}
|
||||
|
||||
public void setNetworkKbsRead(Long networkKbsRead) {
|
||||
this.networkKbsRead = networkKbsRead;
|
||||
}
|
||||
|
||||
public Long getNetworkKbsWrite() {
|
||||
return networkKbsWrite;
|
||||
}
|
||||
|
||||
public void setNetworkKbsWrite(Long networkKbsWrite) {
|
||||
this.networkKbsWrite = networkKbsWrite;
|
||||
}
|
||||
|
||||
public Long getOsTypeId() {
|
||||
return osTypeId;
|
||||
}
|
||||
|
||||
public void setOsTypeId(Long osTypeId) {
|
||||
this.osTypeId = osTypeId;
|
||||
}
|
||||
|
||||
public String getNetworkGroupList() {
|
||||
return networkGroupList;
|
||||
}
|
||||
|
||||
public void setNetworkGroupList(String networkGroupList) {
|
||||
this.networkGroupList = networkGroupList;
|
||||
}
|
||||
|
||||
public Long getJobId() {
|
||||
return jobId;
|
||||
}
|
||||
|
||||
public void setJobId(Long jobId) {
|
||||
this.jobId = jobId;
|
||||
}
|
||||
|
||||
public Integer getJobStatus() {
|
||||
return jobStatus;
|
||||
}
|
||||
|
||||
public void setJobStatus(Integer jobStatus) {
|
||||
this.jobStatus = jobStatus;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ import com.cloud.api.commands.ListSystemVMsCmd;
|
|||
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
|
||||
import com.cloud.api.commands.ListTemplatesCmd;
|
||||
import com.cloud.api.commands.ListUsersCmd;
|
||||
import com.cloud.api.commands.ListVMsCmd;
|
||||
import com.cloud.api.commands.ListVlanIpRangesCmd;
|
||||
import com.cloud.api.commands.LockAccountCmd;
|
||||
import com.cloud.api.commands.LockUserCmd;
|
||||
|
|
@ -1101,6 +1102,14 @@ public interface ManagementServer {
|
|||
*/
|
||||
List<UserVmVO> searchForUserVMs(Criteria c);
|
||||
|
||||
/**
|
||||
* Obtains a list of virtual machines by the specified search criteria.
|
||||
* Can search by: "userId", "name", "state", "dataCenterId", "podId", "hostId"
|
||||
* @param cmd the API command that wraps the search criteria
|
||||
* @return List of UserVMs.
|
||||
*/
|
||||
List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException;
|
||||
|
||||
/**
|
||||
* Update an existing port forwarding rule on the given public IP / public port for the given protocol
|
||||
* @param userId id of the user performing the action
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ import com.cloud.api.commands.ListSystemVMsCmd;
|
|||
import com.cloud.api.commands.ListTemplateOrIsoPermissionsCmd;
|
||||
import com.cloud.api.commands.ListTemplatesCmd;
|
||||
import com.cloud.api.commands.ListUsersCmd;
|
||||
import com.cloud.api.commands.ListVMsCmd;
|
||||
import com.cloud.api.commands.ListVlanIpRangesCmd;
|
||||
import com.cloud.api.commands.LockAccountCmd;
|
||||
import com.cloud.api.commands.LockUserCmd;
|
||||
|
|
@ -4894,13 +4895,62 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return _templateHostDao.findByHostTemplate(secondaryStorageHost.getId(), templateId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> listUserVMsByHostId(long hostId) {
|
||||
return _userVmDao.listByHostId(hostId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> searchForUserVMs(ListVMsCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
|
||||
Account account = (Account)UserContext.current().getAccountObject();
|
||||
Long domainId = cmd.getDomainId();
|
||||
String accountName = cmd.getAccountName();
|
||||
Long accountId = null;
|
||||
boolean isAdmin = false;
|
||||
if ((account == null) || isAdmin(account.getType())) {
|
||||
isAdmin = true;
|
||||
if (domainId != null) {
|
||||
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
|
||||
throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list virtual machines.");
|
||||
}
|
||||
|
||||
if (accountName != null) {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
if (account == null) {
|
||||
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
|
||||
}
|
||||
accountId = account.getId();
|
||||
}
|
||||
} else {
|
||||
domainId = ((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
|
||||
}
|
||||
} else {
|
||||
accountName = account.getAccountName();
|
||||
accountId = account.getId();
|
||||
domainId = account.getDomainId();
|
||||
}
|
||||
|
||||
Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
c.addCriteria(Criteria.KEYWORD, cmd.getKeyword());
|
||||
c.addCriteria(Criteria.ID, cmd.getId());
|
||||
c.addCriteria(Criteria.NAME, cmd.getInstanceName());
|
||||
c.addCriteria(Criteria.STATE, cmd.getState());
|
||||
c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId());
|
||||
|
||||
// ignore these search requests if it's not an admin
|
||||
if (isAdmin == true) {
|
||||
c.addCriteria(Criteria.DOMAINID, domainId);
|
||||
c.addCriteria(Criteria.PODID, cmd.getPodId());
|
||||
c.addCriteria(Criteria.HOSTID, cmd.getHostId());
|
||||
}
|
||||
|
||||
c.addCriteria(Criteria.ACCOUNTID, accountId);
|
||||
c.addCriteria(Criteria.ISADMIN, isAdmin);
|
||||
|
||||
return searchForUserVMs(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> searchForUserVMs(Criteria c) {
|
||||
Filter searchFilter = new Filter(UserVmVO.class, c.getOrderBy(), c.getAscending(), c.getOffset(), c.getLimit());
|
||||
|
|
|
|||
Loading…
Reference in New Issue