From e56dc405f67233326cdc390478339af893bc8e68 Mon Sep 17 00:00:00 2001 From: Frederic Dang Tran Date: Thu, 18 Jul 2013 15:57:32 +0200 Subject: [PATCH] Add volume attachement list and show commands, fix detach command --- .../openstack/nova/api/ServersResource.java | 29 +++++++++++++--- .../nova/model/VolumeAttachments.java | 34 +++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 nova-model/src/main/java/com/woorea/openstack/nova/model/VolumeAttachments.java diff --git a/nova-client/src/main/java/com/woorea/openstack/nova/api/ServersResource.java b/nova-client/src/main/java/com/woorea/openstack/nova/api/ServersResource.java index 11219bea5..8740afde7 100644 --- a/nova-client/src/main/java/com/woorea/openstack/nova/api/ServersResource.java +++ b/nova-client/src/main/java/com/woorea/openstack/nova/api/ServersResource.java @@ -33,6 +33,7 @@ import com.woorea.openstack.nova.model.ServerForCreate; import com.woorea.openstack.nova.model.Servers; import com.woorea.openstack.nova.model.VolumeAttachment; +import com.woorea.openstack.nova.model.VolumeAttachments; public class ServersResource { @@ -429,12 +430,24 @@ public AttachVolume(String serverId, final VolumeAttachment volumeAttachment) { public class DetachVolume extends OpenStackRequest { - private String serverId; + public DetachVolume(String serverId, String volumeId) { + super(CLIENT, HttpMethod.DELETE, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments/").append(volumeId), null, Void.class); + } + + } + + public class ListVolumeAttachments extends OpenStackRequest { - private String volumeId; + public ListVolumeAttachments(String serverId) { + super(CLIENT, HttpMethod.GET, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments"), null, VolumeAttachments.class); + } + + } + + public class ShowVolumeAttachment extends OpenStackRequest { - public DetachVolume(String serverId, String volumeId) { - super(CLIENT, HttpMethod.DELETE, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments").append(volumeId), null, Void.class); + public ShowVolumeAttachment(String serverId, String volumeAttachmentId) { + super(CLIENT, HttpMethod.GET, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments/").append(volumeAttachmentId), null, VolumeAttachment.class); } } @@ -450,5 +463,13 @@ public DetachVolume detachVolume(String serverId, String volumeId) { return new DetachVolume(serverId, volumeId); } + public ListVolumeAttachments listVolumeAttachments(String serverId) { + return new ListVolumeAttachments(serverId); + } + + public ShowVolumeAttachment showVolumeAttachment(String serverId, String volumeAttachmentId) { + return new ShowVolumeAttachment(serverId, volumeAttachmentId); + } + } diff --git a/nova-model/src/main/java/com/woorea/openstack/nova/model/VolumeAttachments.java b/nova-model/src/main/java/com/woorea/openstack/nova/model/VolumeAttachments.java new file mode 100644 index 000000000..be5ea8e33 --- /dev/null +++ b/nova-model/src/main/java/com/woorea/openstack/nova/model/VolumeAttachments.java @@ -0,0 +1,34 @@ +package com.woorea.openstack.nova.model; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class VolumeAttachments implements Iterable, Serializable { + + @JsonProperty("volumeAttachments") + private List list; + + /** + * @return the list + */ + public List getList() { + return list; + } + + @Override + public Iterator iterator() { + return list.iterator(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "VolumeAttachments [list=" + list + "]"; + } + +}