|
1 | 1 | package com.woorea.openstack.nova.api.extensions; |
2 | 2 |
|
3 | | - |
4 | 3 | import com.woorea.openstack.base.client.Entity; |
5 | 4 | import com.woorea.openstack.base.client.HttpMethod; |
6 | 5 | import com.woorea.openstack.base.client.OpenStackClient; |
7 | 6 | import com.woorea.openstack.base.client.OpenStackRequest; |
8 | 7 | import com.woorea.openstack.nova.model.Metadata; |
9 | 8 | import com.woorea.openstack.nova.model.Volume; |
10 | 9 | import com.woorea.openstack.nova.model.VolumeForCreate; |
| 10 | +import com.woorea.openstack.nova.model.VolumeForImageCreate; |
11 | 11 | import com.woorea.openstack.nova.model.Volumes; |
12 | 12 |
|
13 | 13 | public class VolumesExtension { |
14 | | - |
| 14 | + |
15 | 15 | private final OpenStackClient CLIENT; |
16 | | - |
| 16 | + |
17 | 17 | public VolumesExtension(OpenStackClient client) { |
18 | 18 | CLIENT = client; |
19 | 19 | } |
20 | | - |
| 20 | + |
21 | 21 | public List list(boolean detail) { |
22 | 22 | return new List(detail); |
23 | 23 | } |
24 | | - |
25 | | - public Create create(VolumeForCreate volumeForCreate) { |
26 | | - return new Create(volumeForCreate); |
| 24 | + |
| 25 | + public Create create(VolumeForCreate volume) { |
| 26 | + return new Create(volume); |
| 27 | + } |
| 28 | + |
| 29 | + public UploadToImage uploadToImage(VolumeForImageCreate volumeForImage) { |
| 30 | + return new UploadToImage(volumeForImage); |
27 | 31 | } |
28 | | - |
| 32 | + |
29 | 33 | public Show show(String id) { |
30 | 34 | return new Show(id); |
31 | 35 | } |
32 | | - |
| 36 | + |
33 | 37 | public ShowMetadata showMetadata(String id) { |
34 | 38 | return new ShowMetadata(id); |
35 | 39 | } |
36 | 40 |
|
37 | | - |
38 | 41 | public Delete delete(String id) { |
39 | 42 | return new Delete(id); |
40 | 43 | } |
41 | 44 |
|
42 | 45 | public class List extends OpenStackRequest<Volumes> { |
43 | | - |
| 46 | + |
44 | 47 | public List(boolean detail) { |
45 | | - super(CLIENT, HttpMethod.GET, detail ? "/os-volumes/detail" : "/os-volumes", null, Volumes.class); |
| 48 | + super(CLIENT, HttpMethod.GET, detail ? "/os-volumes/detail" |
| 49 | + : "/os-volumes", null, Volumes.class); |
46 | 50 | } |
47 | 51 |
|
48 | 52 | } |
49 | | - |
| 53 | + |
50 | 54 | public class Create extends OpenStackRequest<Volume> { |
51 | 55 |
|
52 | | - public Create(VolumeForCreate volumeForCreate) { |
53 | | - super(CLIENT, HttpMethod.POST, "/os-volumes", Entity.json(volumeForCreate), Volume.class); |
| 56 | + // private Volume volume; |
| 57 | + |
| 58 | + public Create(VolumeForCreate volume) { |
| 59 | + super(CLIENT, HttpMethod.POST, "/os-volumes", Entity.json(volume), |
| 60 | + Volume.class); |
| 61 | + // this.volume = volume; |
| 62 | + } |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + // Upload volume to image service as image |
| 67 | + |
| 68 | + public class UploadToImage extends OpenStackRequest<Void> { |
| 69 | + |
| 70 | + public UploadToImage(VolumeForImageCreate volumeForImageCreate) { |
| 71 | + super(CLIENT, HttpMethod.POST, new StringBuilder("/volumes/") |
| 72 | + .append(volumeForImageCreate.getVolumeId() + "/action"), |
| 73 | + Entity.json(volumeForImageCreate), Void.class); |
54 | 74 | } |
55 | | - |
| 75 | + |
56 | 76 | } |
57 | | - |
| 77 | + |
58 | 78 | public class Show extends OpenStackRequest<Volume> { |
59 | | - |
| 79 | + |
60 | 80 | public Show(String id) { |
61 | | - super(CLIENT, HttpMethod.GET, new StringBuilder("/os-volumes/").append(id).toString(), null, Volume.class); |
| 81 | + super(CLIENT, HttpMethod.GET, new StringBuilder("/os-volumes/") |
| 82 | + .append(id).toString(), null, Volume.class); |
62 | 83 | } |
63 | 84 |
|
64 | 85 | } |
65 | | - |
| 86 | + |
66 | 87 | public class ShowMetadata extends OpenStackRequest<Metadata> { |
67 | | - |
| 88 | + |
68 | 89 | public ShowMetadata(String id) { |
69 | | - super(CLIENT, HttpMethod.GET, new StringBuilder("/os-volumes/").append(id).append("/metadata").toString(), null, Metadata.class); |
| 90 | + super(CLIENT, HttpMethod.GET, new StringBuilder("/os-volumes/") |
| 91 | + .append(id).append("/metadata").toString(), null, |
| 92 | + Metadata.class); |
70 | 93 | } |
71 | 94 |
|
72 | 95 | } |
73 | | - |
| 96 | + |
74 | 97 | public class Delete extends OpenStackRequest<Void> { |
75 | | - |
| 98 | + |
76 | 99 | public Delete(String id) { |
77 | | - super(CLIENT, HttpMethod.DELETE, new StringBuilder("/os-volumes/").append(id).toString(), null, Void.class); |
| 100 | + super(CLIENT, HttpMethod.DELETE, new StringBuilder("/os-volumes/") |
| 101 | + .append(id).toString(), null, Void.class); |
78 | 102 | } |
79 | | - |
| 103 | + |
80 | 104 | } |
81 | | - |
82 | | -} |
83 | 105 |
|
| 106 | +} |
0 commit comments