bug 6487: AttachISO API would return an embedded object on success.

status 6487: resolved fixed
This commit is contained in:
nit 2010-10-25 18:26:39 +05:30
parent 5774fd163d
commit 511a095c26
2 changed files with 165 additions and 7 deletions

27
server/src/com/cloud/api/commands/AttachIsoCmd.java Normal file → Executable file
View File

@ -18,6 +18,7 @@
package com.cloud.api.commands;
import org.apache.log4j.Logger;
import org.hamcrest.core.Is;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.BaseAsyncCmd;
@ -26,10 +27,12 @@ import com.cloud.api.BaseCmd.Manager;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.IsoVmResponse;
import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.Account;
import com.cloud.vm.VMInstanceVO;
@Implementation(method="attachIso", manager=Manager.TemplateManager, description="Attaches an ISO to a virtual machine.")
public class AttachIsoCmd extends BaseAsyncCmd {
@ -90,17 +93,27 @@ public class AttachIsoCmd extends BaseAsyncCmd {
}
@Override @SuppressWarnings("unchecked")
public SuccessResponse getResponse() {
SuccessResponse response = new SuccessResponse();
public IsoVmResponse getResponse() {
Boolean responseObject = (Boolean)getResponseObject();
if (responseObject != null) {
response.setSuccess(responseObject);
if (responseObject != null && responseObject != false) {
IsoVmResponse response = new IsoVmResponse();
VMTemplateVO iso = ApiDBUtils.findTemplateById(id);
VMInstanceVO vmInstance = ApiDBUtils.findVMInstanceById(virtualMachineId);
response.setId(id);
response.setName(iso.getName());
response.setDisplayText(iso.getDisplayText());
response.setOsTypeId(iso.getGuestOSId());
response.setOsTypeName(ApiDBUtils.findGuestOSById(iso.getGuestOSId()).getName());
response.setVirtualMachineId(virtualMachineId);
response.setVirtualMachineName(vmInstance.getName());
response.setVirtualMachineState(vmInstance.getState().toString());
response.setResponseName(getName());
return response;
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach iso");
}
response.setResponseName(getName());
return response;
}
}

View File

@ -0,0 +1,145 @@
/**
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.response;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
public class IsoVmResponse extends BaseResponse {
@SerializedName("id") @Param(description="the ISO ID")
private long id;
@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 Long osTypeId;
@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 Long virtualMachineId;
@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;
}
public void setOsTypeId(Long osTypeId) {
this.osTypeId = osTypeId;
}
public String getOsTypeName() {
return osTypeName;
}
public void setOsTypeName(String osTypeName) {
this.osTypeName = osTypeName;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = 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;
}
public void setVirtualMachineId(Long virtualMachineId) {
this.virtualMachineId = 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;
}
}