1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 13:10:33 +02:00

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>
This commit is contained in:
Sergey Trofimov
2025-04-18 17:08:08 +02:00
committed by Ludovic Courtès
parent 5f1ee7ba73
commit 7a4193ec4a
4 changed files with 100 additions and 6 deletions

View File

@@ -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)