Merge branch 'master' of github.com:jclouds/jclouds

This commit is contained in:
Ivan Meredith 2010-04-28 10:23:29 +12:00
commit ee38b1e349
1 changed files with 24 additions and 13 deletions

View File

@ -16,7 +16,7 @@
;; ==================================================================== ;; ====================================================================
;; ;;
(ns (ns
#^{:author "Chas Emerick, cemerick@snowtide.com" #^{:author "Chas Emerick, cemerick@snowtide.com"
:doc "A clojure binding to the jclouds EBS service interface."} :doc "A clojure binding to the jclouds EBS service interface."}
org.jclouds.aws.ebs org.jclouds.aws.ebs
@ -27,6 +27,16 @@
(org.jclouds.aws.ec2.domain Volume Snapshot AvailabilityZone) (org.jclouds.aws.ec2.domain Volume Snapshot AvailabilityZone)
(org.jclouds.aws.ec2.options DescribeSnapshotsOptions DetachVolumeOptions CreateSnapshotOptions))) (org.jclouds.aws.ec2.options DescribeSnapshotsOptions DetachVolumeOptions CreateSnapshotOptions)))
(defn snapshot?
"Returns true iff the argument is a org.jclouds.aws.ec2.domain.Snapshot."
[s]
(instance? Snapshot s))
(defn volume?
"Returns true iff the argument is a org.jclouds.aws.ec2.domain.Volume."
[v]
(instance? Volume v))
(defn #^org.jclouds.aws.ec2.services.ElasticBlockStoreClient (defn #^org.jclouds.aws.ec2.services.ElasticBlockStoreClient
ebs-service ebs-service
"Returns the synchronous ElasticBlockStoreClient associated with "Returns the synchronous ElasticBlockStoreClient associated with
@ -40,16 +50,17 @@
keyword or already a Region instance. An optional second argument keyword or already a Region instance. 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.
Returns nil otherwise." Returns nil otherwise."
[v & [default-region]] ([v] (get-region v nil))
(cond ([v default-region]
(keyword? v) (Region/fromValue (name v)) (cond
(instance? Region v) v (keyword? v) (Region/fromValue (name v))
(instance? NodeMetadata v) (let [zone (.getLocationId v)] (instance? Region v) v
; no easier way to go from zone -> region? (instance? NodeMetadata v) (let [zone (.getLocationId v)]
(Region/fromValue (if (> (.indexOf zone "-") -1) ; no easier way to go from zone -> region?
(subs zone 0 (-> zone count dec)) (Region/fromValue (if (> (.indexOf zone "-") -1)
zone))) (subs zone 0 (-> zone count dec))
:else default-region)) zone)))
:else default-region)))
(defn get-volume-id (defn get-volume-id
"Returns a string volume ID taken from the given string, keyword, or Volume argument." "Returns a string volume ID taken from the given string, keyword, or Volume argument."
@ -70,7 +81,7 @@
[& [region & volume-ids]] [& [region & volume-ids]]
(set (set
(.describeVolumesInRegion (ebs-service) (.describeVolumesInRegion (ebs-service)
(get-region region Region/DEFAULT) (get-region region)
(into-array String (map get-volume-id (into-array String (map get-volume-id
(if (get-region region) (if (get-region region)
volume-ids volume-ids
@ -124,7 +135,7 @@
options (snapshot-options (dissoc options :region))] options (snapshot-options (dissoc options :region))]
(set (set
(.describeSnapshotsInRegion (ebs-service) (.describeSnapshotsInRegion (ebs-service)
(get-region region Region/DEFAULT) (get-region region)
(into-array DescribeSnapshotsOptions [options]))))) (into-array DescribeSnapshotsOptions [options])))))
(defn create-snapshot (defn create-snapshot