 (timbre/refer-timbre)
 
 
+(defonce all-normal-instances (atom #{}))
+(defonce all-requests (atom #{}))
+
+
 (def cred (read-string (slurp "AWS.clj")))
 (apply defcredential (map cred [:access-key :secret-key :endpoint]))
 

about the request.  If an instance-id is available, the instance-info-map data
will be merged in."
  [ids]
  (let [descs  (describe-spot-instance-requests :spot-instance-request-ids ids)
        sirs   (:spot-instance-requests descs)
        sirs   (map (fn [rm] (m-section rm [[:request-id :spot-instance-request-id] :state :instance-id])) sirs)
        is     (filter string? (map :instance-id sirs))
        ims    (instance-info-map is)
        sirs   (map #(merge % (ims (:instance-id %))) sirs)]
    (mseq->m sirs :request-id)))


(defn request-instances [rs]
  (let [d (describe-spot-instance-requests :spot-instance-request-ids rs)]
    (map :instance-id (:spot-instance-requests d))))

(defn request-spots [req & opts]
  (let [req    (apply ph-assoc req paths opts)
        args   (apply concat (seq req))
        _      (debug "Spot request" (pr-str args))
        rs     (apply request-spot-instances args)]
    (map :spot-instance-request-id  (:spot-instance-requests rs))))

(defn terminate [is]
  (let [t (terminate-instances :instance-ids is)]
    (debug t)
    t))

(defn stop [is]
  (let [t (stop-instances :instance-ids is)]
    (debug t)
    t))

(defn start [is]
  (let [t (start-instances :instance-ids is)]
    (debug t)
    t))


(defn cancel-requests
  "Cancel the specified requests; if instance-id information is available, also stops the instances."
  [rs]
  (let [ds (:spot-instance-requests (describe-spot-instance-requests :spot-instance-request-ids rs))
        is (filter (complement nil?) (map :instance-id ds))
        cr (:cancelled-spot-instance-requests (cancel-spot-instance-requests :spot-instance-request-ids rs))
        ci (and (seq is) (terminate is))]
    [cr ci]))


(def ids->chs (atom {}))

(defn- notify-chan
  "Return a channel that will receive status information extracted from send-up messages

       (every? string? vs)
       (every? pos? (map count vs))))

(defn- really-up? [rs->info rs]
  (let [info (get rs->info rs)]
    (and
