vmfloaty 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfd72279e6067194457cfff7e798bffb6c3f7e516a215ab25507836a35918dfa
4
- data.tar.gz: e5f63b9b99f8969e557cf14993d89063353b2b8d2201e2945204375f4c8599f1
3
+ metadata.gz: d229737ed9cb959ec725227d7c344ad56c1af7fcd7a53a59502fdb5bf7c0c696
4
+ data.tar.gz: 4625d46bc08dc61e806beff43237adac120d509ae704c437b47d56a4ef5413bf
5
5
  SHA512:
6
- metadata.gz: 57500a3436d64a3edc4aa8a11bcfc5590a05788268fb7c556d70816a0dede112225298f657a762c8a5eec3b829117f91599e286115237e5e039dfe5554d9d2c2
7
- data.tar.gz: 288ded1bca5cfe6bff06be880b17264ddd49a10674649a1424515af7a48d646eb0b693123aee0ec353b6bb57424f209ca7cd653e1fd3287831b137593ebfe50b
6
+ metadata.gz: 8763f1c3849bfa0ab7ad2f45cae9737ab16c4f96c7aa9ff9545126979bc7ab611cc40db1c5ace88d812a1dc7004eafa8b27210df92cbe316aff07480db9fe80a
7
+ data.tar.gz: eb5691d5fc84dc667abb0609c6ed9ce1222838e07cc3a5818c5d7294c888e869d28b8fd89300787e4691cfbf691b12356d01c2528d6c2235d832e7245b220dc3
data/lib/vmfloaty.rb CHANGED
@@ -39,8 +39,13 @@ class Vmfloaty
39
39
  c.option '--force', 'Forces vmfloaty to get requested vms'
40
40
  c.option '--json', 'Prints retrieved vms in JSON format'
41
41
  c.option '--ondemand', 'Requested vms are provisioned upon receival of the request, tracked by a request ID'
42
+ c.option '--continue STRING', String, 'resume polling ABS for job_id, for use when the cli was interrupted'
43
+ c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
42
44
  c.action do |args, options|
43
45
  verbose = options.verbose || config['verbose']
46
+ if options.loglevel
47
+ FloatyLogger.setlevel = options.loglevel
48
+ end
44
49
  service = Service.new(options, config)
45
50
  use_token = !options.notoken
46
51
  force = options.force
@@ -52,6 +57,11 @@ class Vmfloaty
52
57
 
53
58
  os_types = Utils.generate_os_hash(args)
54
59
 
60
+ if os_types.empty?
61
+ FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
62
+ exit 1
63
+ end
64
+
55
65
  max_pool_request = 5
56
66
  large_pool_requests = os_types.select { |_, v| v > max_pool_request }
57
67
  if !large_pool_requests.empty? && !force
@@ -60,12 +70,7 @@ class Vmfloaty
60
70
  exit 1
61
71
  end
62
72
 
63
- if os_types.empty?
64
- FloatyLogger.error 'No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs.'
65
- exit 1
66
- end
67
-
68
- response = service.retrieve(verbose, os_types, use_token, options.ondemand)
73
+ response = service.retrieve(verbose, os_types, use_token, options.ondemand, options.continue)
69
74
  request_id = response['request_id'] if options.ondemand
70
75
  response = service.wait_for_request(verbose, request_id) if options.ondemand
71
76
 
@@ -92,8 +97,12 @@ class Vmfloaty
92
97
  c.option '--token STRING', String, 'Token for pooler service'
93
98
  c.option '--url STRING', String, 'URL of pooler service'
94
99
  c.option '--user STRING', String, 'User to authenticate with'
100
+ c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
95
101
  c.action do |args, options|
96
102
  verbose = options.verbose || config['verbose']
103
+ if options.loglevel
104
+ FloatyLogger.setlevel = options.loglevel
105
+ end
97
106
 
98
107
  service = Service.new(options, config)
99
108
  filter = args[0]
@@ -229,8 +238,13 @@ class Vmfloaty
229
238
  c.option '--token STRING', String, 'Token for pooler service'
230
239
  c.option '--url STRING', String, 'URL of pooler service'
231
240
  c.option '--user STRING', String, 'User to authenticate with'
241
+ c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
232
242
  c.action do |args, options|
233
243
  verbose = options.verbose || config['verbose']
244
+ if options.loglevel
245
+ FloatyLogger.setlevel = options.loglevel
246
+ end
247
+
234
248
  service = Service.new(options, config)
235
249
  hostnames = args[0]
236
250
  delete_all = options.all
