Skip to content

Commit e56dc40

Browse files
committed
Add volume attachement list and show commands, fix detach command
1 parent d44a23c commit e56dc40

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

nova-client/src/main/java/com/woorea/openstack/nova/api/ServersResource.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.woorea.openstack.nova.model.ServerForCreate;
3434
import com.woorea.openstack.nova.model.Servers;
3535
import com.woorea.openstack.nova.model.VolumeAttachment;
36+
import com.woorea.openstack.nova.model.VolumeAttachments;
3637

3738
public class ServersResource {
3839

@@ -429,12 +430,24 @@ public AttachVolume(String serverId, final VolumeAttachment volumeAttachment) {
429430

430431
public class DetachVolume extends OpenStackRequest<Void> {
431432

432-
private String serverId;
433+
public DetachVolume(String serverId, String volumeId) {
434+
super(CLIENT, HttpMethod.DELETE, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments/").append(volumeId), null, Void.class);
435+
}
436+
437+
}
438+
439+
public class ListVolumeAttachments extends OpenStackRequest<VolumeAttachments> {
433440

434-
private String volumeId;
441+
public ListVolumeAttachments(String serverId) {
442+
super(CLIENT, HttpMethod.GET, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments"), null, VolumeAttachments.class);
443+
}
444+
445+
}
446+
447+
public class ShowVolumeAttachment extends OpenStackRequest<VolumeAttachment> {
435448

436-
public DetachVolume(String serverId, String volumeId) {
437-
super(CLIENT, HttpMethod.DELETE, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments").append(volumeId), null, Void.class);
449+
public ShowVolumeAttachment(String serverId, String volumeAttachmentId) {
450+
super(CLIENT, HttpMethod.GET, new StringBuilder("/servers/").append(serverId).append("/os-volume_attachments/").append(volumeAttachmentId), null, VolumeAttachment.class);
438451
}
439452

440453
}
@@ -450,5 +463,13 @@ public DetachVolume detachVolume(String serverId, String volumeId) {
450463
return new DetachVolume(serverId, volumeId);
451464
}
452465

466+
public ListVolumeAttachments listVolumeAttachments(String serverId) {
467+
return new ListVolumeAttachments(serverId);
468+
}
469+
470+
public ShowVolumeAttachment showVolumeAttachment(String serverId, String volumeAttachmentId) {
471+
return new ShowVolumeAttachment(serverId, volumeAttachmentId);
472+
}
473+
453474
}
454475

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.woorea.openstack.nova.model;
2+
3+
import java.io.Serializable;
4+
import java.util.Iterator;
5+
import java.util.List;
6+
7+
import org.codehaus.jackson.annotate.JsonProperty;
8+
9+
public class VolumeAttachments implements Iterable<VolumeAttachment>, Serializable {
10+
11+
@JsonProperty("volumeAttachments")
12+
private List<VolumeAttachment> list;
13+
14+
/**
15+
* @return the list
16+
*/
17+
public List<VolumeAttachment> getList() {
18+
return list;
19+
}
20+
21+
@Override
22+
public Iterator<VolumeAttachment> iterator() {
23+
return list.iterator();
24+
}
25+
26+
/* (non-Javadoc)
27+
* @see java.lang.Object#toString()
28+
*/
29+
@Override
30+
public String toString() {
31+
return "VolumeAttachments [list=" + list + "]";
32+
}
33+
34+
}

0 commit comments

Comments
 (0)