clj / src / ird / vps.clj
978 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
(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."
  (:require
   [ird.gate :as gate]
   [ird.transport :as transport]))

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

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

(defn list-ssh-keys
  "GET /vps/ssh-keys — List SSH keys.
  Returns the parsed response map."
  [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.
  Returns the parsed response map."
  [client body]
  (transport/request client :post "/vps/ssh-keys" {:body body}))

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

(defn availability
  "GET /vps/availability — Tier availability.
  Returns the parsed response map."
  [client]
  (transport/request client :get "/vps/availability"))

(defn list-instances
  "GET /vps/instances — List your servers.
  Returns the parsed response map."
  [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.
  Returns the parsed response map."
  [client body]
  (transport/request client :post "/vps/instances" {:body body}))

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

(defn list-app-deployments
  "GET /vps/apps/deployments — List your app deployments.
  Returns the parsed response map."
  [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.
  Returns the parsed response map."
  [client body]
  (transport/request client :post "/vps/apps/deployments" {:body body}))

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

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

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

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

(defn get-metrics
  "GET /vps/instances/{id}/metrics — Server usage metrics.
  Optional QUERY keys include :type, :start, :end, :step.
  Returns the parsed response map."
  ([client id] (get-metrics client id nil))
  ([client id query]
   (transport/request client :get (str "/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.
  Returns the parsed response map."
  [client id body]
  (transport/request client :post (str "/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.
  Returns the parsed response map."
  ([client id] (create-snapshot client id nil))
  ([client id body]
   (transport/request client :post (str "/vps/instances/" id "/images")
                      (when body {:body body}))))

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

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

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

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

(defn power-on
  "POST /vps/instances/{id}/power-on — Power on a stopped server (202).
  Returns the parsed response map."
  [client id]
  (transport/request client :post (str "/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.
  Returns the parsed response map."
  [client id body]
  (transport/request client :put (str "/vps/instances/" id "/rdns")
                     {:body body}))

(defn list-instance-domains
  "GET /vps/instances/{id}/domains — List a server's connected domains.
  Returns the parsed response map."
  [client id]
  (transport/request client :get (str "/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.
  Returns the parsed response map."
  [client id body]
  (gate/check! client "POST /vps/instances/{id}/domains" {:domain (:zone body)})
  (transport/request client :post (str "/vps/instances/" id "/domains")
                     {:body body}))

(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).
  Returns the parsed response map."
  [client id connection-id]
  (when (:gate client)
    (let [zone (some #(when (= (str connection-id) (str (:id %)))
                        (:zone_origin %))
                     (:connections (list-instance-domains client id)))]
      (gate/check! client "DELETE /vps/instances/{id}/domains/{connection-id}"
                   {:domain zone})))
  (transport/request client :delete
                     (str "/vps/instances/" id "/domains/" connection-id)))

(defn list-volumes
  "GET /vps/volumes — List your volumes.
  Returns the parsed response map."
  [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.
  Returns the parsed response map."
  [client body]
  (transport/request client :post "/vps/volumes" {:body body}))

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

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

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

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

(defn list-activity
  "GET /vps/activity — Infrastructure activity timeline.
  Optional QUERY keys include :instance_id.
  Returns the parsed response map."
  ([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/clj.git