@@ -374,8 +388,12 @@ class Vmfloaty
374
388
  c.option '--service STRING', String, 'Configured pooler service name'
375
389
  c.option '--url STRING', String, 'URL of pooler service'
376
390
  c.option '--json', 'Prints status in JSON format'
391
+ c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
377
392
  c.action do |_, options|
378
393
  verbose = options.verbose || config['verbose']
394
+ if options.loglevel
395
+ FloatyLogger.setlevel = options.loglevel
396
+ end
379
397
  service = Service.new(options, config)
380
398
  if options.json
381
399
  pp service.status(verbose)
data/lib/vmfloaty/abs.rb CHANGED
@@ -228,7 +228,7 @@ class ABS
228
228
  end
229
229
 
230
230
  # Retrieve an OS from ABS.
231
- def self.retrieve(verbose, os_types, token, url, user, config, _ondemand = nil)
231
+ def self.retrieve(verbose, os_types, token, url, user, config, _ondemand = nil, continue = nil)
232
232
  #
233
233
  # Contents of post must be like:
234
234
  #
@@ -248,7 +248,12 @@ class ABS
248
248
  conn = Http.get_conn(verbose, supported_abs_url(url))
249
249
  conn.headers['X-AUTH-TOKEN'] = token if token
250
250
 
251
- saved_job_id = user + "-" + DateTime.now.strftime('%Q')
251
+ if continue.nil?
252
+ saved_job_id = user + "-" + DateTime.now.strftime('%Q')
253
+ else
254
+ saved_job_id = continue
255
+ end
256
+
252
257
  req_obj = {
253
258
  :resources => os_types,
254
259
  :job => {
@@ -281,26 +286,28 @@ class ABS
281
286
 
282
287
  # os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
283
288
  # raise MissingParamError, 'No operating systems provided to obtain.' if os_string.empty?
284
- FloatyLogger.info "Requesting VMs with job_id: #{saved_job_id}. Will retry for up to an hour."
289
+ FloatyLogger.info "Requesting VMs with job_id: #{saved_job_id} Will retry for up to an hour."
285
290
  res = conn.post 'request', req_obj.to_json
286
291
 
287
292
  retries = 360
288
293
 
289
- validate_queue_status_response(res.status, res.body, "Initial request", verbose)
294
+ status = validate_queue_status_response(res.status, res.body, "Initial request", verbose)
290
295
 
291
296
  begin
292
297
  (1..retries).each do |i|
293
- queue_place, res_body = check_queue(conn, saved_job_id, req_obj, verbose)
294
- return translated(res_body, saved_job_id) if res_body
298
+ res_body = check_queue(conn, saved_job_id, req_obj, verbose)
299
+ if res_body && res_body.is_a?(Array) # when we get a response with hostnames
300
+ return translated(res_body, saved_job_id)
301
+ end
295
302
 
296
303
  sleep_seconds = 10 if i >= 10
297
304
  sleep_seconds = i if i < 10
298
- FloatyLogger.info "Waiting #{sleep_seconds} seconds to check if ABS request has been filled. Queue Position: #{queue_place}... (x#{i})"
305
+ FloatyLogger.info "Waiting #{sleep_seconds}s (x#{i}) #{res_body.strip}"
299
306
 
300
307
  sleep(sleep_seconds)
301
308
  end
302
309
  rescue SystemExit, Interrupt
303
- FloatyLogger.info "\n\nFloaty interrupted, you can query the state of your request via\n1) `floaty query #{saved_job_id}` or delete it via\n2) `floaty delete #{saved_job_id}`"
310
+ FloatyLogger.info "\n\nFloaty interrupted, you can resume polling with\n1) `floaty get [same arguments] and adding the flag --continue #{saved_job_id}` or query the state of the queue via\n2) `floaty query #{saved_job_id}` or delete it via\n3) `floaty delete #{saved_job_id}`"
304
311
  exit 1
305
312
  end
306
313
  nil
@@ -325,22 +332,13 @@ class ABS
325
332
  end
326
333
 
327
334
  def self.check_queue(conn, job_id, req_obj, verbose)
328
- queue_info_res = conn.get "status/queue/info/#{job_id}"
329
- if valid_json?(queue_info_res.body)
330
- queue_info = JSON.parse(queue_info_res.body)
331
- else
332
- FloatyLogger.warn "Could not parse the status/queue/info/#{job_id}"
333
- return [nil, nil]
334
- end
335
-
336
335
  res = conn.post 'request', req_obj.to_json
337
- validate_queue_status_response(res.status, res.body, "Check queue request", verbose)
338
-
336
+ status = validate_queue_status_response(res.status, res.body, "Check queue request", verbose)
339
337
  unless res.body.empty? || !valid_json?(res.body)
340
338
  res_body = JSON.parse(res.body)
341
- return queue_info['queue_place'], res_body
339
+ return res_body
342
340
  end
343
- [queue_info['queue_place'], nil]
341
+ res.body
344
342
  end
345
343
 
346
344
  def self.snapshot(_verbose, _url, _hostname, _token)
@@ -17,6 +17,19 @@ class FloatyLogger < ::Logger
17
17
  FloatyLogger.logger.error msg
18
18
  end
19
19
 
20
+ def self.setlevel=(level)
21
+ level = level.downcase
22
+ if level == "debug"
23
+ self.logger.level = ::Logger::DEBUG
24
+ elsif level == "info"
25
+ self.logger.level = ::Logger::INFO
26
+ elsif level == "error"
27
+ self.logger.level = ::Logger::ERROR
28
+ else
29
+ error("set loglevel to debug, info or error")
30
+ end
31
+ end
32
+
20
33
  def initialize
21
34
  super(STDERR)
22
35
  self.level = ::Logger::INFO
@@ -22,7 +22,7 @@ class NonstandardPooler
22
22
  status['reserved_hosts'] || []
23
23
  end
24
24
 
25
- def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil)
25
+ def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil, _continue = nil)
26
26
  conn = Http.get_conn(verbose, url)
