Add service resize command to all 38 language implementations
Adds --resize ID --vcpu N flag to resize running services live.
PATCH /services/{id} with {"vcpu": 1-8} applies CPU/memory limits
without restart. Memory formula: 2GB per vCPU.
This commit is contained in:
parent
87397949d1
commit
c219d6e550
38 changed files with 1214 additions and 45 deletions
32
un.lisp
32
un.lisp
|
|
@ -186,6 +186,19 @@
|
|||
response))
|
||||
(delete-file tmp-file))))
|
||||
|
||||
(defun curl-patch (api-key endpoint json-data)
|
||||
(let ((tmp-file (write-temp-file json-data)))
|
||||
(unwind-protect
|
||||
(destructuring-bind (public-key secret-key) (get-api-keys)
|
||||
(let* ((auth-headers (build-auth-headers public-key secret-key "PATCH" endpoint json-data))
|
||||
(base-args (list "curl" "-s" "-X" "PATCH"
|
||||
(format nil "https://api.unsandbox.com~a" endpoint)
|
||||
"-H" "Content-Type: application/json"))
|
||||
(response (run-curl (append base-args auth-headers (list "-d" (format nil "@~a" tmp-file))))))
|
||||
(check-clock-drift response)
|
||||
response))
|
||||
(delete-file tmp-file))))
|
||||
|
||||
(defun curl-put-text (api-key endpoint content)
|
||||
"PUT request with text/plain content type (for vault)"
|
||||
(let ((tmp-file (write-temp-file content)))
|
||||
|
|
@ -316,6 +329,16 @@
|
|||
((string= action "destroy")
|
||||
(curl-delete api-key (format nil "/services/~a" id))
|
||||
(format t "~aService destroyed: ~a~a~%" *green* id *reset*))
|
||||
((string= action "resize")
|
||||
(if (or (null service-type) (string= service-type ""))
|
||||
(progn
|
||||
(format *error-output* "~aError: --resize requires --vcpu N (1-8)~a~%" *red* *reset*)
|
||||
(uiop:quit 1))
|
||||
(let* ((vcpu (parse-integer service-type))
|
||||
(ram (* vcpu 2))
|
||||
(json (format nil "{\"vcpu\":~a}" vcpu)))
|
||||
(curl-patch api-key (format nil "/services/~a" id) json)
|
||||
(format t "~aService resized to ~a vCPU, ~a GB RAM~a~%" *green* vcpu ram *reset*))))
|
||||
((string= action "execute")
|
||||
(when (and id bootstrap)
|
||||
(let* ((json (format nil "{\"command\":\"~a\"}" (escape-json bootstrap)))
|
||||
|
|
@ -522,6 +545,15 @@
|
|||
(service-cmd "wake" (third args) nil nil nil nil nil nil nil nil))
|
||||
((and (> (length args) 2) (string= (second args) "--destroy"))
|
||||
(service-cmd "destroy" (third args) nil nil nil nil nil nil nil nil))
|
||||
((and (> (length args) 3) (string= (second args) "--resize"))
|
||||
;; --resize ID --vcpu N: id is third, vcpu is fourth (after -v flag)
|
||||
(let ((id (third args))
|
||||
(vcpu (if (and (> (length args) 4)
|
||||
(or (string= (fourth args) "-v")
|
||||
(string= (fourth args) "--vcpu")))
|
||||
(fifth args)
|
||||
nil)))
|
||||
(service-cmd "resize" id nil nil nil nil vcpu nil nil nil)))
|
||||
((and (> (length args) 3) (string= (second args) "--execute"))
|
||||
(service-cmd "execute" (third args) nil nil (fourth args) nil nil nil nil nil))
|
||||
((and (> (length args) 3) (string= (second args) "--dump-bootstrap"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue