From 12b79da6c207071eac02fcfc496e5a4b11922383 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 21 Feb 2012 10:38:40 -0800 Subject: [PATCH] bug 13903: return vm's hostName as a displayName when displayName is null in bunch of api responses status 13903: resolved fixed Reviewed-by: Kelven Yang --- .../api/commands/ListNetworkOfferingsCmd.java | 11 +- .../com/cloud/api/response/IsoVmResponse.java | 146 ------------------ .../src/com/cloud/api/ApiResponseHelper.java | 25 ++- .../ConfigurationManagerImpl.java | 5 + 4 files changed, 34 insertions(+), 153 deletions(-) delete mode 100755 api/src/com/cloud/api/response/IsoVmResponse.java diff --git a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java index 692f923abeb..98ffe270d91 100644 --- a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java @@ -84,11 +84,12 @@ public class ListNetworkOfferingsCmd extends BaseListCmd { @Parameter(name=ApiConstants.SOURCE_NAT_SUPPORTED, type=CommandType.BOOLEAN, description="true if need to list only netwok offerings where source nat is supported, false otherwise") private Boolean sourceNatSupported; - - @Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only network offerings which support specifying ip ranges") private Boolean specifyIpRanges; + @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="list network offerings by tags", length=4096) + private String tags; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -149,7 +150,11 @@ public class ListNetworkOfferingsCmd extends BaseListCmd { return specifyIpRanges; } - ///////////////////////////////////////////////////// + public String getTags() { + return tags; + } + + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @Override diff --git a/api/src/com/cloud/api/response/IsoVmResponse.java b/api/src/com/cloud/api/response/IsoVmResponse.java deleted file mode 100755 index 1da14f9fdd7..00000000000 --- a/api/src/com/cloud/api/response/IsoVmResponse.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package com.cloud.api.response; - -import com.cloud.api.IdentityProxy; -import com.cloud.serializer.Param; -import com.google.gson.annotations.SerializedName; - -public class IsoVmResponse extends BaseResponse { - @SerializedName("id") @Param(description="the ISO ID") - private IdentityProxy id = new IdentityProxy("vm_template"); - - @SerializedName("name") @Param(description="the ISO name") - private String name; - - @SerializedName("displaytext") @Param(description="the ISO display text") - private String displayText; - - @SerializedName("bootable") @Param(description="true if the ISO is bootable, false otherwise") - private Boolean bootable; - - @SerializedName("isfeatured") @Param(description="true if this template is a featured template, false otherwise") - private Boolean featured; - - @SerializedName("ostypeid") @Param(description="the ID of the OS type for this template.") - private IdentityProxy osTypeId = new IdentityProxy("guest_os"); - - @SerializedName("ostypename") @Param(description="the name of the OS type for this template.") - private String osTypeName; - - @SerializedName("virtualmachineid") @Param(description="id of the virtual machine") - private IdentityProxy virtualMachineId = new IdentityProxy("vm_instance"); - - @SerializedName("vmname") @Param(description="name of the virtual machine") - private String virtualMachineName; - - @SerializedName("vmdisplayname") @Param(description="display name of the virtual machine") - private String virtualMachineDisplayName; - - @SerializedName("vmstate") @Param(description="state of the virtual machine") - private String virtualMachineState; - - - public Long getOsTypeId() { - return osTypeId.getValue(); - } - - public void setOsTypeId(Long osTypeId) { - this.osTypeId.setValue(osTypeId); - } - - public String getOsTypeName() { - return osTypeName; - } - - public void setOsTypeName(String osTypeName) { - this.osTypeName = osTypeName; - } - - public Long getId() { - return id.getValue(); - } - - public void setId(Long id) { - this.id.setValue(id); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDisplayText() { - return displayText; - } - - public void setDisplayText(String displayText) { - this.displayText = displayText; - } - - public Boolean isBootable() { - return bootable; - } - - public void setBootable(Boolean bootable) { - this.bootable = bootable; - } - - public Boolean isFeatured() { - return featured; - } - - public void setFeatured(Boolean featured) { - this.featured = featured; - } - - public Long getVirtualMachineId() { - return virtualMachineId.getValue(); - } - - public void setVirtualMachineId(Long virtualMachineId) { - this.virtualMachineId.setValue(virtualMachineId); - } - - public String getVirtualMachineName() { - return virtualMachineName; - } - - public void setVirtualMachineName(String virtualMachineName) { - this.virtualMachineName = virtualMachineName; - } - - public String getVirtualMachineDisplayName() { - return virtualMachineDisplayName; - } - - public void setVirtualMachineDisplayName(String virtualMachineDisplayName) { - this.virtualMachineDisplayName = virtualMachineDisplayName; - } - - public String getVirtualMachineState() { - return virtualMachineState; - } - - public void setVirtualMachineState(String virtualMachineState) { - this.virtualMachineState = virtualMachineState; - } -} diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 0049a44cec0..b55273c1e11 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -727,7 +727,11 @@ public class ApiResponseHelper implements ResponseGenerator { UserVm vm = ApiDBUtils.findUserVmById(ipAddress.getAssociatedWithVmId()); ipResponse.setVirtualMachineId(vm.getId()); ipResponse.setVirtualMachineName(vm.getHostName()); - ipResponse.setVirtualMachineDisplayName(vm.getDisplayName()); + if (vm.getDisplayName() != null) { + ipResponse.setVirtualMachineDisplayName(vm.getDisplayName()); + } else { + ipResponse.setVirtualMachineDisplayName(vm.getHostName()); + } } ipResponse.setAssociatedNetworkId(ipAddress.getAssociatedWithNetworkId()); @@ -972,7 +976,11 @@ public class ApiResponseHelper implements ResponseGenerator { volResponse.setVirtualMachineName(vm.getHostName()); UserVm userVm = ApiDBUtils.findUserVmById(vm.getId()); if (userVm != null) { - volResponse.setVirtualMachineDisplayName(userVm.getDisplayName()); + if (userVm.getDisplayName() != null) { + volResponse.setVirtualMachineDisplayName(userVm.getDisplayName()); + } else { + volResponse.setVirtualMachineDisplayName(userVm.getHostName()); + } volResponse.setVirtualMachineState(vm.getState().toString()); } else { s_logger.error("User Vm with Id: " + instanceId + " does not exist for volume " + volume.getId()); @@ -1175,7 +1183,12 @@ public class ApiResponseHelper implements ResponseGenerator { if (vm != null) { response.setVirtualMachineId(vm.getId()); response.setVirtualMachineName(vm.getHostName()); - response.setVirtualMachineDisplayName(vm.getDisplayName()); + + if (vm.getDisplayName() != null) { + response.setVirtualMachineDisplayName(vm.getDisplayName()); + } else { + response.setVirtualMachineDisplayName(vm.getHostName()); + } } } FirewallRule.State state = fwRule.getState(); @@ -1203,7 +1216,11 @@ public class ApiResponseHelper implements ResponseGenerator { if (vm != null) {// vm might be destroyed response.setVirtualMachineId(vm.getId()); response.setVirtualMachineName(vm.getHostName()); - response.setVirtualMachineDisplayName(vm.getDisplayName()); + if (vm.getDisplayName() != null) { + response.setVirtualMachineDisplayName(vm.getDisplayName()); + } else { + response.setVirtualMachineDisplayName(vm.getHostName()); + } } } FirewallRule.State state = fwRule.getState(); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index b31c6a1dd83..d9c94dab2f3 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3391,6 +3391,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String guestIpType = cmd.getGuestIpType(); List supportedServicesStr = cmd.getSupportedServices(); Object specifyIpRanges = cmd.getSpecifyIpRanges(); + String tags = cmd.getTags(); if (zoneId != null) { zone = getZone(zoneId); @@ -3483,6 +3484,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (id != null) { sc.addAnd("id", SearchCriteria.Op.EQ, id); } + + if (tags != null) { + sc.addAnd("tags", SearchCriteria.Op.EQ, tags); + } List offerings = _networkOfferingDao.search(sc, searchFilter); Boolean sourceNatSupported = cmd.getSourceNatSupported();