Skip to content

Commit

Permalink
Issue #500 - Use enums for Block Device Mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
gondor committed Nov 7, 2015
1 parent 6b9510e commit cd165d9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
35 changes: 35 additions & 0 deletions core/src/main/java/org/openstack4j/model/compute/BDMDestType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openstack4j.model.compute;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* Block Device Mapping Destination Type
*
* @author Jeremy Unruh
* @see http://docs.openstack.org/developer/nova/block_device_mapping.html
*/
public enum BDMDestType {

/** Will either mean an ephemeral blank disk on hypervisor local storage, or a swap disk **/
LOCAL,
/** Creates a blank Cinder volume and attaches it. This will also require the volume size to be set **/
VOLUME;

@JsonCreator
public static BDMDestType value(String v) {
if (v == null)
return LOCAL;
try {
return valueOf(v.toUpperCase());
} catch (IllegalArgumentException e) {
return LOCAL;
}
}

@JsonValue
public String value() {
return name().toLowerCase();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openstack4j.model.compute;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* Block Device Mapping Source Type
*
* @author Jeremy Unruh
* @see http://docs.openstack.org/developer/nova/block_device_mapping.html
*/
public enum BDMSourceType {
BLANK,
IMAGE,
SNAPSHOT,
VOLUME
;

@JsonCreator
public static BDMSourceType value(String v) {
if (v == null)
return VOLUME;
try {
return valueOf(v.toUpperCase());
} catch (IllegalArgumentException e) {
return VOLUME;
}
}

@JsonValue
public String value() {
return name().toLowerCase();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.openstack4j.model.compute.builder;

import org.openstack4j.common.Buildable;
import org.openstack4j.model.compute.BDMDestType;
import org.openstack4j.model.compute.BDMSourceType;
import org.openstack4j.model.compute.BlockDeviceMappingCreate;

/**
Expand Down Expand Up @@ -40,15 +42,15 @@ public interface BlockDeviceMappingBuilder extends Buildable.Builder<BlockDevice
* @param type the destination type
* @return BlockDeviceMappingBuilder
*/
BlockDeviceMappingBuilder destinationType(String type);
BlockDeviceMappingBuilder destinationType(BDMDestType type);

/**
* Either snap or any other value, including a blank string. snap means that the volume was created from a snapshot.
*
* @param type the source type
* @return BlockDeviceMappingBuilder
*/
BlockDeviceMappingBuilder sourceType(String type);
BlockDeviceMappingBuilder sourceType(BDMSourceType type);

/**
* Set to True to delete the volume when the instance is deleted. Set to False to retain the volume when the instance is deleted.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package org.openstack4j.openstack.compute.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.openstack4j.model.compute.BDMDestType;
import org.openstack4j.model.compute.BDMSourceType;
import org.openstack4j.model.compute.BlockDeviceMappingCreate;
import org.openstack4j.model.compute.builder.BlockDeviceMappingBuilder;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
*
* @author [email protected]
*/
public class NovaBlockDeviceMappingCreate implements BlockDeviceMappingCreate {

public String device_name;
public String source_type = "volume";
public String destination_type = "volume";
public BDMSourceType source_type = BDMSourceType.VOLUME;
public BDMDestType destination_type = BDMDestType.VOLUME;
public String uuid;
public String boot_index;
public Integer volume_size;
Expand Down Expand Up @@ -61,13 +64,13 @@ public BlockDeviceMappingBuilder bootIndex(int i) {
}

@Override
public BlockDeviceMappingBuilder sourceType(String type){
public BlockDeviceMappingBuilder sourceType(BDMSourceType type){
create.source_type = type;
return this;
}

@Override
public BlockDeviceMappingBuilder destinationType(String type){
public BlockDeviceMappingBuilder destinationType(BDMDestType type){
create.destination_type = type;
return this;
}
Expand Down

0 comments on commit cd165d9

Please sign in to comment.