  `(if-let [~'instance-id (instance-id* ~'spec)]
     (do ~@body) 
     (throw+ {:type ::aws:missing-id :message "Instance id not found"}))) 
-
-(defn image-id [machine]
-  (hypervisor :aws :ostemplates (machine :os) :ami))
-
-(defn handle-volumes 
-   "attached and waits for ebs volumes" 
-   [{:keys [aws machine] :as spec} endpoint instance-id]
-  (when (= (image-desc endpoint (image-id machine) :root-device-type) "ebs")
-    (wait-for-attach endpoint instance-id [10 :minute]))
-  (let [zone (instance-desc endpoint instance-id :placement :availability-zone)]
-    (doseq [{:keys [device size]} (aws :volumes)]
-      (let [{:keys [volumeId]} (with-ctx ebs/create-volume size zone)]
-        (wait-for {:timeout [10 :minute]} #(= "available" (with-ctx ebs/state volumeId))
-           {:type ::aws:ebs-volume-availability :message "Failed to wait for ebs volume to become available"})
-        (with-ctx ebs/attach-volume volumeId instance-id device)
-        (wait-for {:timeout [10 :minute]} #(= "attached" (with-ctx ebs/attachment-status volumeId))
-           {:type ::aws:ebs-volume-attach-failed :message "Failed to wait for ebs volume device attach"})))))
-
-(defn delete-volumes 
-   "Clear instance volumes" 
-   [endpoint instance-id]
-   (doseq [{:keys [ebs]} (-> (instance-desc endpoint instance-id) :block-device-mappings rest)]
-     (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))))
 
 (defn create-instance 
    "creates instance from aws" 

  (delete [this]
    (with-instance-id
      (debug "deleting" instance-id)
      (delete-volumes endpoint instance-id) 
      (with-ctx ec2/terminate-instances instance-id) 
      (wait-for-status this "terminated" [5 :minute])
      ; for reload support

  (wait-for {:timeout timeout} #(= req-stat (.status instance))
    {:type ::aws:status-failed :message "Timed out on waiting for status" :status req-stat :timeout timeout}))

(defn wait-for-ssh [endpoint instance-id user timeout]
    (wait-for {:timeout timeout}
      #(ssh-up? {:host (pub-dns endpoint instance-id) :port 22 :user user})
      {:type ::aws:ssh-failed :message "Timed out while waiting for ssh" :timeout timeout}))

(defn instance-id*
  "grabbing instance id of spec"
