mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1129: [EC2 Query API] DescribeVolumes, add support for filter attachment.status
1. If volume is attached to a VM set attachment state based on the state of the VM it is attached to. Running, Starting, Stopped -> Attached Starting -> Attaching Destroyed, Error -> Detached 2. If volume is not attached to a VM set attachment state as 'detached'
This commit is contained in:
parent
cd039206d3
commit
c26b02a0a7
|
|
@ -1290,7 +1290,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
|||
param5.setInstanceId(vol.getInstanceId().toString());
|
||||
String devicePath = engine.cloudDeviceIdToDevicePath( vol.getHypervisor(), vol.getDeviceId());
|
||||
param5.setDevice( devicePath );
|
||||
param5.setStatus( toVolumeAttachmentState( vol.getInstanceId(), vol.getVMState()));
|
||||
param5.setStatus(vol.getAttachmentState());
|
||||
if (vol.getAttached() == null) {
|
||||
param5.setAttachTime( cal );
|
||||
} else {
|
||||
|
|
@ -1546,25 +1546,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
|||
else if (cloudState.equalsIgnoreCase( "Expunging" )) return new String( "terminated");
|
||||
else return new String( "running" );
|
||||
}
|
||||
|
||||
/**
|
||||
* We assume a state for the volume based on what its associated VM is doing.
|
||||
*
|
||||
* @param vmId
|
||||
* @param vmState
|
||||
* @return
|
||||
*/
|
||||
public static String toVolumeAttachmentState(String instanceId, String vmState ) {
|
||||
if (null == instanceId || null == vmState) return "detached";
|
||||
|
||||
if (vmState.equalsIgnoreCase( "Destroyed" )) return "detached";
|
||||
else if (vmState.equalsIgnoreCase( "Stopped" )) return "attached";
|
||||
else if (vmState.equalsIgnoreCase( "Running" )) return "attached";
|
||||
else if (vmState.equalsIgnoreCase( "Starting" )) return "attaching";
|
||||
else if (vmState.equalsIgnoreCase( "Stopping" )) return "attached";
|
||||
else if (vmState.equalsIgnoreCase( "Error" )) return "detached";
|
||||
else return "detached";
|
||||
}
|
||||
|
||||
|
||||
public static StopInstancesResponse toStopInstancesResponse(EC2StopInstancesResponse engineResponse) {
|
||||
StopInstancesResponse response = new StopInstancesResponse();
|
||||
|
|
@ -1808,10 +1790,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
|||
param1.setVolumeId( engineResponse.getId().toString());
|
||||
param1.setInstanceId( engineResponse.getInstanceId().toString());
|
||||
param1.setDevice( engineResponse.getDevice());
|
||||
if ( null != engineResponse.getState())
|
||||
param1.setStatus( engineResponse.getState());
|
||||
else param1.setStatus( "" ); // ToDo - throw an Soap Fault
|
||||
|
||||
param1.setStatus(engineResponse.getAttachmentState());
|
||||
param1.setAttachTime( cal );
|
||||
|
||||
param1.setRequestId( UUID.randomUUID().toString());
|
||||
|
|
@ -1828,10 +1807,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
|
|||
param1.setVolumeId( engineResponse.getId().toString());
|
||||
param1.setInstanceId( (null == engineResponse.getInstanceId() ? "" : engineResponse.getInstanceId().toString()));
|
||||
param1.setDevice( (null == engineResponse.getDevice() ? "" : engineResponse.getDevice()));
|
||||
if ( null != engineResponse.getState())
|
||||
param1.setStatus( engineResponse.getState());
|
||||
else param1.setStatus( "" ); // ToDo - throw an Soap Fault
|
||||
|
||||
param1.setStatus(engineResponse.getAttachmentState());
|
||||
param1.setAttachTime( cal );
|
||||
|
||||
param1.setRequestId( UUID.randomUUID().toString());
|
||||
|
|
|
|||
|
|
@ -1125,6 +1125,7 @@ public class EC2Engine extends ManagerBase {
|
|||
resp.setState(vol.getState());
|
||||
resp.setType(vol.getVolumeType());
|
||||
resp.setVMState(vol.getVirtualMachineState());
|
||||
resp.setAttachmentState(mapToAmazonVolumeAttachmentState(vol.getVirtualMachineState()));
|
||||
resp.setZoneName(vol.getZoneName());
|
||||
return resp;
|
||||
}
|
||||
|
|
@ -1211,6 +1212,7 @@ public class EC2Engine extends ManagerBase {
|
|||
resp.setState(vol.getState());
|
||||
resp.setType(vol.getVolumeType());
|
||||
resp.setVMState(vol.getVirtualMachineState());
|
||||
resp.setAttachmentState("detached");
|
||||
resp.setZoneName(vol.getZoneName());
|
||||
return resp;
|
||||
}
|
||||
|
|
@ -1639,11 +1641,16 @@ public class EC2Engine extends ManagerBase {
|
|||
ec2Vol.setSize(vol.getSize());
|
||||
ec2Vol.setType(vol.getVolumeType());
|
||||
|
||||
if(vol.getVirtualMachineId() != null)
|
||||
if(vol.getVirtualMachineId() != null) {
|
||||
ec2Vol.setInstanceId(vol.getVirtualMachineId());
|
||||
if (vol.getVirtualMachineState() != null) {
|
||||
ec2Vol.setVMState(vol.getVirtualMachineState());
|
||||
ec2Vol.setAttachmentState(mapToAmazonVolumeAttachmentState(vol.getVirtualMachineState()));
|
||||
}
|
||||
} else {
|
||||
ec2Vol.setAttachmentState("detached");
|
||||
}
|
||||
|
||||
if(vol.getVirtualMachineState() != null)
|
||||
ec2Vol.setVMState(vol.getVirtualMachineState());
|
||||
ec2Vol.setZoneName(vol.getZoneName());
|
||||
|
||||
List<CloudStackKeyValue> resourceTags = vol.getTags();
|
||||
|
|
@ -2404,6 +2411,25 @@ public class EC2Engine extends ManagerBase {
|
|||
return "error";
|
||||
}
|
||||
|
||||
/**
|
||||
* Map CloudStack VM state to Amazon volume attachment state
|
||||
*
|
||||
* @param CloudStack VM state
|
||||
* @return Amazon Volume attachment state
|
||||
*/
|
||||
private String mapToAmazonVolumeAttachmentState (String vmState) {
|
||||
if ( vmState.equalsIgnoreCase("Running") || vmState.equalsIgnoreCase("Stopping") ||
|
||||
vmState.equalsIgnoreCase("Stopped") ) {
|
||||
return "attached";
|
||||
}
|
||||
else if (vmState.equalsIgnoreCase("Starting")) {
|
||||
return "attaching";
|
||||
}
|
||||
else { // VM state is 'destroyed' or 'error' or other
|
||||
return "detached";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map Amazon resourceType to CloudStack resourceType
|
||||
*
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ public class EC2Volume {
|
|||
private String hypervisor;
|
||||
private String created;
|
||||
private String attached;
|
||||
private String attachmentState;
|
||||
private List<EC2TagKeyValue> tagsSet;
|
||||
|
||||
public EC2Volume() {
|
||||
|
|
@ -50,6 +51,7 @@ public class EC2Volume {
|
|||
hypervisor = null;
|
||||
created = null;
|
||||
attached = null;
|
||||
attachmentState = null;
|
||||
tagsSet = new ArrayList<EC2TagKeyValue>();
|
||||
}
|
||||
|
||||
|
|
@ -236,6 +238,20 @@ public class EC2Volume {
|
|||
this.attached = attached;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state of the attached VM to set
|
||||
*/
|
||||
public void setAttachmentState(String attachedState) {
|
||||
this.attachmentState = attachedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return state of the vm
|
||||
*/
|
||||
public String getAttachmentState() {
|
||||
return attachmentState;
|
||||
}
|
||||
|
||||
public void addResourceTag( EC2TagKeyValue param ) {
|
||||
tagsSet.add( param );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class EC2VolumeFilterSet {
|
|||
filterTypes.put( "attachment.delete-on-termination", "null" );
|
||||
filterTypes.put( "attachment.device", "string" );
|
||||
filterTypes.put( "attachment.instance-id", "string" );
|
||||
filterTypes.put( "attachment.status", "null" );
|
||||
filterTypes.put( "attachment.status", "set:attached|attaching|detached|detaching" );
|
||||
filterTypes.put( "availability-zone", "string" );
|
||||
filterTypes.put( "create-time", "xsd:dateTime" );
|
||||
filterTypes.put( "size", "integer" );
|
||||
|
|
@ -136,6 +136,9 @@ public class EC2VolumeFilterSet {
|
|||
return containsDevice(vol.getDeviceId(), valueSet );
|
||||
else if (filterName.equalsIgnoreCase( "attachment.instance-id" ))
|
||||
return containsString(String.valueOf(vol.getInstanceId()), valueSet );
|
||||
else if ( filterName.equalsIgnoreCase( "attachment.status" ) ) {
|
||||
return containsString(vol.getAttachmentState(), valueSet );
|
||||
}
|
||||
else if (filterName.equalsIgnoreCase("tag-key"))
|
||||
{
|
||||
EC2TagKeyValue[] tagSet = vol.getResourceTags();
|
||||
|
|
|
|||
Loading…
Reference in New Issue