summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Trofimov <sarg@sarg.org.ru>2025-04-18 17:08:08 +0200
committerLudovic Courtès <ludo@gnu.org>2025-04-21 23:55:50 +0200
commit7a4193ec4a09fecc68dc726c1e0bbb5ad03d404a (patch)
treedbb9740caaf85b85bc39c6b333b01c3609a4507e /tests
parent5f1ee7ba730b5e2c0bb4b33878d0462dd22d2eb6 (diff)
machine: hetzner: Allow attaching existing public IPs.
* gnu/machine/hetzner.scm (hetzner-configuration): Add ipv4 and ipv6 fields. Export accessors. * gnu/machine/hetzner/http.scm (hetnzer-api-primary-ips): New function. (<hetzner-primary-ip>): New json mapping. (hetzner-api-server-create): Pass IP addresses in request. * doc/guix.texi (Invoking guix deploy): Document it. Change-Id: I44509cc98e041762dc483e876566e79bde85b26a Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/machine/hetzner/http.scm38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/machine/hetzner/http.scm b/tests/machine/hetzner/http.scm
index 618d9a4c94..6c6d848a57 100644
--- a/tests/machine/hetzner/http.scm
+++ b/tests/machine/hetzner/http.scm
@@ -239,6 +239,30 @@
("status" . "running")
("volumes" . #())))
+(define primary-ip
+ (make-hetzner-primary-ip
+ #(55 2 19 28 9 123 6 300 -1 0 #f)
+ 42
+ "131.232.99.1"
+ '()
+ "static-ip"
+ "ipv4"))
+
+(define primary-ip-alist
+ `(("created" . "2023-10-28T19:02:55+00:00")
+ ("id" . 42)
+ ("labels")
+ ("name" . "static-ip")
+ ("blocked" . #f)
+ ("ip" . "131.232.99.1")
+ ("datacenter")
+ ("dns_ptr")
+ ("protection" . (("delete" . #f)))
+ ("type" . "ipv4")
+ ("auto_delete" . #t)
+ ("assignee_type" . "server")
+ ("assignee_id" . 17)))
+
(define ssh-key-root
(make-hetzner-ssh-key
#(55 2 19 28 9 123 6 300 -1 0 #f)
@@ -512,6 +536,20 @@
("ssh_keys" . #(,ssh-key-root-alist)))))))
(hetzner-api-ssh-keys (hetzner-api))))
+(test-equal "hetzner-api-primary-ips-unit"
+ (list primary-ip)
+ (mock ((gnu machine hetzner http) hetzner-api-request-send
+ (lambda* (request #:key expected)
+ (assert (equal? 'GET (hetzner-api-request-method request)))
+ (assert (equal? "https://api.hetzner.cloud/v1/primary_ips"
+ (hetzner-api-request-url request)))
+ (assert (unspecified? (hetzner-api-request-body request)))
+ (assert (equal? '(("page" . 1)) (hetzner-api-request-params request)))
+ (hetzner-api-response
+ (body `(("meta" . ,meta-page-alist)
+ ("primary_ips" . #(,primary-ip-alist)))))))
+ (hetzner-api-primary-ips (hetzner-api))))
+
;; Integration tests
(test-skip %when-no-token)