-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompute-api.lisp
More file actions
139 lines (123 loc) · 6.49 KB
/
compute-api.lisp
File metadata and controls
139 lines (123 loc) · 6.49 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
;;;; compute-api.lisp
(in-package #:trivial-openstack)
;;; Bindings for OpenStack Nova Compute API are defined here.
(def-openstack-api list-flavors ()
(response :get ((get-public-url "nova") "/flavors"))
"Lists all of the currently available flavors."
(mapcar #'(lambda (jso)
(cons (st-json:getjso "name" jso)
(st-json:getjso "id" jso)))
(st-json:getjso "flavors" (st-json:read-json response))))
(def-openstack-api list-flavor-details (flavor-id)
(response :get ((get-public-url "nova") "/flavors/" flavor-id))
"List a flavor details."
(let ((jso (st-json:read-json response)))
(pairlis (list "name" "vcpus" "ram" "swap" "disk")
(list (st-json:getjso* "flavor.name" jso)
(st-json:getjso* "flavor.vcpus" jso)
(st-json:getjso* "flavor.ram" jso)
(st-json:getjso* "flavor.swap" jso)
(st-json:getjso* "flavor.disk" jso)))))
(def-openstack-api list-servers ()
(response :get ((get-public-url "nova") "/servers"))
"Lists all of the currently active servers."
(mapcar #'(lambda (jso)
(cons (st-json:getjso "name" jso)
(st-json:getjso "id" jso)))
(st-json:getjso "servers" (st-json:read-json response))))
(def-openstack-api list-servers-details ()
(response :get ((get-public-url "nova") "/servers/detail"))
"Lists all of the currently active servers in details."
(mapcar #'(lambda (jso)
(cons (st-json:getjso "name" jso)
(pairlis (list "id" "status" "addresses")
(list
(st-json:getjso "id" jso)
(st-json:getjso "status" jso)
(mapcar #'(lambda (jso)
(cons (st-json:getjso "OS-EXT-IPS:type" jso)
(st-json:getjso "addr" jso)))
(st-json:getjso* "addresses.private" jso))))))
(st-json:getjso "servers" (st-json:read-json response))))
(def-openstack-api create-server (server-name image-id flavor-id)
(response :post ((get-public-url "nova") "/servers")
(st-json:write-json-to-string
(plist-hash-table
(list "server"
(plist-hash-table
(list "name" server-name
"imageRef" image-id
"flavorRef" flavor-id))))))
"Creates a new server."
(st-json:getjso* "server.id" (st-json:read-json response)))
(def-openstack-api delete-server (server-id)
(response :delete ((get-public-url "nova") "/servers/" server-id))
"Deletes a server."
response)
(def-openstack-api list-floating-ips ()
(response :get ((get-public-url "nova") "/os-floating-ips"))
"Lists all of the currently allocated floating IPs."
(mapcar #'(lambda (jso)
(cons (st-json:getjso "ip" jso)
(pairlis (list "fixed-ip" "pool")
(list (st-json:getjso "fixed_ip" jso)
(st-json:getjso "pool" jso)))))
(st-json:getjso "floating_ips" (st-json:read-json response))))
(def-openstack-api create-floating-ip (&key (pool "public"))
(response :post ((get-public-url "nova") "/os-floating-ips")
(st-json:write-json-to-string
(plist-hash-table
(list "pool" pool))))
"Creates/allocates a new floating IP."
(st-json:getjso* "floating_ip.ip" (st-json:read-json response)))
(def-openstack-api associate-floating-ip (server-id floating-ip)
(response :post ((get-public-url "nova") "/servers/" server-id "/action")
(st-json:write-json-to-string
(plist-hash-table
(list "addFloatingIp"
(plist-hash-table
(list "address" floating-ip))))))
"Associates a floating IP with an active server."
response)
(def-openstack-api list-default-security-group-rules ()
(response :get ((get-public-url "nova") "/os-security-group-default-rules"))
"Lists all the currently active security rules in the default security group."
(st-json:read-json response))
(def-openstack-api create-default-security-group-rule (rule)
(response :post ((get-public-url "nova") "/os-security-group-default-rules")
rule)
"Creates a new security rule in the default security group."
response)
(defun add-security-rule-accept-all-icmp ()
"Adds a security rule that accepts all incoming ICMP connection to
the default security group."
(create-default-security-group-rule (st-json:write-json-to-string
(plist-hash-table
(list "security_group_default_rule"
(plist-hash-table
(list "ip_protocol" "ICMP"
"from_port" "-1"
"to_port" "-1"
"cidr" "0.0.0.0/0")))))))
(defun add-security-rule-accept-all-tcp ()
"Adds a security rule that accepts all incoming TCP connection to
the default security group."
(create-default-security-group-rule (st-json:write-json-to-string
(plist-hash-table
(list "security_group_default_rule"
(plist-hash-table
(list "ip_protocol" "TCP"
"from_port" "1"
"to_port" "65535"
"cidr" "0.0.0.0/0")))))))
(defun add-security-rule-accept-all-udp ()
"Adds a security rule that accepts all incoming UDP connection to
the default security group."
(create-default-security-group-rule (st-json:write-json-to-string
(plist-hash-table
(list "security_group_default_rule"
(plist-hash-table
(list "ip_protocol" "UDP"
"from_port" "1"
"to_port" "65535"
"cidr" "0.0.0.0/0")))))))