summaryrefslogtreecommitdiff
path: root/lisp/service/asg-recycle-service.lisp
blob: 821abb503565879fe1b388841da837c6b47b27a0 (plain)
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
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(declaim (optimize (speed 0) (safety 3) (debug 3)))

(in-package :snow)

(defclass asg-recycle-service (rest-service)
  ()
  (:documentation ""))

(defun asg-recycle-json ()
  (with-noauth (instance asg-recycle-service)
    t))

(defclass asg-recycle/view-service (asg-recycle-service)
  ((form :initarg :form
         :initform nil
         :accessor form)
   (location-p :initform nil))
  (:documentation ""))

(defun asg-recycle-view-json ()
  (with-noauth (instance asg-recycle/view-service)
    (setf (form instance)
          (make-form "asg-recycle-form"
                     nil
                     t
                     `((:name "profile" :label "Profile" :field-type "text" :required "required" :value ,(or (session-value :profile) ""))
                       (:name "region" :label "Region" :field-type "text" :required "required" :value ,(or (session-value :region) (region *webapp*)))
                       (:name "filter" :label "Filter" :field-type "text" :required "required" :value ,(or (session-value :asg-recycle-filter) ""))
                       (:label "Find Matching ASGs" :field-type "button" :onclick "on_asg_recycle_results_clicked()"))))))

(defclass asg-recycle/results-service (asg-recycle/view-service)
  ((results :initarg :results
            :initform nil
            :accessor results)
   (location-p :initform nil))
  (:documentation ""))

(defun asg-recycle-results-json (profile region filter)
  (with-noauth (instance asg-recycle/results-service)
    (let* ((aws (make-instance 'aws :profile profile :region region))
           (asgs (get-asgs aws filter)))
      (setf (results instance) (mapcar (lambda (asg)
                                         (sanitize-json asg))
                                       asgs))
      (setf (session-value :profile) profile)
      (setf (session-value :region) region)
      (setf (session-value :asg-recycle-filter) filter)
      (setf (session-value :asg-recycle-asgs) asgs)
      (setf (form instance)
            (make-form "asg-recycle-submit-form"
                       nil
                       t
                       `((:label "Recycle All Hosts in ASGs" :field-type "button" :onclick "on_asg_recycle_results_submit_clicked('all')")
                         (:label "Recycle One Host in ASGs" :field-type "button" :onclick "on_asg_recycle_results_submit_clicked('one')")))))))

(defclass asg-recycle/results-submit-service (asg-recycle-service)
  ((location-p :initform nil))
  (:documentation ""))

(defun asg-recycle-results-submit-json (howmany)
  (with-noauth (instance asg-recycle/results-submit-service)
    (loop for asg in (session-value :asg-recycle-asgs)
          do (setf (howmany asg) howmany)
             (recycle-asg asg))))