@@ -87,6 +87,7 @@ def run # rubocop:disable Metrics/AbcSize
87
87
c . option '--verbose' , 'Enables verbose output'
88
88
c . option '--service STRING' , String , 'Configured pooler service name'
89
89
c . option '--active' , 'Prints information about active vms for a given token'
90
+ c . option '--json' , 'Prints information as JSON'
90
91
c . option '--token STRING' , String , 'Token for pooler service'
91
92
c . option '--url STRING' , String , 'URL of pooler service'
92
93
c . action do |args , options |
@@ -100,10 +101,18 @@ def run # rubocop:disable Metrics/AbcSize
100
101
running_vms = service . list_active ( verbose )
101
102
host = URI . parse ( service . url ) . host
102
103
if running_vms . empty?
103
- puts "You have no running VMs on #{ host } "
104
+ if options . json
105
+ puts { } . to_json
106
+ else
107
+ FloatyLogger . info "You have no running VMs on #{ host } "
108
+ end
104
109
else
105
- puts "Your VMs on #{ host } :"
106
- Utils . pretty_print_hosts ( verbose , service , running_vms )
110
+ if options . json
111
+ puts Utils . get_host_data ( verbose , service , running_vms ) . to_json
112
+ else
113
+ puts "Your VMs on #{ host } :"
114
+ Utils . pretty_print_hosts ( verbose , service , running_vms )
115
+ end
107
116
end
108
117
else
109
118
# list available vms from pooler
@@ -200,6 +209,7 @@ def run # rubocop:disable Metrics/AbcSize
200
209
c . option '--service STRING' , String , 'Configured pooler service name'
201
210
c . option '--all' , 'Deletes all vms acquired by a token'
202
211
c . option '-f' , 'Does not prompt user when deleting all vms'
212
+ c . option '--json' , 'Outputs hosts scheduled for deletion as JSON'
203
213
c . option '--token STRING' , String , 'Token for pooler service'
204
214
c . option '--url STRING' , String , 'URL of pooler service'
205
215
c . action do |args , options |
@@ -215,12 +225,18 @@ def run # rubocop:disable Metrics/AbcSize
215
225
if delete_all
216
226
running_vms = service . list_active ( verbose )
217
227
if running_vms . empty?
218
- puts 'You have no running VMs.'
228
+ if options . json
229
+ puts { } . to_json
230
+ else
231
+ FloatyLogger . info "You have no running VMs."
232
+ end
219
233
else
220
- Utils . pretty_print_hosts ( verbose , service , running_vms , true )
221
- # Confirm deletion
222
234
confirmed = true
223
- confirmed = agree ( 'Delete all these VMs? [y/N]' ) unless force
235
+ unless force
236
+ Utils . pretty_print_hosts ( verbose , service , running_vms , true )
237
+ # Confirm deletion
238
+ confirmed = agree ( 'Delete all these VMs? [y/N]' )
239
+ end
224
240
if confirmed
225
241
response = service . delete ( verbose , running_vms )
226
242
response . each do |hostname , result |
@@ -257,9 +273,15 @@ def run # rubocop:disable Metrics/AbcSize
257
273
258
274
unless successes . empty?
259
275
FloatyLogger . info unless failures . empty?
260
- puts 'Scheduled the following VMs for deletion:'
261
- successes . each do |hostname |
262
- puts "- #{ hostname } "
276
+ if options . json
277
+ puts successes . to_json
278
+ else
279
+ puts 'Scheduled the following VMs for deletion:'
280
+ output = ''
281
+ successes . each do |hostname |
282
+ output += "- #{ hostname } \n "
283
+ end
284
+ puts output
263
285
end
264
286
end
265
287
0 commit comments