-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #500 - Use enums for Block Device Mappings
- Loading branch information
Showing
4 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
core/src/main/java/org/openstack4j/model/compute/BDMDestType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
core/src/main/java/org/openstack4j/model/compute/BDMSourceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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; | ||
} | ||
|