Starting a Scheme SDK for Equinix Metal

This commit is contained in:
2024-06-07 22:09:24 -04:00
commit 155e15e9f5
5 changed files with 247 additions and 0 deletions

34
metalapi/vlan.scm Normal file
View File

@@ -0,0 +1,34 @@
(define-module (metalapi vlan)
#:use-module (metalapi requests)
#:use-module (metalapi project)
#:export (build-vlan
vlan->project
vlan->metro-code
vlan->vxlan
vlan-request-body
list-all-vlans))
(define (build-vlan vlan-alist)
(extract-attrs vlan-alist "id" "description" "vxlan" "metro_code"))
(define (vlan->project vlan)
(project->id (assoc-ref vlan "project")))
(define (vlan->metro-code vlan)
(assoc-ref vlan "metro_code"))
(define (vlan->description vlan)
(assoc-ref vlan "description"))
(define (vlan-request-body vlan)
(scm->json-string
`(("metro" . ,(assoc-ref vlan "metro_code"))
("description" . ,(vlan->description vlan)))))
(define (vlan->vxlan vlan)
(assoc-ref vlan "vxlan"))
(define (list-all-vlans project)
(handle-pagination (format #f "/projects/~a/virtual-networks" (project->id project)) "virtual_networks" build-vlan))