cljs / src / ird / vps.cljs
841 words
  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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
(ns ird.vps
  "EU cloud servers: tiers, SSH keys, instances, one-click apps, volumes,
  snapshots and activity. Hourly prepaid credit billing until destroy.
  Cross-account handover lives in ird.transfers. Every function returns a
  channel (see ird.async)."
  (:require [ird.async :refer [go-try <?]]
            [ird.gate :as gate]
            [ird.transport :as transport]))

(defn list-tiers
  "GET /vps/tiers — VPS tiers."
  [client]
  (transport/request client :get "/vps/tiers"))

(defn list-system-images
  "GET /vps/system-images — Bootable system images."
  [client]
  (transport/request client :get "/vps/system-images"))

(defn list-ssh-keys
  "GET /vps/ssh-keys — List SSH keys."
  [client]
  (transport/request client :get "/vps/ssh-keys"))

(defn add-ssh-key
  "POST /vps/ssh-keys — Add an SSH key.
  BODY is a plain map with :name and :public_key."
  [client body]
  (transport/request client :post "/vps/ssh-keys" {:body body}))

(defn delete-ssh-key
  "DELETE /vps/ssh-keys/{id} — Delete an SSH key."
  [client id]
  (transport/request client :delete ["vps" "ssh-keys" id]))

(defn availability
  "GET /vps/availability — Tier availability."
  [client]
  (transport/request client :get "/vps/availability"))

(defn list-instances
  "GET /vps/instances — List your servers."
  [client]
  (transport/request client :get "/vps/instances"))

(defn create-instance
  "POST /vps/instances — Create a server (202, hourly billing starts).
  BODY keys include :tier_id, :image_ref, :name, :ssh_key_ids, :zone,
  :subdomain, :volume_id, :queue_if_unavailable, :notify_on_outcome,
  :totp_code."
  [client body]
  (transport/request client :post "/vps/instances" {:body body}))

(defn app-catalog
  "GET /vps/apps — One-click app catalog."
  [client]
  (transport/request client :get "/vps/apps"))

(defn list-app-deployments
  "GET /vps/apps/deployments — List your app deployments."
  [client]
  (transport/request client :get "/vps/apps/deployments"))

(defn deploy-app
  "POST /vps/apps/deployments — Deploy an app (202, hourly billing starts).
  BODY keys include :app_id, :tier_id, :name, :ssh_key_ids, :zone,
  :subdomain, :queue_if_unavailable, :notify_on_outcome, :totp_code."
  [client body]
  (transport/request client :post "/vps/apps/deployments" {:body body}))

(defn get-app-deployment
  "GET /vps/apps/deployments/{id} — Get an app deployment."
  [client id]
  (transport/request client :get ["vps" "apps" "deployments" id]))

(defn reveal-app-password
  "POST /vps/apps/deployments/{id}/reveal-password — Reveal an app
  deployment's root password (once)."
  [client id]
  (transport/request client :post ["vps" "apps" "deployments" id "reveal-password"]))

(defn get-instance
  "GET /vps/instances/{id} — Get a server."
  [client id]
  (transport/request client :get ["vps" "instances" id]))

(defn destroy-instance
  "DELETE /vps/instances/{id} — Destroy a server (202; billing stops)."
  [client id]
  (transport/request client :delete ["vps" "instances" id]))

(defn get-metrics
  "GET /vps/instances/{id}/metrics — Server usage metrics.
  Optional QUERY keys include :type, :start, :end, :step."
  ([client id] (get-metrics client id nil))
  ([client id query]
   (transport/request client :get ["vps" "instances" id "metrics"] {:query query})))

(defn set-queue-notify
  "POST /vps/instances/{id}/queue-notify — Toggle the queued-create outcome
  email. BODY is a plain map with :enabled."
  [client id body]
  (transport/request client :post ["vps" "instances" id "queue-notify"] {:body body}))

(defn create-snapshot
  "POST /vps/instances/{id}/images — Snapshot a server (202).
  BODY is a plain map with optional :name."
  ([client id] (create-snapshot client id nil))
  ([client id body]
   (transport/request client :post ["vps" "instances" id "images"] (when body {:body body}))))

(defn restart
  "POST /vps/instances/{id}/restart — Restart a server (graceful, 202)."
  [client id]
  (transport/request client :post ["vps" "instances" id "restart"]))

(defn reset
  "POST /vps/instances/{id}/reset — Force reset a server (hard, 202)."
  [client id]
  (transport/request client :post ["vps" "instances" id "reset"]))

(defn shutdown
  "POST /vps/instances/{id}/shutdown — Shut down a server (graceful, 202)."
  [client id]
  (transport/request client :post ["vps" "instances" id "shutdown"]))

(defn power-off
  "POST /vps/instances/{id}/power-off — Force power off a server (hard, 202)."
  [client id]
  (transport/request client :post ["vps" "instances" id "power-off"]))

(defn power-on
  "POST /vps/instances/{id}/power-on — Power on a stopped server (202)."
  [client id]
  (transport/request client :post ["vps" "instances" id "power-on"]))

(defn set-rdns
  "PUT /vps/instances/{id}/rdns — Set a server's reverse DNS (PTR, 202).
  BODY is a plain map with :hostname and optional :ip."
  [client id body]
  (transport/request client :put ["vps" "instances" id "rdns"] {:body body}))

(defn list-instance-domains
  "GET /vps/instances/{id}/domains — List a server's connected domains."
  [client id]
  (transport/request client :get ["vps" "instances" id "domains"]))

(defn connect-domain
  "POST /vps/instances/{id}/domains — Connect a domain to a server (202).
  BODY requires :zone (the domain name) and :subdomain; optional keys are
  :set_rdns and :totp_code. Subject to the client's domain gate on :zone."
  [client id body]
  (gate/request client "POST /vps/instances/{id}/domains" {:domain (:zone body)}
                :post ["vps" "instances" id "domains"] {:body body}))

(defn- connection-target
  "Gate target for a domain connection: its zone, found in
  `list-instance-domains`. Called only when the client has a gate."
  [client id connection-id]
  (go-try
    {:domain (some #(when (= (str connection-id) (str (:id %))) (:zone_origin %))
                   (:connections (<? (list-instance-domains client id))))}))

(defn disconnect-domain
  "DELETE /vps/instances/{id}/domains/{connection-id} — Disconnect a domain
  from a server. Subject to the client's domain gate on the connection's
  zone (resolved via `list-instance-domains` when a gate is set)."
  [client id connection-id]
  (gate/request client "DELETE /vps/instances/{id}/domains/{connection-id}"
                #(connection-target client id connection-id)
                :delete ["vps" "instances" id "domains" connection-id]))

(defn list-volumes
  "GET /vps/volumes — List your volumes."
  [client]
  (transport/request client :get "/vps/volumes"))

(defn create-volume
  "POST /vps/volumes — Create a volume (202, hourly billing starts).
  BODY is a plain map with :name and :size_gb."
  [client body]
  (transport/request client :post "/vps/volumes" {:body body}))

(defn delete-volume
  "DELETE /vps/volumes/{id} — Delete a volume (202; billing stops)."
  [client id]
  (transport/request client :delete ["vps" "volumes" id]))

(defn list-images
  "GET /vps/images — List your snapshots."
  [client]
  (transport/request client :get "/vps/images"))

(defn delete-image
  "DELETE /vps/images/{id} — Delete a snapshot (202)."
  [client id]
  (transport/request client :delete ["vps" "images" id]))

(defn get-action
  "GET /vps/actions/{id} — Poll a VPS action."
  [client id]
  (transport/request client :get ["vps" "actions" id]))

(defn list-activity
  "GET /vps/activity — Infrastructure activity timeline.
  Optional QUERY keys include :instance_id."
  ([client] (list-activity client nil))
  ([client query]
   (transport/request client :get "/vps/activity" {:query query})))

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/cljs.git