mirror of https://github.com/apache/jclouds.git
additional region-related fixes for clojure wrappers
This commit is contained in:
parent
9c772c54aa
commit
fb5d3067cf
|
@ -24,7 +24,7 @@
|
||||||
(:use (clojure.contrib def core))
|
(:use (clojure.contrib def core))
|
||||||
(:import org.jclouds.aws.domain.Region
|
(:import org.jclouds.aws.domain.Region
|
||||||
org.jclouds.compute.domain.NodeMetadata
|
org.jclouds.compute.domain.NodeMetadata
|
||||||
(org.jclouds.aws.ec2.domain Volume Snapshot AvailabilityZone)
|
(org.jclouds.aws.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZone)
|
||||||
(org.jclouds.aws.ec2.options DescribeSnapshotsOptions DetachVolumeOptions CreateSnapshotOptions)))
|
(org.jclouds.aws.ec2.options DescribeSnapshotsOptions DetachVolumeOptions CreateSnapshotOptions)))
|
||||||
|
|
||||||
(defn snapshot?
|
(defn snapshot?
|
||||||
|
@ -46,16 +46,16 @@
|
||||||
.getContext .getProviderSpecificContext .getApi .getElasticBlockStoreServices))
|
.getContext .getProviderSpecificContext .getApi .getElasticBlockStoreServices))
|
||||||
|
|
||||||
(defn get-region
|
(defn get-region
|
||||||
"Returns the first argument as the corresponding Region if it is a
|
"Coerces the first parameter into a Region string; strings, keywords, and
|
||||||
keyword or already a Region instance. An optional second argument
|
NodeMetadata instances are acceptable arguments. An optional second argument
|
||||||
is returned if the first cannot be coerced into a Region.
|
is returned if the first cannot be coerced into a region string.
|
||||||
Returns nil otherwise."
|
Returns nil otherwise."
|
||||||
([v] (get-region v nil))
|
([v] (get-region v nil))
|
||||||
([v default-region]
|
([v default-region]
|
||||||
(cond
|
(cond
|
||||||
|
(string? v) v
|
||||||
(keyword? v) (name v)
|
(keyword? v) (name v)
|
||||||
(instance? Region v) v
|
(instance? NodeMetadata v) (let [zone (compute/location v)]
|
||||||
(instance? NodeMetadata v) (let [zone (.getLocationId v)]
|
|
||||||
; no easier way to go from zone -> region?
|
; no easier way to go from zone -> region?
|
||||||
(if (> (.indexOf zone "-") -1)
|
(if (> (.indexOf zone "-") -1)
|
||||||
(subs zone 0 (-> zone count dec))
|
(subs zone 0 (-> zone count dec))
|
||||||
|
@ -119,7 +119,7 @@
|
||||||
"Returns a set of org.jclouds.aws.ec2.domain.Snapshot instances that match
|
"Returns a set of org.jclouds.aws.ec2.domain.Snapshot instances that match
|
||||||
the criteria provided. Options include:
|
the criteria provided. Options include:
|
||||||
|
|
||||||
:region - region string or keyword
|
:region - region string, keyword, or NodeMetadata
|
||||||
:owner - AWS account id (or \"amazon\" or \"self\")
|
:owner - AWS account id (or \"amazon\" or \"self\")
|
||||||
:restorable-by - AWS account id
|
:restorable-by - AWS account id
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
[v]
|
[v]
|
||||||
(cond
|
(cond
|
||||||
(instance? AvailabilityZone v) v
|
(instance? AvailabilityZone v) v
|
||||||
(instance? NodeMetadata v) (.getLocationId #^NodeMetadata v)
|
(instance? NodeMetadata v) (compute/location #^NodeMetadata v)
|
||||||
(string? v) v
|
(string? v) v
|
||||||
(keyword? v) (name v)
|
(keyword? v) (name v)
|
||||||
:else (throw (IllegalArgumentException.
|
:else (throw (IllegalArgumentException.
|
||||||
|
@ -282,4 +282,37 @@
|
||||||
([region volume-id]
|
([region volume-id]
|
||||||
(.deleteVolumeInRegion (ebs-service)
|
(.deleteVolumeInRegion (ebs-service)
|
||||||
(get-region region)
|
(get-region region)
|
||||||
(as-string volume-id))))
|
(as-string volume-id))))
|
||||||
|
|
||||||
|
(defn status
|
||||||
|
"Returns the status of the given entity; works for Volumes and Snapshots."
|
||||||
|
[k]
|
||||||
|
(.getStatus k))
|
||||||
|
|
||||||
|
(defn status-available?
|
||||||
|
[#^Volume v]
|
||||||
|
(= Volume$Status/AVAILABLE (status v)))
|
||||||
|
|
||||||
|
(defn status-creating?
|
||||||
|
[#^Volume v]
|
||||||
|
(= Volume$Status/CREATING (status v)))
|
||||||
|
|
||||||
|
(defn status-deleting?
|
||||||
|
[#^Volume v]
|
||||||
|
(= Volume$Status/DELETING (status v)))
|
||||||
|
|
||||||
|
(defn status-in-use?
|
||||||
|
[#^Volume v]
|
||||||
|
(= Volume$Status/IN_USE (status v)))
|
||||||
|
|
||||||
|
(defn status-completed?
|
||||||
|
[#^Snapshot s]
|
||||||
|
(= Snapshot$Status/COMPLETED (status s)))
|
||||||
|
|
||||||
|
(defn status-error?
|
||||||
|
[#^Snapshot s]
|
||||||
|
(= Snapshot$Status/ERROR (status s)))
|
||||||
|
|
||||||
|
(defn status-pending?
|
||||||
|
[#^Snapshot s]
|
||||||
|
(= Snapshot$Status/PENDING (status s)))
|
|
@ -51,7 +51,7 @@ Here's an example of creating and running a small linux node with the tag webser
|
||||||
|
|
||||||
See http://code.google.com/p/jclouds for details."
|
See http://code.google.com/p/jclouds for details."
|
||||||
(:use org.jclouds.core
|
(:use org.jclouds.core
|
||||||
clojure.contrib.logging)
|
(clojure.contrib logging core))
|
||||||
(:import java.io.File
|
(:import java.io.File
|
||||||
java.util.Properties
|
java.util.Properties
|
||||||
[org.jclouds.domain Location]
|
[org.jclouds.domain Location]
|
||||||
|
@ -304,7 +304,7 @@ See http://code.google.com/p/jclouds for details."
|
||||||
(defn location
|
(defn location
|
||||||
"Returns the compute node's location id"
|
"Returns the compute node's location id"
|
||||||
[#^ComputeMetadata node]
|
[#^ComputeMetadata node]
|
||||||
(.getLocationId node))
|
(-?> node .getLocation .getId))
|
||||||
|
|
||||||
(define-accessors Template image size location options)
|
(define-accessors Template image size location options)
|
||||||
(define-accessors Image version os-family os-description architecture)
|
(define-accessors Image version os-family os-description architecture)
|
||||||
|
|
Loading…
Reference in New Issue