v1_0.rb
1.08 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
class Lxd::API::V1_0
include Lxd::API
def config
get '/1.0'
end
def config= config={}
put '/1.0', config: config
end
def certificates
get('/1.0/certificates').map { |uri|
{ :uri => uri }.merge get(uri)
}
end
def add_certificate data={}
# TODO validate hash
post '/1.0/certificates', data
end
def delete_certificate fingerprint
delete '/1.0/certificates/' + fingerprint
end
def handle_response resp
"""
100 Operation created
101 Started
102 Stopped
103 Running
104 Cancelling
105 Pending
106 Starting
107 Stopping
108 Aborting
109 Freezing
110 Frozen
111 Thawed
200 Success
400 Failure
401 Cancelled
100 to 199: resource state (started, stopped, ready, ...)
200 to 399: positive action result
400 to 599: negative action result
600 to 999: future use
"""
raise "api error: (" + resp['error_code'].to_s + ") " + resp['error'] if resp['error_code'] and resp['error_code'] != 403
resp['metadata']
end
end
# vim: set et ts=2 sw=2: