morpheus-cli 5.4.3.1 → 5.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/api_client.rb +8 -0
  4. data/lib/morpheus/api/catalog_item_types_interface.rb +9 -12
  5. data/lib/morpheus/api/clusters_interface.rb +12 -0
  6. data/lib/morpheus/api/credential_types_interface.rb +9 -0
  7. data/lib/morpheus/api/credentials_interface.rb +9 -0
  8. data/lib/morpheus/api/monitoring_apps_interface.rb +12 -4
  9. data/lib/morpheus/api/monitoring_checks_interface.rb +12 -4
  10. data/lib/morpheus/api/monitoring_groups_interface.rb +13 -5
  11. data/lib/morpheus/api/monitoring_incidents_interface.rb +12 -4
  12. data/lib/morpheus/api/options_interface.rb +8 -1
  13. data/lib/morpheus/api/power_schedules_interface.rb +2 -2
  14. data/lib/morpheus/api/service_plans_interface.rb +6 -0
  15. data/lib/morpheus/cli/cli_command.rb +10 -17
  16. data/lib/morpheus/cli/commands/catalog_item_types_command.rb +75 -8
  17. data/lib/morpheus/cli/commands/clusters.rb +119 -5
  18. data/lib/morpheus/cli/commands/credential_types_command.rb +36 -0
  19. data/lib/morpheus/cli/commands/credentials_command.rb +124 -0
  20. data/lib/morpheus/cli/commands/hosts.rb +20 -2
  21. data/lib/morpheus/cli/commands/instances.rb +5 -1
  22. data/lib/morpheus/cli/commands/monitoring_apps_command.rb +8 -8
  23. data/lib/morpheus/cli/commands/monitoring_checks_command.rb +8 -8
  24. data/lib/morpheus/cli/commands/monitoring_groups_command.rb +8 -8
  25. data/lib/morpheus/cli/commands/monitoring_incidents_command.rb +8 -8
  26. data/lib/morpheus/cli/commands/power_schedules_command.rb +189 -258
  27. data/lib/morpheus/cli/commands/service_plans_command.rb +51 -4
  28. data/lib/morpheus/cli/commands/storage_server_types.rb +0 -5
  29. data/lib/morpheus/cli/commands/storage_servers.rb +0 -6
  30. data/lib/morpheus/cli/commands/storage_volume_types.rb +0 -5
  31. data/lib/morpheus/cli/commands/storage_volumes.rb +0 -6
  32. data/lib/morpheus/cli/mixins/provisioning_helper.rb +37 -27
  33. data/lib/morpheus/cli/mixins/rest_command.rb +20 -4
  34. data/lib/morpheus/cli/mixins/storage_servers_helper.rb +0 -63
  35. data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +0 -43
  36. data/lib/morpheus/cli/option_types.rb +1 -0
  37. data/lib/morpheus/cli/version.rb +1 -1
  38. data/lib/morpheus/routes.rb +13 -3
  39. metadata +11 -7
@@ -26,124 +26,84 @@ class Morpheus::Cli::PowerSchedulesCommand
26
26
  options = {}
27
27
  params = {}
28
28
  optparse = Morpheus::Cli::OptionParser.new do |opts|
29
- opts.banner = subcommand_usage()
30
- build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
29
+ opts.banner = subcommand_usage("[search]")
30
+ build_standard_list_options(opts, options)
31
+ opts.footer = "List power schedules."
31
32
  end
32
33
  optparse.parse!(args)
33
34
  connect(options)
34
- begin
35
- params.merge!(parse_list_options(options))
36
- @power_schedules_interface.setopts(options)
37
- if options[:dry_run]
38
- print_dry_run @power_schedules_interface.dry.list(params)
39
- return
40
- end
41
- json_response = @power_schedules_interface.list(params)
42
- if options[:json]
43
- puts as_json(json_response, options, "schedules")
44
- return 0
45
- elsif options[:csv]
46
- puts records_as_csv(json_response['schedules'], options)
47
- return 0
48
- elsif options[:yaml]
49
- puts as_yaml(json_response, options, "schedules")
50
- return 0
51
- end
52
- schedules = json_response['schedules']
53
- title = "Morpheus Power Schedules"
54
- subtitles = []
55
- subtitles += parse_list_subtitles(options)
56
- print_h1 title, subtitles
57
- if schedules.empty?
35
+ if args.count > 0
36
+ options[:phrase] = args.join(" ")
37
+ end
38
+ params.merge!(parse_list_options(options))
39
+ @power_schedules_interface.setopts(options)
40
+ if options[:dry_run]
41
+ print_dry_run @power_schedules_interface.dry.list(params)
42
+ return
43
+ end
44
+ json_response = @power_schedules_interface.list(params)
45
+ render_response(json_response, options, power_schedule_list_key) do
46
+ power_schedules = json_response[power_schedule_list_key]
47
+ print_h1 "Morpheus Power Schedules", parse_list_subtitles(options), options
48
+ if power_schedules.empty?
58
49
  print cyan,"No power schedules found.",reset,"\n"
59
50
  else
60
- print_schedules_table(schedules, options)
61
- print_results_pagination(json_response, {:label => "power schedule", :n_label => "power schedules"})
62
- # print_results_pagination(json_response)
51
+ print as_pretty_table(power_schedules, power_schedule_list_column_definitions(options).upcase_keys!, options)
52
+ print_results_pagination(json_response)
63
53
  end
64
54
  print reset,"\n"
65
- rescue RestClient::Exception => e
66
- print_rest_exception(e, options)
67
- return 1
68
55
  end
56
+ return 0, nil
69
57
  end
70
58
 
71
59
  def get(args)
60
+ params = {}
72
61
  options = {}
73
62
  options[:max_instances] = 10
74
63
  options[:max_servers] = 10
75
64
  optparse = Morpheus::Cli::OptionParser.new do |opts|
76
- opts.banner = subcommand_usage("[name]")
77
- opts.on('--max-instances VALUE', String, "Display a limited number of instances in schedule. Default is 25") do |val|
65
+ opts.banner = subcommand_usage("[schedule]")
66
+ opts.on('--max-instances VALUE', String, "Display a limited number of instances in schedule. Default is 10") do |val|
78
67
  options[:max_instances] = val.to_i
79
68
  end
80
- opts.on('--max-hosts VALUE', String, "Display a limited number of hosts in schedule. Default is 25") do |val|
69
+ opts.on('--max-hosts VALUE', String, "Display a limited number of hosts in schedule. Default is 10") do |val|
81
70
  options[:max_servers] = val.to_i
82
71
  end
83
- build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
72
+ build_standard_get_options(opts, options)
84
73
  end
85
74
  optparse.parse!(args)
86
- if args.count < 1
87
- puts optparse
88
- return 1
89
- end
75
+ verify_args!(args:args, optparse:optparse, min:1)
90
76
  connect(options)
77
+ params.merge!(parse_query_options(options))
91
78
  id_list = parse_id_list(args)
92
79
  return run_command_for_each_arg(id_list) do |arg|
93
- _get(arg, options)
80
+ _get(arg, params, options)
94
81
  end
95
82
  end
96
83
 
97
- def _get(id, options)
84
+ def _get(id, params, options)
98
85
  options ||= {}
99
86
  options[:max_servers] ||= 10
100
87
  options[:max_instances] ||= 10
101
- begin
102
- schedule = find_schedule_by_name_or_id(id)
103
- if schedule.nil?
104
- return 1
105
- end
106
- @power_schedules_interface.setopts(options)
107
- if options[:dry_run]
108
- print_dry_run @power_schedules_interface.dry.get(schedule['id'])
109
- return
110
- end
111
- json_response = @power_schedules_interface.get(schedule['id'])
112
- schedule = json_response['schedule']
88
+
89
+ schedule = find_schedule_by_name_or_id(id)
90
+ if schedule.nil?
91
+ return 1
92
+ end
93
+ @power_schedules_interface.setopts(options)
94
+ if options[:dry_run]
95
+ print_dry_run @power_schedules_interface.dry.get(schedule['id'], params)
96
+ return
97
+ end
98
+ json_response = @power_schedules_interface.get(schedule['id'], params)
99
+ render_response(json_response, options, power_schedule_object_key) do
100
+ schedule = json_response[power_schedule_object_key]
113
101
  instances = json_response['instances'] || []
114
102
  servers = json_response['servers'] || []
115
- if options[:json]
116
- puts as_json(json_response, options, "schedule")
117
- return 0
118
- elsif options[:yaml]
119
- puts as_yaml(json_response, options, "schedule")
120
- return 0
121
- elsif options[:csv]
122
- puts records_as_csv([json_response['schedule']], options)
123
- return 0
124
- end
125
-
103
+
126
104
  print_h1 "Power Schedule Details"
127
105
  print cyan
128
- description_cols = {
129
- "ID" => lambda {|it| it['id'] },
130
- #"Account" => lambda {|it| it['owner'] ? it['owner']['name'] : '' },
131
- "Name" => lambda {|it| it['name'] },
132
- "Description" => lambda {|it| it['description'] },
133
- "Type" => lambda {|it| format_schedule_type(it['scheduleType']) },
134
- "Enabled" => lambda {|it| format_boolean it['enabled'] },
135
- "Time Zone" => lambda {|it| it['scheduleTimezone'] || 'UTC (default)' },
136
- "Sunday" => lambda {|it| schedule_hour_to_time(it['sundayOn']) + ' - ' + schedule_hour_to_time(it['sundayOff']) },
137
- "Monday" => lambda {|it| schedule_hour_to_time(it['mondayOn']) + ' - ' + schedule_hour_to_time(it['mondayOff']) },
138
- "Tuesday" => lambda {|it| schedule_hour_to_time(it['tuesdayOn']) + ' - ' + schedule_hour_to_time(it['tuesdayOff']) },
139
- "Wednesday" => lambda {|it| schedule_hour_to_time(it['wednesdayOn']) + ' - ' + schedule_hour_to_time(it['wednesdayOff']) },
140
- "Thursday" => lambda {|it| schedule_hour_to_time(it['thursdayOn']) + ' - ' + schedule_hour_to_time(it['thursdayOff']) },
141
- "Friday" => lambda {|it| schedule_hour_to_time(it['fridayOn']) + ' - ' + schedule_hour_to_time(it['fridayOff']) },
142
- "Saturday" => lambda {|it| schedule_hour_to_time(it['saturdayOn']) + ' - ' + schedule_hour_to_time(it['saturdayOff']) },
143
- "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
144
- "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
145
- }
146
- print_description_list(description_cols, schedule)
106
+ print_description_list(power_schedule_column_definitions(options), schedule, options)
147
107
 
148
108
  ## Instances
149
109
  if instances.size == 0
@@ -167,11 +127,8 @@ class Morpheus::Cli::PowerSchedulesCommand
167
127
  end
168
128
 
169
129
  print reset,"\n"
170
-
171
- rescue RestClient::Exception => e
172
- print_rest_exception(e, options)
173
- return 1
174
130
  end
131
+ return 0, nil
175
132
  end
176
133
 
177
134
  def add(args)
@@ -179,59 +136,31 @@ class Morpheus::Cli::PowerSchedulesCommand
179
136
  params = {'scheduleType' => 'power'}
180
137
  optparse = Morpheus::Cli::OptionParser.new do |opts|
181
138
  opts.banner = subcommand_usage("[name]")
182
- opts.on('--name VALUE', String, "Name") do |val|
183
- params['name'] = val
184
- end
185
- # opts.on('--code VALUE', String, "Code") do |val|
186
- # params['code'] = val
187
- # end
188
- opts.on('--description VALUE', String, "Description") do |val|
189
- params['description'] = val
190
- end
191
- opts.on('--type [power|power off]', String, "Type of Schedule. Default is 'power'") do |val|
192
- params['scheduleType'] = val
193
- end
194
- opts.on('--timezone CODE', String, "The timezone. Default is UTC.") do |val|
195
- params['scheduleTimezone'] = val
196
- end
197
- [
198
- 'sunday','monday','tuesday','wednesday','thursday','friday','saturday'
199
- ].each do |day|
200
- opts.on("--#{day}On [0-24]", String, "#{day.capitalize} start hour. Default is 0.") do |val|
201
- params["#{day}On"] = val.to_f
202
- end
203
- opts.on("--#{day}Off [0-24]", String, "#{day.capitalize} end hour. Default is 24.") do |val|
204
- params["#{day}Off"] = val.to_f
205
- end
206
- end
207
- opts.on('--enabled [on|off]', String, "Can be used to disable it") do |val|
208
- params['enabled'] = !(val.to_s == 'off' || val.to_s == 'false')
209
- end
210
- build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
139
+ build_option_type_options(opts, options, add_power_schedule_option_types)
140
+ build_standard_add_options(opts, options)
211
141
  opts.footer = "Create a new power schedule." + "\n" +
212
142
  "[name] is required and can be passed as --name instead."
213
143
  end
214
144
  optparse.parse!(args)
215
- if args.count > 1
216
- print_error Morpheus::Terminal.angry_prompt
217
- puts_error "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
218
- return 1
219
- end
145
+ verify_args!(args:args, optparse:optparse, min:0, max:1)
220
146
  # support [name] as first argument
221
147
  if args[0]
222
- params['name'] = args[0]
148
+ options[:options]['name'] = args[0]
223
149
  end
224
150
  connect(options)
225
151
  begin
226
152
  # construct payload
227
- payload = nil
153
+ payload = {}
228
154
  if options[:payload]
229
155
  payload = options[:payload]
156
+ payload.deep_merge!({'schedule' => parse_passed_options(options)})
230
157
  else
231
158
  # merge -O options into normally parsed options
232
- params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
233
- # todo: prompt?
234
- payload = {'schedule' => params}
159
+ payload.deep_merge!({'schedule' => parse_passed_options(options)})
160
+ # prompt
161
+ schedule_payload = Morpheus::Cli::OptionTypes.prompt(add_power_schedule_option_types, options[:options], @api_client, options[:params])
162
+ payload.deep_merge!({'schedule' => schedule_payload})
163
+ payload.booleanize!
235
164
  end
236
165
  @power_schedules_interface.setopts(options)
237
166
  if options[:dry_run]
@@ -244,7 +173,7 @@ class Morpheus::Cli::PowerSchedulesCommand
244
173
  elsif !options[:quiet]
245
174
  schedule = json_response['schedule']
246
175
  print_green_success "Added power schedule #{schedule['name']}"
247
- _get(schedule['id'], {})
176
+ _get(schedule['id'], {}, options)
248
177
  end
249
178
  return 0
250
179
  rescue RestClient::Exception => e
@@ -258,45 +187,14 @@ class Morpheus::Cli::PowerSchedulesCommand
258
187
  options = {}
259
188
  params = {}
260
189
  optparse = Morpheus::Cli::OptionParser.new do |opts|
261
- opts.banner = subcommand_usage("[name]")
262
- opts.on('--name VALUE', String, "Name") do |val|
263
- params['name'] = val
264
- end
265
- # opts.on('--code VALUE', String, "Code") do |val|
266
- # params['code'] = val
267
- # end
268
- opts.on('--description VALUE', String, "Description") do |val|
269
- params['description'] = val
270
- end
271
- opts.on('--type [power|power off]', String, "Type of Schedule. Default is 'power'") do |val|
272
- params['scheduleType'] = val
273
- end
274
- opts.on('--timezone CODE', String, "The timezone. Default is UTC.") do |val|
275
- params['scheduleTimezone'] = val
276
- end
277
- [
278
- 'sunday','monday','tuesday','wednesday','thursday','friday','saturday'
279
- ].each do |day|
280
- opts.on("--#{day}On [0-24]", String, "#{day.capitalize} on hour. Default is 0.") do |val|
281
- params["#{day}On"] = val.to_f
282
- end
283
- opts.on("--#{day}Off [0-24]", String, "#{day.capitalize} off hour. Default is 24.") do |val|
284
- params["#{day}Off"] = val.to_f
285
- end
286
- end
287
- opts.on('--enabled [on|off]', String, "Can be used to disable it") do |val|
288
- params['enabled'] = !(val.to_s == 'off' || val.to_s == 'false')
289
- end
290
- build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
190
+ opts.banner = subcommand_usage("[schedule]")
191
+ build_option_type_options(opts, options, update_power_schedule_option_types)
192
+ build_standard_add_options(opts, options)
291
193
  opts.footer = "Update a power schedule." + "\n" +
292
- "[name] is required. This is the name or id of a power schedule."
194
+ "[schedule] is required. This is the name or id of a power schedule."
293
195
  end
294
196
  optparse.parse!(args)
295
- if args.count != 1
296
- print_error Morpheus::Terminal.angry_prompt
297
- puts_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.inspect}\n#{optparse}"
298
- return 1
299
- end
197
+ verify_args!(args:args, optparse:optparse, count:1)
300
198
  connect(options)
301
199
  begin
302
200
  schedule = find_schedule_by_name_or_id(args[0])
@@ -304,13 +202,17 @@ class Morpheus::Cli::PowerSchedulesCommand
304
202
  return 1
305
203
  end
306
204
  # construct payload
307
- payload = nil
205
+ payload = {}
308
206
  if options[:payload]
309
207
  payload = options[:payload]
208
+ payload.deep_merge!({'schedule' => parse_passed_options(options)})
310
209
  else
311
210
  # merge -O options into normally parsed options
312
- params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
313
- payload = {'schedule' => params}
211
+ payload.deep_merge!({'schedule' => parse_passed_options(options)})
212
+ # prompt
213
+ schedule_payload = Morpheus::Cli::OptionTypes.no_prompt(update_power_schedule_option_types, options[:options], @api_client, options[:params])
214
+ payload.deep_merge!({'schedule' => schedule_payload})
215
+ payload.booleanize!
314
216
  end
315
217
  @power_schedules_interface.setopts(options)
316
218
  if options[:dry_run]
@@ -322,7 +224,7 @@ class Morpheus::Cli::PowerSchedulesCommand
322
224
  puts as_json(json_response, options)
323
225
  elsif !options[:quiet]
324
226
  print_green_success "Updated power schedule #{schedule['name']}"
325
- _get(schedule['id'], {})
227
+ _get(schedule['id'], {}, options)
326
228
  end
327
229
  return 0
328
230
  rescue RestClient::Exception => e
@@ -335,14 +237,11 @@ class Morpheus::Cli::PowerSchedulesCommand
335
237
  options = {}
336
238
  params = {}
337
239
  optparse = Morpheus::Cli::OptionParser.new do |opts|
338
- opts.banner = subcommand_usage("[name]")
339
- build_common_options(opts, options, [:json, :dry_run, :quiet, :auto_confirm])
240
+ opts.banner = subcommand_usage("[schedule]")
241
+ build_standard_remove_options(opts, options)
340
242
  end
341
243
  optparse.parse!(args)
342
- if args.count < 1
343
- puts optparse
344
- return 127
345
- end
244
+ verify_args!(args:args, optparse:optparse, count:1)
346
245
  connect(options)
347
246
 
348
247
  begin
@@ -355,11 +254,6 @@ class Morpheus::Cli::PowerSchedulesCommand
355
254
  return false
356
255
  end
357
256
 
358
- # payload = {
359
- # 'schedule' => {id: schedule["id"]}
360
- # }
361
- # payload['schedule'].merge!(schedule)
362
- payload = params
363
257
  @power_schedules_interface.setopts(options)
364
258
  if options[:dry_run]
365
259
  print_dry_run @power_schedules_interface.dry.destroy(schedule["id"])
@@ -383,17 +277,14 @@ class Morpheus::Cli::PowerSchedulesCommand
383
277
  options = {}
384
278
  params = {}
385
279
  optparse = Morpheus::Cli::OptionParser.new do |opts|
386
- opts.banner = subcommand_usage("[name] [instance]")
387
- build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
280
+ opts.banner = subcommand_usage("[schedule] [instance]")
281
+ build_standard_update_options(opts, options)
388
282
  opts.footer = "Assign instances to a power schedule.\n" +
389
- "[name] is required. This is the name or id of a power schedule.\n" +
283
+ "[schedule] is required. This is the name or id of a power schedule.\n" +
390
284
  "[instance] is required. This is the name or id of an instance. More than one can be passed."
391
285
  end
392
286
  optparse.parse!(args)
393
- if args.count < 2
394
- puts optparse
395
- return 1
396
- end
287
+ verify_args!(args:args, optparse:optparse, min:2)
397
288
  connect(options)
398
289
  begin
399
290
  schedule = find_schedule_by_name_or_id(args[0])
@@ -402,10 +293,12 @@ class Morpheus::Cli::PowerSchedulesCommand
402
293
  end
403
294
 
404
295
  # construct payload
405
- payload = nil
296
+ payload = {}
406
297
  if options[:payload]
407
298
  payload = options[:payload]
299
+ payload.deep_merge!(parse_passed_options(options))
408
300
  else
301
+ payload.deep_merge!(parse_passed_options(options))
409
302
  instance_ids = args[1..-1]
410
303
  instances = []
411
304
  instance_ids.each do |instance_id|
@@ -413,7 +306,7 @@ class Morpheus::Cli::PowerSchedulesCommand
413
306
  return 1 if instance.nil?
414
307
  instances << instance
415
308
  end
416
- payload = {'instances' => instances.collect {|it| it['id'] } }
309
+ payload.deep_merge!({'instances' => instances.collect {|it| it['id'] } })
417
310
  end
418
311
  @power_schedules_interface.setopts(options)
419
312
  if options[:dry_run]
@@ -429,7 +322,7 @@ class Morpheus::Cli::PowerSchedulesCommand
429
322
  else
430
323
  print_green_success "Added #{instances.size} instances to power schedule #{schedule['name']}"
431
324
  end
432
- _get(schedule['id'], {})
325
+ _get(schedule['id'], {}, options)
433
326
  end
434
327
  return 0
435
328
  rescue RestClient::Exception => e
@@ -442,17 +335,14 @@ class Morpheus::Cli::PowerSchedulesCommand
442
335
  options = {}
443
336
  params = {}
444
337
  optparse = Morpheus::Cli::OptionParser.new do |opts|
445
- opts.banner = subcommand_usage("[name] [instance]")
446
- build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
338
+ opts.banner = subcommand_usage("[schedule] [instance]")
339
+ build_standard_update_options(opts, options)
447
340
  opts.footer = "Remove instances from a power schedule.\n" +
448
- "[name] is required. This is the name or id of a power schedule.\n" +
341
+ "[schedule] is required. This is the name or id of a power schedule.\n" +
449
342
  "[instance] is required. This is the name or id of an instance. More than one can be passed."
450
343
  end
451
344
  optparse.parse!(args)
452
- if args.count < 2
453
- puts optparse
454
- return 1
455
- end
345
+ verify_args!(args:args, optparse:optparse, min:2)
456
346
  connect(options)
457
347
  begin
458
348
  schedule = find_schedule_by_name_or_id(args[0])
@@ -461,10 +351,12 @@ class Morpheus::Cli::PowerSchedulesCommand
461
351
  end
462
352
 
463
353
  # construct payload
464
- payload = nil
354
+ payload = {}
465
355
  if options[:payload]
466
356
  payload = options[:payload]
357
+ payload.deep_merge!(parse_passed_options(options))
467
358
  else
359
+ payload.deep_merge!(parse_passed_options(options))
468
360
  instance_ids = args[1..-1]
469
361
  instances = []
470
362
  instance_ids.each do |instance_id|
@@ -472,7 +364,7 @@ class Morpheus::Cli::PowerSchedulesCommand
472
364
  return 1 if instance.nil?
473
365
  instances << instance
474
366
  end
475
- payload = {'instances' => instances.collect {|it| it['id'] } }
367
+ payload.deep_merge!({'instances' => instances.collect {|it| it['id'] } })
476
368
  end
477
369
  @power_schedules_interface.setopts(options)
478
370
  if options[:dry_run]
@@ -488,7 +380,7 @@ class Morpheus::Cli::PowerSchedulesCommand
488
380
  else
489
381
  print_green_success "Removed #{instances.size} instances from power schedule #{schedule['name']}"
490
382
  end
491
- _get(schedule['id'], {})
383
+ _get(schedule['id'], {}, options)
492
384
  end
493
385
  return 0
494
386
  rescue RestClient::Exception => e
@@ -501,17 +393,14 @@ class Morpheus::Cli::PowerSchedulesCommand
501
393
  options = {}
502
394
  params = {}
503
395
  optparse = Morpheus::Cli::OptionParser.new do |opts|
504
- opts.banner = subcommand_usage("[name] [host]")
505
- build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
396
+ opts.banner = subcommand_usage("[schedule] [host]")
397
+ build_standard_update_options(opts, options)
506
398
  opts.footer = "Assign hosts to a power schedule.\n" +
507
- "[name] is required. This is the name or id of a power schedule.\n" +
399
+ "[schedule] is required. This is the name or id of a power schedule.\n" +
508
400
  "[host] is required. This is the name or id of a host. More than one can be passed."
509
401
  end
510
402
  optparse.parse!(args)
511
- if args.count < 2
512
- puts optparse
513
- return 1
514
- end
403
+ verify_args!(args:args, optparse:optparse, min:2)
515
404
  connect(options)
516
405
  begin
517
406
  schedule = find_schedule_by_name_or_id(args[0])
@@ -520,10 +409,12 @@ class Morpheus::Cli::PowerSchedulesCommand
520
409
  end
521
410
 
522
411
  # construct payload
523
- payload = nil
412
+ payload = {}
524
413
  if options[:payload]
525
414
  payload = options[:payload]
415
+ payload.deep_merge!(parse_passed_options(options))
526
416
  else
417
+ payload.deep_merge!(parse_passed_options(options))
527
418
  server_ids = args[1..-1]
528
419
  servers = []
529
420
  server_ids.each do |server_id|
@@ -531,7 +422,7 @@ class Morpheus::Cli::PowerSchedulesCommand
531
422
  return 1 if server.nil?
532
423
  servers << server
533
424
  end
534
- payload = {'servers' => servers.collect {|it| it['id'] } }
425
+ payload.deep_merge!({'servers' => servers.collect {|it| it['id'] } })
535
426
  end
536
427
  @power_schedules_interface.setopts(options)
537
428
  if options[:dry_run]
@@ -547,7 +438,7 @@ class Morpheus::Cli::PowerSchedulesCommand
547
438
  else
548
439
  print_green_success "Added #{servers.size} hosts to power schedule #{schedule['name']}"
549
440
  end
550
- _get(schedule['id'], {})
441
+ _get(schedule['id'], {}, options)
551
442
  end
552
443
  return 0
553
444
  rescue RestClient::Exception => e
@@ -560,17 +451,14 @@ class Morpheus::Cli::PowerSchedulesCommand
560
451
  options = {}
561
452
  params = {}
562
453
  optparse = Morpheus::Cli::OptionParser.new do |opts|
563
- opts.banner = subcommand_usage("[name] [host]")
564
- build_common_options(opts, options, [:payload, :json, :dry_run, :remote, :quiet])
454
+ opts.banner = subcommand_usage("[schedule] [host]")
455
+ build_standard_update_options(opts, options)
565
456
  opts.footer = "Remove hosts from a power schedule.\n" +
566
- "[name] is required. This is the name or id of a power schedule.\n" +
457
+ "[schedule] is required. This is the name or id of a power schedule.\n" +
567
458
  "[host] is required. This is the name or id of a host. More than one can be passed."
568
459
  end
569
460
  optparse.parse!(args)
570
- if args.count < 2
571
- puts optparse
572
- return 1
573
- end
461
+ verify_args!(args:args, optparse:optparse, min:2)
574
462
  connect(options)
575
463
  begin
576
464
  schedule = find_schedule_by_name_or_id(args[0])
@@ -579,10 +467,12 @@ class Morpheus::Cli::PowerSchedulesCommand
579
467
  end
580
468
 
581
469
  # construct payload
582
- payload = nil
470
+ payload = {}
583
471
  if options[:payload]
584
472
  payload = options[:payload]
473
+ payload.deep_merge!(parse_passed_options(options))
585
474
  else
475
+ payload.deep_merge!(parse_passed_options(options))
586
476
  server_ids = args[1..-1]
587
477
  servers = []
588
478
  server_ids.each do |server_id|
@@ -590,7 +480,7 @@ class Morpheus::Cli::PowerSchedulesCommand
590
480
  return 1 if server.nil?
591
481
  servers << server
592
482
  end
593
- payload = {'servers' => servers.collect {|it| it['id'] } }
483
+ payload.deep_merge!({'servers' => servers.collect {|it| it['id'] } })
594
484
  end
595
485
  @power_schedules_interface.setopts(options)
596
486
  if options[:dry_run]
@@ -606,7 +496,7 @@ class Morpheus::Cli::PowerSchedulesCommand
606
496
  else
607
497
  print_green_success "Removed #{servers.size} hosts from power schedule #{schedule['name']}"
608
498
  end
609
- _get(schedule['id'], {})
499
+ _get(schedule['id'], {}, options)
610
500
  end
611
501
  return 0
612
502
  rescue RestClient::Exception => e
@@ -618,6 +508,71 @@ class Morpheus::Cli::PowerSchedulesCommand
618
508
 
619
509
  private
620
510
 
511
+ def power_schedule_object_key
512
+ 'schedule'
513
+ end
514
+
515
+ def power_schedule_list_key
516
+ 'schedules'
517
+ end
518
+
519
+ def power_schedule_list_column_definitions(options)
520
+ {
521
+ "ID" => lambda {|it| it['id'] },
522
+ "Name" => lambda {|it| it['name'] },
523
+ "Description" => lambda {|it| it['description'] },
524
+ "Type" => lambda {|it| format_schedule_type(it['scheduleType']) }
525
+ }
526
+ end
527
+
528
+ def power_schedule_column_definitions(options)
529
+ {
530
+ "ID" => lambda {|it| it['id'] },
531
+ #"Account" => lambda {|it| it['owner'] ? it['owner']['name'] : '' },
532
+ "Name" => lambda {|it| it['name'] },
533
+ "Description" => lambda {|it| it['description'] },
534
+ "Type" => lambda {|it| format_schedule_type(it['scheduleType']) },
535
+ "Enabled" => lambda {|it| format_boolean it['enabled'] },
536
+ "Time Zone" => lambda {|it| it['scheduleTimezone'] || 'UTC (default)' },
537
+ "Monday" => lambda {|it| format_schedule_day(it, "monday")},
538
+ "Tuesday" => lambda {|it| format_schedule_day(it, "tuesday") },
539
+ "Wednesday" => lambda {|it| format_schedule_day(it, "wednesday") },
540
+ "Thursday" => lambda {|it| format_schedule_day(it, "thursday") },
541
+ "Friday" => lambda {|it| format_schedule_day(it, "friday") },
542
+ "Saturday" => lambda {|it| format_schedule_day(it, "saturday") },
543
+ "Sunday" => lambda {|it| format_schedule_day(it, "sunday") },
544
+ "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
545
+ "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
546
+ }
547
+ end
548
+
549
+ def add_power_schedule_option_types()
550
+ option_list = [
551
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Choose a unique name for the power schedule', 'fieldGroup' => 'Options', 'displayOrder' => 1},
552
+ {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'description' => 'Description', 'displayOrder' => 2},
553
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 3},
554
+ {'fieldName' => 'scheduleTimezone', 'fieldLabel' => 'Time Zone', 'type' => 'select', 'optionSource' => 'timezones', 'description' => "Time Zone", 'displayOrder' => 4}, #, 'defaultValue' => Time.now.zone
555
+ {'fieldName' => 'scheduleType', 'fieldLabel' => 'Schedule Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Power On', 'value' => 'power'}, {'name' => 'Power Off', 'value' => 'power off'}], 'defaultValue' => 'power', 'description' => "Type of Power Schedule 'power' or 'power off'", 'displayOrder' => 5},
556
+ {'fieldName' => 'enabled', 'fieldLabel' => 'Enabled', 'type' => 'checkbox', 'defaultValue' => true, 'description' => 'Enable the power schedule to make it available for use.', 'displayOrder' => 6},
557
+ ]
558
+ [
559
+ 'monday','tuesday','wednesday','thursday','friday','saturday','sunday'
560
+ ].each_with_index do |day, i|
561
+ option_list << {'fieldName' => "#{day}OnTime", 'fieldLabel' => "#{day.capitalize} Start", 'type' => 'text', 'placeHolder' => 'HH:MM', 'description' => "#{day.capitalize} start time in HH:MM 24-hour format", 'defaultValue' => "00:00", 'displayOrder' => 7+((i*2))}
562
+ option_list << {'fieldName' => "#{day}OffTime", 'fieldLabel' => "#{day.capitalize} End", 'type' => 'text', 'placeHolder' => 'HH:MM', 'description' => "#{day.capitalize} end time in HH:MM 24-hour format", 'defaultValue' => "24:00", 'displayOrder' => 7+((i*2)+1)}
563
+ end
564
+ return option_list
565
+ end
566
+
567
+ def update_power_schedule_option_types()
568
+ option_list = add_power_schedule_option_types
569
+ option_list.each do |option_type|
570
+ option_type.delete('required')
571
+ option_type.delete('defaultValue')
572
+ end
573
+ return option_list
574
+ end
575
+
621
576
  def find_schedule_by_name_or_id(val)
622
577
  if val.to_s =~ /\A\d{1,}\Z/
623
578
  return find_schedule_by_id(val)
@@ -678,51 +633,27 @@ class Morpheus::Cli::PowerSchedulesCommand
678
633
  end
679
634
  end
680
635
 
681
- # convert the schedule on/off values [0-24] to a time
682
- def schedule_hour_to_time(val, format=nil)
683
- hour = val.to_f.floor
684
- remainder = val.to_f % 1
685
- minute = remainder == 0 ? 0 : (60 * remainder).floor
686
- # if hour > 23
687
- # "Midnight" # "12:00 AM"
688
- # elsif hour > 12
689
- # "#{(hour-12).to_s.rjust(2,'0')}:#{minute.to_s.rjust(2,'0')} PM"
690
- # else
691
- # "#{hour.to_s.rjust(2,'0')}:#{minute.to_s.rjust(2,'0')} AM"
692
- # end
693
- if format == :short
694
- if minute == 0
695
- "#{hour}"
696
- else
697
- "#{hour}:#{minute.to_s.rjust(2,'0')}"
698
- end
636
+ # format day on - off times in HH:MM - HH:MM
637
+ def format_schedule_day(schedule, day)
638
+ # API used to only return On/Off but now returns OnTime/OffTime
639
+ if schedule[day + 'OnTime']
640
+ schedule[day + 'OnTime'].to_s + ' - ' + schedule[day + 'OffTime'].to_s
641
+ elsif schedule[day + 'On']
642
+ schedule_hour_to_time(schedule[day + 'On']) + ' - ' + schedule_hour_to_time(schedule[day + 'Off'])
699
643
  else
700
- "#{hour.to_s.rjust(2,'0')}:#{minute.to_s.rjust(2,'0')}"
644
+ "" #"bad day"
701
645
  end
702
646
  end
703
647
 
704
- def format_schedule_days_short(schedule)
705
- # [
706
- # "Sn: #{schedule_hour_to_time(schedule['sundayOn'])}-#{schedule_hour_to_time(schedule['sundayOff'])}",
707
- # "M: #{schedule_hour_to_time(schedule['mondayOn'])}-#{schedule_hour_to_time(schedule['mondayOff'])}",
708
- # "T: #{schedule_hour_to_time(schedule['tuesdayOn'])}-#{schedule_hour_to_time(schedule['tuesdayOff'])}",
709
- # "W: #{schedule_hour_to_time(schedule['wednesdayOn'])}-#{schedule_hour_to_time(schedule['wednesdayOff'])}",
710
- # "Th: #{schedule_hour_to_time(schedule['thursdayOn'])}-#{schedule_hour_to_time(schedule['thursdayOff'])}",
711
- # "F: #{schedule_hour_to_time(schedule['fridayOn'])}-#{schedule_hour_to_time(schedule['fridayOff'])}",
712
- # "S: #{schedule_hour_to_time(schedule['saturdayOn'])}-#{schedule_hour_to_time(schedule['saturdayOff'])}",
713
- # ].join(", ")
714
- [
715
- "Sn: #{schedule_hour_to_time(schedule['sundayOn'],:short)}-#{schedule_hour_to_time(schedule['sundayOff'],:short)}",
716
- "M: #{schedule_hour_to_time(schedule['mondayOn'],:short)}-#{schedule_hour_to_time(schedule['mondayOff'],:short)}",
717
- "T: #{schedule_hour_to_time(schedule['tuesdayOn'],:short)}-#{schedule_hour_to_time(schedule['tuesdayOff'],:short)}",
718
- "W: #{schedule_hour_to_time(schedule['wednesdayOn'],:short)}-#{schedule_hour_to_time(schedule['wednesdayOff'],:short)}",
719
- "Th: #{schedule_hour_to_time(schedule['thursdayOn'],:short)}-#{schedule_hour_to_time(schedule['thursdayOff'],:short)}",
720
- "F: #{schedule_hour_to_time(schedule['fridayOn'],:short)}-#{schedule_hour_to_time(schedule['fridayOff'],:short)}",
721
- "S: #{schedule_hour_to_time(schedule['saturdayOn'],:short)}-#{schedule_hour_to_time(schedule['saturdayOff'],:short)}",
722
- ].join(", ")
648
+ # convert the schedule on/off minute values [0-1440] to a time
649
+ # older versions used hours 0-24 instead of minutes
650
+ def schedule_hour_to_time(val)
651
+ hour = val.to_f.floor
652
+ remainder = val.to_f % 1
653
+ minute = remainder == 0 ? 0 : (60 * remainder).floor
654
+ "#{hour.to_s.rjust(2,'0')}:#{minute.to_s.rjust(2,'0')}"
723
655
  end
724
656
 
725
-
726
657
  def find_instance_by_name_or_id(val)
727
658
  if val.to_s =~ /\A\d{1,}\Z/
728
659
  return find_instance_by_id(val)