27
27
  conn.headers['X-AUTH-TOKEN'] = token if token
28
28
 
@@ -28,7 +28,7 @@ class Pooler
28
28
  vms
29
29
  end
30
30
 
31
- def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil)
31
+ def self.retrieve(verbose, os_type, token, url, _user, _options, ondemand = nil, _continue = nil)
32
32
  # NOTE:
33
33
  # Developers can use `Utils.generate_os_hash` to
34
34
  # generate the os_type param.
@@ -77,10 +77,10 @@ class Service
77
77
  @service_object.list_active verbose, url, token, user
78
78
  end
79
79
 
80
- def retrieve(verbose, os_types, use_token = true, ondemand = nil)
80
+ def retrieve(verbose, os_types, use_token = true, ondemand = nil, continue = nil)
81
81
  FloatyLogger.info 'Requesting a vm without a token...' unless use_token
82
82
  token_value = use_token ? token : nil
83
- @service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand
83
+ @service_object.retrieve verbose, os_types, token_value, url, user, @config, ondemand, continue
84
84
  end
85
85
 
86
86
  def wait_for_request(verbose, requestid)
@@ -116,7 +116,7 @@ class Utils
116
116
 
117
117
  output_target.puts "- [JobID:#{host_data['request']['job']['id']}] <#{host_data['state']}>"
118
118
  host_data['allocated_resources'].each do |allocated_resources, _i|
119
- if allocated_resources['engine'] == "vmpooler" && service.config["vmpooler_fallback"]
119
+ if (allocated_resources['engine'] == "vmpooler" || allocated_resources['engine'] == 'ondemand') && service.config["vmpooler_fallback"]
120
120
  vmpooler_service = service.clone
121
121
  vmpooler_service.silent = true
122
122
  vmpooler_service.maybe_use_vmpooler
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Vmfloaty
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmfloaty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cain
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-16 00:00:00.000000000 Z
12
+ date: 2021-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -115,18 +115,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.1.2
118
+ rubygems_version: 3.2.3
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: CLI application to interface with vmpooler
122
122
  test_files:
123
- - spec/vmfloaty/vmfloaty_services_spec.rb
124
- - spec/vmfloaty/utils_spec.rb
123
+ - spec/spec_helper.rb
125
124
  - spec/vmfloaty/abs/auth_spec.rb
126
125
  - spec/vmfloaty/abs_spec.rb
126
+ - spec/vmfloaty/auth_spec.rb
127
+ - spec/vmfloaty/nonstandard_pooler_spec.rb
127
128
  - spec/vmfloaty/pooler_spec.rb
128
- - spec/vmfloaty/ssh_spec.rb
129
129
  - spec/vmfloaty/service_spec.rb
130
- - spec/vmfloaty/nonstandard_pooler_spec.rb
131
- - spec/vmfloaty/auth_spec.rb
132
- - spec/spec_helper.rb
130
+ - spec/vmfloaty/ssh_spec.rb
131
+ - spec/vmfloaty/utils_spec.rb
132
+ - spec/vmfloaty/vmfloaty_services_spec.rb