Cleaning up API for ebs2 and elastic-ip2 after review. Minor changes to doc-strings, code formatting and order of args in release fn.

This commit is contained in:
Mattias Holmqvist 2011-06-03 09:29:04 +02:00
parent c330e100f0
commit 69aac6b455
2 changed files with 24 additions and 26 deletions

View File

@ -37,7 +37,7 @@
[v] [v]
(instance? Volume v)) (instance? Volume v))
(defn #^org.jclouds.ec2.services.ElasticBlockStoreClient (defn ^org.jclouds.ec2.services.ElasticBlockStoreClient
ebs-service ebs-service
"" ""
[compute] [compute]
@ -68,7 +68,7 @@
"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."
[v] [v]
(cond (cond
(instance? Volume v) (.getId #^Volume v) (instance? Volume v) (.getId ^Volume v)
(keyword? v) (name v) (keyword? v) (name v)
(string? v) v (string? v) v
:else (throw (IllegalArgumentException. :else (throw (IllegalArgumentException.
@ -77,7 +77,6 @@
(defn volumes (defn volumes
"Returns a set of org.jclouds.ec2.domain.Volume instances corresponding to the "Returns a set of org.jclouds.ec2.domain.Volume instances corresponding to the
volumes in the specified region (defaulting to your account's default region)." volumes in the specified region (defaulting to your account's default region)."
[compute & [region & volume-ids]] [compute & [region & volume-ids]]
(set (set
(.describeVolumesInRegion (ebs-service compute) (.describeVolumesInRegion (ebs-service compute)
@ -86,6 +85,7 @@
(if (get-region region) (if (get-region region)
volume-ids volume-ids
(when region (cons region volume-ids)))))))) (when region (cons region volume-ids))))))))
(defn- as-string (defn- as-string
[v] [v]
(cond (cond
@ -95,6 +95,7 @@
(defn- get-string (defn- get-string
[map key] [map key]
(as-string (get map key))) (as-string (get map key)))
(defn- as-int (defn- as-int
[v] [v]
(cond (cond
@ -138,9 +139,8 @@
"Creates a snapshot of a volume in the specified region with an optional description. "Creates a snapshot of a volume in the specified region with an optional description.
If provided, the description must be < 255 characters in length. Returns the If provided, the description must be < 255 characters in length. Returns the
org.jclouds.aws.ec2.domain.Snapshot object representing the created snapshot." org.jclouds.aws.ec2.domain.Snapshot object representing the created snapshot."
([compute ^Volume volume] (create-snapshot compute volume nil))
([compute #^Volume volume] (create-snapshot compute volume nil)) ([compute ^Volume volume description] (create-snapshot compute (.getRegion volume) (.getId volume) description))
([compute #^Volume volume description] (create-snapshot compute (.getRegion volume) (.getId volume) description))
([compute region volume-id description] ([compute region volume-id description]
(.createSnapshotInRegion (ebs-service compute) (.createSnapshotInRegion (ebs-service compute)
(get-region region) (get-region region)
@ -150,7 +150,7 @@
(defn delete-snapshot (defn delete-snapshot
"Deletes a snapshot in the specified region." "Deletes a snapshot in the specified region."
([compute #^Snapshot snapshot] (delete-snapshot compute (.getRegion snapshot) (.getId snapshot))) ([compute ^Snapshot snapshot] (delete-snapshot compute (.getRegion snapshot) (.getId snapshot)))
([compute region snapshot-id] ([compute region snapshot-id]
(.deleteSnapshotInRegion (ebs-service compute) (.deleteSnapshotInRegion (ebs-service compute)
(get-region region) (get-region region)
@ -160,7 +160,7 @@
[v] [v]
(cond (cond
(instance? AvailabilityZoneInfo v) (.getZone v) (instance? AvailabilityZoneInfo v) (.getZone v)
(instance? NodeMetadata v) (location #^NodeMetadata v) (instance? NodeMetadata v) (location ^NodeMetadata v)
(string? v) v (string? v) v
(keyword? v) (name v) (keyword? v) (name v)
:else (throw (IllegalArgumentException. :else (throw (IllegalArgumentException.
@ -168,7 +168,7 @@
(defn attach-volume (defn attach-volume
"Attaches a volume to an instance, returning the resulting org.jclouds.aws.ec2.domain.Attachment." "Attaches a volume to an instance, returning the resulting org.jclouds.aws.ec2.domain.Attachment."
([compute #^NodeMetadata node volume device] ([compute ^NodeMetadata node volume device]
(attach-volume compute node (.getProviderId node) (get-volume-id volume) device)) (attach-volume compute node (.getProviderId node) (get-volume-id volume) device))
([compute region instance-id volume-id device] ([compute region instance-id volume-id device]
(apply #(.attachVolumeInRegion (ebs-service compute) (apply #(.attachVolumeInRegion (ebs-service compute)
@ -223,7 +223,6 @@
Note also that if :device and :node are specified, and the attach operation fails, Note also that if :device and :node are specified, and the attach operation fails,
you will have \"leaked\" the newly-created volume you will have \"leaked\" the newly-created volume
(volume creation and attachment cannot be done atomically)." (volume creation and attachment cannot be done atomically)."
[compute & options] [compute & options]
(when (-> options count odd?) (when (-> options count odd?)
(throw (IllegalArgumentException. "Must provide key-value pairs, e.g. :zone :us-east-1d :size 200"))) (throw (IllegalArgumentException. "Must provide key-value pairs, e.g. :zone :us-east-1d :size 200")))
@ -231,7 +230,7 @@
snapshot (get-string options :snapshot) snapshot (get-string options :snapshot)
snapshot (if (snapshot? snapshot) (.getId snapshot) snapshot) snapshot (if (snapshot? snapshot) (.getId snapshot) snapshot)
size (-?> (get-string options :size) as-int) size (-?> (get-string options :size) as-int)
#^NodeMetadata node (:node options) ^NodeMetadata node (:node options)
zone (or node (get-string options :zone)) zone (or node (get-string options :zone))
zone (if zone zone (if zone
(get-zone zone) (get-zone zone)
@ -249,7 +248,7 @@
(defn delete-volume (defn delete-volume
"Deletes a volume in the specified region." "Deletes a volume in the specified region."
([compute #^Volume volume] ([compute ^Volume volume]
(delete-volume (.getRegion volume) (.getId volume))) (delete-volume (.getRegion volume) (.getId volume)))
([compute region volume-id] ([compute region volume-id]
(.deleteVolumeInRegion (ebs-service compute) (.deleteVolumeInRegion (ebs-service compute)
@ -262,29 +261,29 @@
(.getStatus k)) (.getStatus k))
(defn status-available? (defn status-available?
[#^Volume v] [^Volume v]
(= Volume$Status/AVAILABLE (status v))) (= Volume$Status/AVAILABLE (status v)))
(defn status-creating? (defn status-creating?
[#^Volume v] [^Volume v]
(= Volume$Status/CREATING (status v))) (= Volume$Status/CREATING (status v)))
(defn status-deleting? (defn status-deleting?
[#^Volume v] [^Volume v]
(= Volume$Status/DELETING (status v))) (= Volume$Status/DELETING (status v)))
(defn status-in-use? (defn status-in-use?
[#^Volume v] [^Volume v]
(= Volume$Status/IN_USE (status v))) (= Volume$Status/IN_USE (status v)))
(defn status-completed? (defn status-completed?
[#^Snapshot s] [^Snapshot s]
(= Snapshot$Status/COMPLETED (status s))) (= Snapshot$Status/COMPLETED (status s)))
(defn status-error? (defn status-error?
[#^Snapshot s] [^Snapshot s]
(= Snapshot$Status/ERROR (status s))) (= Snapshot$Status/ERROR (status s)))
(defn status-pending? (defn status-pending?
[#^Snapshot s] [^Snapshot s]
(= Snapshot$Status/PENDING (status s))) (= Snapshot$Status/PENDING (status s)))

View File

@ -27,10 +27,9 @@
(:import org.jclouds.compute.domain.NodeMetadata (:import org.jclouds.compute.domain.NodeMetadata
(org.jclouds.ec2.domain PublicIpInstanceIdPair))) (org.jclouds.ec2.domain PublicIpInstanceIdPair)))
(defn #^org.jclouds.ec2.services.ElasticIPAddressClient (defn ^org.jclouds.ec2.services.ElasticIPAddressClient
eip-service eip-service
"Returns the synchronous ElasticIPAddressClient associated with "Returns an ElasticIPAddressClient for the given ComputeService"
the specified compute service, or compute/*compute* as bound by with-compute-service."
[compute] [compute]
(-> compute (-> compute
.getContext .getProviderSpecificContext .getApi .getElasticIPAddressServices)) .getContext .getProviderSpecificContext .getApi .getElasticIPAddressServices))
@ -45,7 +44,7 @@
(defn associate (defn associate
"Associates an elastic IP address with a node." "Associates an elastic IP address with a node."
([compute #^NodeMetadata node public-ip] ([compute ^NodeMetadata node public-ip]
(associate node public-ip (.getProviderId node))) (associate node public-ip (.getProviderId node)))
([compute region public-ip instance-id] ([compute region public-ip instance-id]
(.associateAddressInRegion (eip-service compute) (.associateAddressInRegion (eip-service compute)
@ -62,7 +61,7 @@
You may optionally specify which IP addresses you would like to query." You may optionally specify which IP addresses you would like to query."
([compute] (addresses compute nil)) ([compute] (addresses compute nil))
([compute region & public-ips] ([compute region & public-ips]
(into {} (for [#^PublicIpInstanceIdPair pair (.describeAddressesInRegion (eip-service compute) (into {} (for [^PublicIpInstanceIdPair pair (.describeAddressesInRegion (eip-service compute)
(ebs/get-region region) (ebs/get-region region)
(into-array String public-ips))] (into-array String public-ips))]
[(.getPublicIp pair) (merge {:region (.getRegion pair)} [(.getPublicIp pair) (merge {:region (.getRegion pair)}
@ -77,8 +76,8 @@
(defn release (defn release
"Disclaims an elastic IP address from your account." "Disclaims an elastic IP address from your account."
([compute public-ip] (release compute nil public-ip)) ([compute public-ip] (release compute public-ip nil))
([compute region public-ip] ([compute public-ip region]
(.releaseAddressInRegion (eip-service compute) (.releaseAddressInRegion (eip-service compute)
(ebs/get-region region) (ebs/get-region region)
public-ip))) public-ip)))