mirror of https://github.com/apache/jclouds.git
Merge pull request #812 from richardcloudsoft/cloudstack-template-status
Update parsing of Status in CloudStack Template
This commit is contained in:
commit
9578b5a24d
|
@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import java.beans.ConstructorProperties;
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
@ -82,9 +83,14 @@ public class Template implements Comparable<Template> {
|
||||||
UPLOAD_IN_PROGRESS, UNRECOGNIZED;
|
UPLOAD_IN_PROGRESS, UNRECOGNIZED;
|
||||||
|
|
||||||
public static Status fromValue(String state) {
|
public static Status fromValue(String state) {
|
||||||
if (state.equals("Download Complete")) {
|
// Statuses are in free text form. These are the ones in CloudStack 3.0.4 source
|
||||||
return DOWNLOADED;
|
// https://github.com/CloudStack/CloudStack/blob/e2e76c70ec51bfb35d755371f6c33856cef8a277/server/src/com/cloud/api/ApiResponseHelper.java#L1968
|
||||||
}
|
if (Strings.isNullOrEmpty(state)) { return UNKNOWN; }
|
||||||
|
else if (state.equals("Processing")) { return DOWNLOAD_IN_PROGRESS; }
|
||||||
|
else if (state.endsWith("% Downloaded")) { return DOWNLOAD_IN_PROGRESS; }
|
||||||
|
else if (state.equals("Installing Template")) { return DOWNLOAD_IN_PROGRESS; }
|
||||||
|
else if (state.equals("Installing ISO")) { return DOWNLOAD_IN_PROGRESS; }
|
||||||
|
else if (state.equals("Download Complete")) { return DOWNLOADED; }
|
||||||
try {
|
try {
|
||||||
return valueOf(checkNotNull(state, "state"));
|
return valueOf(checkNotNull(state, "state"));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
@ -646,6 +652,14 @@ public class Template implements Comparable<Template> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Retrieve the status of the template.
|
||||||
|
*
|
||||||
|
* <p>Note that in CloudStack 2.2.x through to at least 3.0.4, the possible status values are
|
||||||
|
* not well defined by CloudStack. CloudStack returns a plain-text English string for UI
|
||||||
|
* display, which jclouds attempts to parse into an enumeration, but the mapping is incomplete.
|
||||||
|
* This method should be reliable for the common cases, but it is possible (particularly for
|
||||||
|
* error statuses) that this method will return UNRECOGNIZED.</p>
|
||||||
|
*
|
||||||
* @return status of the template
|
* @return status of the template
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
Loading…
Reference in New Issue