Skip to content

Commit cd165d9

Browse files
committed
Issue #500 - Use enums for Block Device Mappings
1 parent 6b9510e commit cd165d9

File tree

4 files changed

+82
-7
lines changed

4 files changed

+82
-7
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.openstack4j.model.compute;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
/**
7+
* Block Device Mapping Destination Type
8+
*
9+
* @author Jeremy Unruh
10+
* @see http://docs.openstack.org/developer/nova/block_device_mapping.html
11+
*/
12+
public enum BDMDestType {
13+
14+
/** Will either mean an ephemeral blank disk on hypervisor local storage, or a swap disk **/
15+
LOCAL,
16+
/** Creates a blank Cinder volume and attaches it. This will also require the volume size to be set **/
17+
VOLUME;
18+
19+
@JsonCreator
20+
public static BDMDestType value(String v) {
21+
if (v == null)
22+
return LOCAL;
23+
try {
24+
return valueOf(v.toUpperCase());
25+
} catch (IllegalArgumentException e) {
26+
return LOCAL;
27+
}
28+
}
29+
30+
@JsonValue
31+
public String value() {
32+
return name().toLowerCase();
33+
}
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.openstack4j.model.compute;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonValue;
5+
6+
/**
7+
* Block Device Mapping Source Type
8+
*
9+
* @author Jeremy Unruh
10+
* @see http://docs.openstack.org/developer/nova/block_device_mapping.html
11+
*/
12+
public enum BDMSourceType {
13+
BLANK,
14+
IMAGE,
15+
SNAPSHOT,
16+
VOLUME
17+
;
18+
19+
@JsonCreator
20+
public static BDMSourceType value(String v) {
21+
if (v == null)
22+
return VOLUME;
23+
try {
24+
return valueOf(v.toUpperCase());
25+
} catch (IllegalArgumentException e) {
26+
return VOLUME;
27+
}
28+
}
29+
30+
@JsonValue
31+
public String value() {
32+
return name().toLowerCase();
33+
}
34+
35+
}

core/src/main/java/org/openstack4j/model/compute/builder/BlockDeviceMappingBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.openstack4j.model.compute.builder;
22

33
import org.openstack4j.common.Buildable;
4+
import org.openstack4j.model.compute.BDMDestType;
5+
import org.openstack4j.model.compute.BDMSourceType;
46
import org.openstack4j.model.compute.BlockDeviceMappingCreate;
57

68
/**
@@ -40,15 +42,15 @@ public interface BlockDeviceMappingBuilder extends Buildable.Builder<BlockDevice
4042
* @param type the destination type
4143
* @return BlockDeviceMappingBuilder
4244
*/
43-
BlockDeviceMappingBuilder destinationType(String type);
45+
BlockDeviceMappingBuilder destinationType(BDMDestType type);
4446

4547
/**
4648
* Either snap or any other value, including a blank string. snap means that the volume was created from a snapshot.
4749
*
4850
* @param type the source type
4951
* @return BlockDeviceMappingBuilder
5052
*/
51-
BlockDeviceMappingBuilder sourceType(String type);
53+
BlockDeviceMappingBuilder sourceType(BDMSourceType type);
5254

5355
/**
5456
* Set to True to delete the volume when the instance is deleted. Set to False to retain the volume when the instance is deleted.

core/src/main/java/org/openstack4j/openstack/compute/domain/NovaBlockDeviceMappingCreate.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package org.openstack4j.openstack.compute.domain;
22

3-
import com.fasterxml.jackson.annotation.JsonProperty;
3+
import org.openstack4j.model.compute.BDMDestType;
4+
import org.openstack4j.model.compute.BDMSourceType;
45
import org.openstack4j.model.compute.BlockDeviceMappingCreate;
56
import org.openstack4j.model.compute.builder.BlockDeviceMappingBuilder;
67

8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
710
/**
811
*
912
* @author jaroslav.sovicka@oracle.com
1013
*/
1114
public class NovaBlockDeviceMappingCreate implements BlockDeviceMappingCreate {
1215

1316
public String device_name;
14-
public String source_type = "volume";
15-
public String destination_type = "volume";
17+
public BDMSourceType source_type = BDMSourceType.VOLUME;
18+
public BDMDestType destination_type = BDMDestType.VOLUME;
1619
public String uuid;
1720
public String boot_index;
1821
public Integer volume_size;
@@ -61,13 +64,13 @@ public BlockDeviceMappingBuilder bootIndex(int i) {
6164
}
6265

6366
@Override
64-
public BlockDeviceMappingBuilder sourceType(String type){
67+
public BlockDeviceMappingBuilder sourceType(BDMSourceType type){
6568
create.source_type = type;
6669
return this;
6770
}
6871

6972
@Override
70-
public BlockDeviceMappingBuilder destinationType(String type){
73+
public BlockDeviceMappingBuilder destinationType(BDMDestType type){
7174
create.destination_type = type;
7275
return this;
7376
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy