 (import-logging)
 
 (defn image-desc [endpoint ami & ks]
-  (-> (ec2/describe-images (assoc (creds) :endpoint endpoint) (ec2/image-id-filter ami))
-      first (apply ks)))
+  (-> 
+    (ec2/describe-images (assoc (creds) :endpoint endpoint) 
+       :image-ids [ami]) :images first (apply ks)
+      ))
 
 (defn wait-for-attach [endpoint instance-id timeout]
   (wait-for {:timeout timeout} 
     #(= "attached" (instance-desc endpoint instance-id :block-device-mappings 0 :ebs :status)) 
     {:type ::aws:ebs-attach-failed :message "Failed to wait for ebs root device attach"}))
+
+(defn volume-desc [endpoint volume-id & ks]
+  (-> 
+   (with-ctx ec2/describe-volumes {:volume-ids [volume-id]}))
+    :volumes first (get-in ks))
 
 (defn handle-volumes 
    "attached and waits for ebs volumes" 

  (doseq [{:keys [ebs device-name]} (-> (instance-desc endpoint instance-id) :block-device-mappings rest)]
    (when (clear? device-name system-id)
      (trace "deleting volume" ebs) 
      (with-ctx ebs/detach-volume (ebs :volume-id)) 
      (wait-for {:timeout [10 :minute]} 
        #(= "available" (with-ctx ebs/state  (ebs :volume-id)))
        {:type ::aws:ebs-volume-availability 
         :message "Failed to wait for ebs volume to become available"}) 
      (with-ctx ebs/delete-volume (ebs :volume-id)))))

(comment
  (clojure.pprint/pprint 
    (celestial.model/set-env :dev 
                             (-> (instance-desc "ec2.eu-west-1.amazonaws.com" "i-a5a88de9") :block-device-mappings rest)
                             ))
  )

  (:require 
    [celestial.common :refer (import-logging )] 
    [celestial.provider :refer (wait-for)] 
    [amazonica.aws.ec2 :as ec2]
    [celestial.persistency.systems :as s]
    [aws.common :refer (with-ctx instance-desc creds image-id)]
    )) 
