-
Notifications
You must be signed in to change notification settings - Fork 1
/
eip.clj
46 lines (38 loc) · 1.39 KB
/
eip.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(ns exoscale.compute.api.eip
"Higher order functions to manipulate keypairs.
In addition to standard facilities, this also
bundles an opt-in atom-backed store for private keys
created here."
(:refer-clojure :exclude [update list])
(:require [exoscale.compute.api.client :as client]
[qbits.auspex :as auspex]
[clojure.string :as str]))
(defn sanitize
[eip]
(with-meta {:id (client/parse-uuid (:id eip))
:zone (:zonename eip)
:ipv4 {:address (:ipaddress eip)}
:tags (:tags eip)
:bound? (= (:state eip) "Allocated")
:state (-> (:state eip) str/lower-case keyword)}
{:exoscale.compute/type :exoscale.compute/eip
:exoscale.compute/zone (client/parse-uuid (:zoneid eip))
:exoscale.compute/source eip}))
(comment
(defn by-name
[config eipname]
(auspex/chain (client/api-call config :list-zones {:name (name zname)})
(fn [resp]
(when-not (= 1 (count resp))
(throw (IllegalArgumentException.
"cannot resolve zone")))
(sanitize (first resp))))))
(defn list
"List virtual machines"
[config]
(auspex/chain
(client/api-call config :list-public-ip-addresses {:iselastic true})
#(mapv sanitize %)))
(comment
@(list config)
)