vmpooler 0.16.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vmpooler.rb +9 -14
- data/lib/vmpooler/api/dashboard.rb +18 -20
- data/lib/vmpooler/api/helpers.rb +15 -15
- data/lib/vmpooler/api/v1.rb +51 -52
- data/lib/vmpooler/metrics/dummy_statsd.rb +0 -3
- data/lib/vmpooler/metrics/graphite.rb +2 -0
- data/lib/vmpooler/metrics/promstats.rb +2 -0
- data/lib/vmpooler/metrics/promstats/collector_middleware.rb +1 -1
- data/lib/vmpooler/metrics/statsd.rb +5 -3
- data/lib/vmpooler/pool_manager.rb +48 -55
- data/lib/vmpooler/providers/dummy.rb +20 -38
- data/lib/vmpooler/providers/vsphere.rb +48 -38
- data/lib/vmpooler/version.rb +1 -1
- metadata +38 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 277212a5ca26187ed46a4e6d0ef0716511a3b63097deab1485908c95bb437c5e
|
4
|
+
data.tar.gz: 36272bc0744f943d88ca3eb0a33a070268f2a0fa45e130a7ee8abb04d4d0243e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bb11603444163deb47713be137b1da3234096c60c59cbedda58b35d5dafeef80a2f6f733ccd1c1d0eb4db39959f189183937a712139346ccd673a8d1ea7f8d0
|
7
|
+
data.tar.gz: 4502d6509ac75fc693ca24c9defdb401fc00aff14f3cba2d39143786efe3b0aef6eed0bc3ab6a1adb9cdd925684aa39f8e84c999dbbdd88d121efc052ba6fd84
|
data/lib/vmpooler.rb
CHANGED
@@ -16,7 +16,6 @@ module Vmpooler
|
|
16
16
|
require 'yaml'
|
17
17
|
|
18
18
|
# Dependencies for tracing
|
19
|
-
require 'opentelemetry-api'
|
20
19
|
require 'opentelemetry-instrumentation-concurrent_ruby'
|
21
20
|
require 'opentelemetry-instrumentation-redis'
|
22
21
|
require 'opentelemetry-instrumentation-sinatra'
|
@@ -53,17 +52,13 @@ module Vmpooler
|
|
53
52
|
|
54
53
|
# Bail out if someone attempts to start vmpooler with dummy authentication
|
55
54
|
# without enbaling debug mode.
|
56
|
-
if parsed_config.key? :auth
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
raise warning.join(";\s")
|
65
|
-
end
|
66
|
-
end
|
55
|
+
if parsed_config.key?(:auth) && parsed_config[:auth]['provider'] == 'dummy' && !ENV['VMPOOLER_DEBUG']
|
56
|
+
warning = [
|
57
|
+
'Dummy authentication should not be used outside of debug mode',
|
58
|
+
'please set environment variable VMPOOLER_DEBUG to \'true\' if you want to use dummy authentication'
|
59
|
+
]
|
60
|
+
|
61
|
+
raise warning.join(";\s")
|
67
62
|
end
|
68
63
|
|
69
64
|
# Set some configuration defaults
|
@@ -140,14 +135,14 @@ module Vmpooler
|
|
140
135
|
parsed_config[:pool_names] << pool['name']
|
141
136
|
pool['ready_ttl'] ||= parsed_config[:config]['ready_ttl']
|
142
137
|
if pool['alias']
|
143
|
-
if pool['alias'].
|
138
|
+
if pool['alias'].instance_of?(Array)
|
144
139
|
pool['alias'].each do |pool_alias|
|
145
140
|
parsed_config[:alias] ||= {}
|
146
141
|
parsed_config[:alias][pool_alias] = [pool['name']] unless parsed_config[:alias].key? pool_alias
|
147
142
|
parsed_config[:alias][pool_alias] << pool['name'] unless parsed_config[:alias][pool_alias].include? pool['name']
|
148
143
|
parsed_config[:pool_names] << pool_alias
|
149
144
|
end
|
150
|
-
elsif pool['alias'].
|
145
|
+
elsif pool['alias'].instance_of?(String)
|
151
146
|
parsed_config[:alias][pool['alias']] = pool['name']
|
152
147
|
parsed_config[:pool_names] << pool['alias']
|
153
148
|
end
|
@@ -128,34 +128,32 @@ module Vmpooler
|
|
128
128
|
|
129
129
|
pools.each do |pool|
|
130
130
|
running = running_hash[pool['name']]
|
131
|
-
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)
|
131
|
+
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)-/
|
132
132
|
result[pool['major']] ||= {}
|
133
133
|
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
|
134
134
|
end
|
135
135
|
|
136
|
-
if params[:history]
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
153
|
-
end
|
136
|
+
if params[:history] && graph_url
|
137
|
+
begin
|
138
|
+
buffer = URI.parse(graph_link('.running.*&from=-1hour&format=json')).read
|
139
|
+
JSON.parse(buffer).each do |pool|
|
140
|
+
if pool['target'] =~ /.*\.(.*)$/
|
141
|
+
pool['name'] = Regexp.last_match[1]
|
142
|
+
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)-/
|
143
|
+
result[pool['major']]['history'] ||= []
|
144
|
+
|
145
|
+
for i in 0..pool['datapoints'].length
|
146
|
+
if pool['datapoints'][i] && pool['datapoints'][i][0]
|
147
|
+
pool['last'] = pool['datapoints'][i][0]
|
148
|
+
result[pool['major']]['history'][i] ||= 0
|
149
|
+
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
|
150
|
+
else
|
151
|
+
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
154
152
|
end
|
155
153
|
end
|
156
154
|
end
|
157
|
-
rescue StandardError
|
158
155
|
end
|
156
|
+
rescue StandardError
|
159
157
|
end
|
160
158
|
end
|
161
159
|
JSON.pretty_generate(result)
|
data/lib/vmpooler/api/helpers.rb
CHANGED
@@ -13,12 +13,12 @@ module Vmpooler
|
|
13
13
|
def valid_token?(backend)
|
14
14
|
return false unless has_token?
|
15
15
|
|
16
|
-
backend.exists?(
|
16
|
+
backend.exists?("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}") ? true : false
|
17
17
|
end
|
18
18
|
|
19
19
|
def validate_token(backend)
|
20
20
|
if valid_token?(backend)
|
21
|
-
backend.hset(
|
21
|
+
backend.hset("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'last', Time.now)
|
22
22
|
|
23
23
|
return true
|
24
24
|
end
|
@@ -114,11 +114,13 @@ module Vmpooler
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def export_tags(backend, hostname, tags)
|
117
|
-
|
118
|
-
|
117
|
+
backend.pipelined do
|
118
|
+
tags.each_pair do |tag, value|
|
119
|
+
next if value.nil? or value.empty?
|
119
120
|
|
120
|
-
|
121
|
-
|
121
|
+
backend.hset("vmpooler__vm__#{hostname}", "tag:#{tag}", value)
|
122
|
+
backend.hset("vmpooler__tag__#{Date.today}", "#{hostname}:#{tag}", value)
|
123
|
+
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -145,7 +147,7 @@ module Vmpooler
|
|
145
147
|
|
146
148
|
def hostname_shorten(hostname, domain=nil)
|
147
149
|
if domain && hostname =~ /^[\w-]+\.#{domain}$/
|
148
|
-
hostname = hostname[/[
|
150
|
+
hostname = hostname[/[^.]+/]
|
149
151
|
end
|
150
152
|
|
151
153
|
hostname
|
@@ -251,17 +253,15 @@ module Vmpooler
|
|
251
253
|
|
252
254
|
tags = {}
|
253
255
|
|
254
|
-
backend.hgetall(
|
256
|
+
backend.hgetall("vmpooler__tag__#{date_str}").each do |key, value|
|
255
257
|
hostname = 'unknown'
|
256
258
|
tag = 'unknown'
|
257
259
|
|
258
|
-
if key =~
|
260
|
+
if key =~ /:/
|
259
261
|
hostname, tag = key.split(':', 2)
|
260
262
|
end
|
261
263
|
|
262
|
-
if opts[:only]
|
263
|
-
next unless tag == opts[:only]
|
264
|
-
end
|
264
|
+
next if opts[:only] && tag != opts[:only]
|
265
265
|
|
266
266
|
tags[tag] ||= {}
|
267
267
|
tags[tag][value] ||= 0
|
@@ -319,7 +319,7 @@ module Vmpooler
|
|
319
319
|
}
|
320
320
|
}
|
321
321
|
|
322
|
-
task[:count][:total] = backend.hlen(
|
322
|
+
task[:count][:total] = backend.hlen("vmpooler__#{task_str}__#{date_str}").to_i
|
323
323
|
|
324
324
|
if task[:count][:total] > 0
|
325
325
|
if opts[:bypool] == true
|
@@ -328,11 +328,11 @@ module Vmpooler
|
|
328
328
|
task[:count][:pool] = {}
|
329
329
|
task[:duration][:pool] = {}
|
330
330
|
|
331
|
-
backend.hgetall(
|
331
|
+
backend.hgetall("vmpooler__#{task_str}__#{date_str}").each do |key, value|
|
332
332
|
pool = 'unknown'
|
333
333
|
hostname = 'unknown'
|
334
334
|
|
335
|
-
if key =~
|
335
|
+
if key =~ /:/
|
336
336
|
pool, hostname = key.split(':')
|
337
337
|
else
|
338
338
|
hostname = key
|
data/lib/vmpooler/api/v1.rb
CHANGED
@@ -163,24 +163,25 @@ module Vmpooler
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def return_vm_to_ready_state(template, vm)
|
166
|
+
backend.srem("vmpooler__migrating__#{template}", vm)
|
167
|
+
backend.hdel("vmpooler__active__#{template}", vm)
|
168
|
+
backend.hdel("vmpooler__vm__#{vm}", 'checkout', 'token:token', 'token:user')
|
166
169
|
backend.smove("vmpooler__running__#{template}", "vmpooler__ready__#{template}", vm)
|
167
170
|
end
|
168
171
|
|
169
172
|
def account_for_starting_vm(template, vm)
|
173
|
+
user = backend.hget("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'user')
|
174
|
+
has_token_result = has_token?
|
170
175
|
backend.sadd("vmpooler__migrating__#{template}", vm)
|
171
176
|
backend.hset("vmpooler__active__#{template}", vm, Time.now)
|
172
177
|
backend.hset("vmpooler__vm__#{vm}", 'checkout', Time.now)
|
173
178
|
|
174
|
-
if Vmpooler::API.settings.config[:auth] and
|
175
|
-
|
176
|
-
|
177
|
-
backend.hset('vmpooler__vm__' + vm, 'token:token', request.env['HTTP_X_AUTH_TOKEN'])
|
178
|
-
backend.hset('vmpooler__vm__' + vm, 'token:user',
|
179
|
-
backend.hget('vmpooler__token__' + request.env['HTTP_X_AUTH_TOKEN'], 'user')
|
180
|
-
)
|
179
|
+
if Vmpooler::API.settings.config[:auth] and has_token_result
|
180
|
+
backend.hset("vmpooler__vm__#{vm}", 'token:token', request.env['HTTP_X_AUTH_TOKEN'])
|
181
|
+
backend.hset("vmpooler__vm__#{vm}", 'token:user', user)
|
181
182
|
|
182
183
|
if config['vm_lifetime_auth'].to_i > 0
|
183
|
-
backend.hset(
|
184
|
+
backend.hset("vmpooler__vm__#{vm}", 'lifetime', config['vm_lifetime_auth'].to_i)
|
184
185
|
end
|
185
186
|
end
|
186
187
|
end
|
@@ -200,16 +201,19 @@ module Vmpooler
|
|
200
201
|
failed = false
|
201
202
|
vms = []
|
202
203
|
|
204
|
+
validate_token(backend) if Vmpooler::API.settings.config[:auth] and has_token?
|
205
|
+
|
203
206
|
payload.each do |requested, count|
|
204
207
|
count.to_i.times do |_i|
|
205
208
|
vmname, vmpool, vmtemplate = fetch_single_vm(requested)
|
206
|
-
if
|
209
|
+
if vmname
|
210
|
+
account_for_starting_vm(vmpool, vmname)
|
211
|
+
vms << [vmpool, vmname, vmtemplate]
|
212
|
+
metrics.increment("checkout.success.#{vmpool}")
|
213
|
+
else
|
207
214
|
failed = true
|
208
|
-
metrics.increment(
|
215
|
+
metrics.increment("checkout.empty.#{requested}")
|
209
216
|
break
|
210
|
-
else
|
211
|
-
vms << [vmpool, vmname, vmtemplate]
|
212
|
-
metrics.increment('checkout.success.' + vmtemplate)
|
213
217
|
end
|
214
218
|
end
|
215
219
|
end
|
@@ -220,8 +224,7 @@ module Vmpooler
|
|
220
224
|
end
|
221
225
|
status 503
|
222
226
|
else
|
223
|
-
vms.each do |(
|
224
|
-
account_for_starting_vm(vmpool, vmname)
|
227
|
+
vms.each do |(_vmpool, vmname, vmtemplate)|
|
225
228
|
update_result_hosts(result, vmtemplate, vmname)
|
226
229
|
end
|
227
230
|
|
@@ -337,7 +340,7 @@ module Vmpooler
|
|
337
340
|
payload&.each do |poolname, count|
|
338
341
|
next unless count.to_i > config['max_ondemand_instances_per_request']
|
339
342
|
|
340
|
-
metrics.increment(
|
343
|
+
metrics.increment("ondemandrequest_fail.toomanyrequests.#{poolname}")
|
341
344
|
return true
|
342
345
|
end
|
343
346
|
false
|
@@ -380,7 +383,7 @@ module Vmpooler
|
|
380
383
|
if Vmpooler::API.settings.config[:auth] and has_token?
|
381
384
|
backend.hset("vmpooler__odrequest__#{request_id}", 'token:token', request.env['HTTP_X_AUTH_TOKEN'])
|
382
385
|
backend.hset("vmpooler__odrequest__#{request_id}", 'token:user',
|
383
|
-
backend.hget(
|
386
|
+
backend.hget("vmpooler__token__#{request.env['HTTP_X_AUTH_TOKEN']}", 'user'))
|
384
387
|
end
|
385
388
|
|
386
389
|
result['domain'] = config['domain'] if config['domain']
|
@@ -542,9 +545,9 @@ module Vmpooler
|
|
542
545
|
if subpool.include?(p['name'])
|
543
546
|
true
|
544
547
|
elsif !p['alias'].nil?
|
545
|
-
if p['alias'].
|
548
|
+
if p['alias'].instance_of?(Array)
|
546
549
|
(p['alias'] & subpool).any?
|
547
|
-
elsif p['alias'].
|
550
|
+
elsif p['alias'].instance_of?(String)
|
548
551
|
subpool.include?(p['alias'])
|
549
552
|
end
|
550
553
|
end
|
@@ -727,14 +730,14 @@ module Vmpooler
|
|
727
730
|
result = { 'ok' => false }
|
728
731
|
|
729
732
|
if Vmpooler::API.settings.config[:auth]
|
730
|
-
token = backend.hgetall(
|
733
|
+
token = backend.hgetall("vmpooler__token__#{params[:token]}")
|
731
734
|
|
732
735
|
if not token.nil? and not token.empty?
|
733
736
|
status 200
|
734
737
|
|
735
738
|
pools.each do |pool|
|
736
|
-
backend.smembers(
|
737
|
-
if backend.hget(
|
739
|
+
backend.smembers("vmpooler__running__#{pool['name']}").each do |vm|
|
740
|
+
if backend.hget("vmpooler__vm__#{vm}", 'token:token') == params[:token]
|
738
741
|
token['vms'] ||= {}
|
739
742
|
token['vms']['running'] ||= []
|
740
743
|
token['vms']['running'].push(vm)
|
@@ -760,7 +763,7 @@ module Vmpooler
|
|
760
763
|
|
761
764
|
need_auth!
|
762
765
|
|
763
|
-
if backend.del(
|
766
|
+
if backend.del("vmpooler__token__#{params[:token]}").to_i > 0
|
764
767
|
status 200
|
765
768
|
result['ok'] = true
|
766
769
|
end
|
@@ -783,8 +786,8 @@ module Vmpooler
|
|
783
786
|
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
|
784
787
|
result['token'] = o[rand(25)] + (0...31).map { o[rand(o.length)] }.join
|
785
788
|
|
786
|
-
backend.hset(
|
787
|
-
backend.hset(
|
789
|
+
backend.hset("vmpooler__token__#{result['token']}", 'user', @auth.username)
|
790
|
+
backend.hset("vmpooler__token__#{result['token']}", 'created', Time.now)
|
788
791
|
|
789
792
|
status 200
|
790
793
|
result['ok'] = true
|
@@ -823,7 +826,7 @@ module Vmpooler
|
|
823
826
|
else
|
824
827
|
result[:bad_templates] = invalid
|
825
828
|
invalid.each do |bad_template|
|
826
|
-
metrics.increment(
|
829
|
+
metrics.increment("ondemandrequest_fail.invalid.#{bad_template}")
|
827
830
|
end
|
828
831
|
status 404
|
829
832
|
end
|
@@ -858,7 +861,7 @@ module Vmpooler
|
|
858
861
|
else
|
859
862
|
result[:bad_templates] = invalid
|
860
863
|
invalid.each do |bad_template|
|
861
|
-
metrics.increment(
|
864
|
+
metrics.increment("ondemandrequest_fail.invalid.#{bad_template}")
|
862
865
|
end
|
863
866
|
status 404
|
864
867
|
end
|
@@ -904,7 +907,7 @@ module Vmpooler
|
|
904
907
|
result = atomically_allocate_vms(payload)
|
905
908
|
else
|
906
909
|
invalid.each do |bad_template|
|
907
|
-
metrics.increment(
|
910
|
+
metrics.increment("checkout.invalid.#{bad_template}")
|
908
911
|
end
|
909
912
|
status 404
|
910
913
|
end
|
@@ -980,7 +983,8 @@ module Vmpooler
|
|
980
983
|
result['ok'] = true
|
981
984
|
status 202
|
982
985
|
|
983
|
-
|
986
|
+
case request_hash['status']
|
987
|
+
when 'ready'
|
984
988
|
result['ready'] = true
|
985
989
|
Parsing.get_platform_pool_count(request_hash['requested']) do |platform_alias, pool, _count|
|
986
990
|
instances = backend.smembers("vmpooler__#{request_id}__#{platform_alias}__#{pool}")
|
@@ -993,10 +997,10 @@ module Vmpooler
|
|
993
997
|
end
|
994
998
|
result['domain'] = config['domain'] if config['domain']
|
995
999
|
status 200
|
996
|
-
|
1000
|
+
when 'failed'
|
997
1001
|
result['message'] = "The request failed to provision instances within the configured ondemand_request_ttl '#{config['ondemand_request_ttl']}'"
|
998
1002
|
status 200
|
999
|
-
|
1003
|
+
when 'deleted'
|
1000
1004
|
result['message'] = 'The request has been deleted'
|
1001
1005
|
status 200
|
1002
1006
|
else
|
@@ -1059,7 +1063,7 @@ module Vmpooler
|
|
1059
1063
|
result = atomically_allocate_vms(payload)
|
1060
1064
|
else
|
1061
1065
|
invalid.each do |bad_template|
|
1062
|
-
metrics.increment(
|
1066
|
+
metrics.increment("checkout.invalid.#{bad_template}")
|
1063
1067
|
end
|
1064
1068
|
status 404
|
1065
1069
|
end
|
@@ -1082,7 +1086,7 @@ module Vmpooler
|
|
1082
1086
|
|
1083
1087
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
1084
1088
|
|
1085
|
-
rdata = backend.hgetall(
|
1089
|
+
rdata = backend.hgetall("vmpooler__vm__#{params[:hostname]}")
|
1086
1090
|
unless rdata.empty?
|
1087
1091
|
status 200
|
1088
1092
|
result['ok'] = true
|
@@ -1093,7 +1097,7 @@ module Vmpooler
|
|
1093
1097
|
result[params[:hostname]]['lifetime'] = (rdata['lifetime'] || config['vm_lifetime']).to_i
|
1094
1098
|
|
1095
1099
|
if rdata['destroy']
|
1096
|
-
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
1100
|
+
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2) if rdata['checkout']
|
1097
1101
|
result[params[:hostname]]['state'] = 'destroyed'
|
1098
1102
|
elsif rdata['checkout']
|
1099
1103
|
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
|
@@ -1155,12 +1159,12 @@ module Vmpooler
|
|
1155
1159
|
|
1156
1160
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
1157
1161
|
|
1158
|
-
rdata = backend.hgetall(
|
1162
|
+
rdata = backend.hgetall("vmpooler__vm__#{params[:hostname]}")
|
1159
1163
|
unless rdata.empty?
|
1160
1164
|
need_token! if rdata['token:token']
|
1161
1165
|
|
1162
|
-
if backend.srem(
|
1163
|
-
backend.sadd(
|
1166
|
+
if backend.srem("vmpooler__running__#{rdata['template']}", params[:hostname])
|
1167
|
+
backend.sadd("vmpooler__completed__#{rdata['template']}", params[:hostname])
|
1164
1168
|
|
1165
1169
|
status 200
|
1166
1170
|
result['ok'] = true
|
@@ -1184,7 +1188,7 @@ module Vmpooler
|
|
1184
1188
|
|
1185
1189
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
1186
1190
|
|
1187
|
-
if backend.exists?(
|
1191
|
+
if backend.exists?("vmpooler__vm__#{params[:hostname]}")
|
1188
1192
|
begin
|
1189
1193
|
jdata = JSON.parse(request.body.read)
|
1190
1194
|
rescue StandardError
|
@@ -1212,13 +1216,8 @@ module Vmpooler
|
|
1212
1216
|
end
|
1213
1217
|
|
1214
1218
|
when 'tags'
|
1215
|
-
unless arg.is_a?(Hash)
|
1216
|
-
|
1217
|
-
end
|
1218
|
-
|
1219
|
-
if config['allowed_tags']
|
1220
|
-
failure.push("You provided unsuppored tags (#{arg}).") if not (arg.keys - config['allowed_tags']).empty?
|
1221
|
-
end
|
1219
|
+
failure.push("You provided tags (#{arg}) as something other than a hash.") unless arg.is_a?(Hash)
|
1220
|
+
failure.push("You provided unsuppored tags (#{arg}).") if config['allowed_tags'] && !(arg.keys - config['allowed_tags']).empty?
|
1222
1221
|
else
|
1223
1222
|
failure.push("Unknown argument #{arg}.")
|
1224
1223
|
end
|
@@ -1235,7 +1234,7 @@ module Vmpooler
|
|
1235
1234
|
|
1236
1235
|
arg = arg.to_i
|
1237
1236
|
|
1238
|
-
backend.hset(
|
1237
|
+
backend.hset("vmpooler__vm__#{params[:hostname]}", param, arg)
|
1239
1238
|
when 'tags'
|
1240
1239
|
filter_tags(arg)
|
1241
1240
|
export_tags(backend, params[:hostname], arg)
|
@@ -1261,11 +1260,11 @@ module Vmpooler
|
|
1261
1260
|
|
1262
1261
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
1263
1262
|
|
1264
|
-
if ((params[:size].to_i > 0 )and (backend.exists?(
|
1263
|
+
if ((params[:size].to_i > 0 )and (backend.exists?("vmpooler__vm__#{params[:hostname]}")))
|
1265
1264
|
result[params[:hostname]] = {}
|
1266
1265
|
result[params[:hostname]]['disk'] = "+#{params[:size]}gb"
|
1267
1266
|
|
1268
|
-
backend.sadd('vmpooler__tasks__disk', params[:hostname]
|
1267
|
+
backend.sadd('vmpooler__tasks__disk', "#{params[:hostname]}:#{params[:size]}")
|
1269
1268
|
|
1270
1269
|
status 202
|
1271
1270
|
result['ok'] = true
|
@@ -1285,13 +1284,13 @@ module Vmpooler
|
|
1285
1284
|
|
1286
1285
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
1287
1286
|
|
1288
|
-
if backend.exists?(
|
1287
|
+
if backend.exists?("vmpooler__vm__#{params[:hostname]}")
|
1289
1288
|
result[params[:hostname]] = {}
|
1290
1289
|
|
1291
1290
|
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
|
1292
1291
|
result[params[:hostname]]['snapshot'] = o[rand(25)] + (0...31).map { o[rand(o.length)] }.join
|
1293
1292
|
|
1294
|
-
backend.sadd('vmpooler__tasks__snapshot', params[:hostname]
|
1293
|
+
backend.sadd('vmpooler__tasks__snapshot', "#{params[:hostname]}:#{result[params[:hostname]]['snapshot']}")
|
1295
1294
|
|
1296
1295
|
status 202
|
1297
1296
|
result['ok'] = true
|
@@ -1311,8 +1310,8 @@ module Vmpooler
|
|
1311
1310
|
|
1312
1311
|
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
1313
1312
|
|
1314
|
-
unless backend.hget(
|
1315
|
-
backend.sadd('vmpooler__tasks__snapshot-revert', params[:hostname]
|
1313
|
+
unless backend.hget("vmpooler__vm__#{params[:hostname]}", "snapshot:#{params[:snapshot]}").to_i.zero?
|
1314
|
+
backend.sadd('vmpooler__tasks__snapshot-revert', "#{params[:hostname]}:#{params[:snapshot]}")
|
1316
1315
|
|
1317
1316
|
status 202
|
1318
1317
|
result['ok'] = true
|