morpheus-cli 4.2.6 → 4.2.7

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/api_client.rb +4 -0
  4. data/lib/morpheus/api/clouds_interface.rb +14 -0
  5. data/lib/morpheus/api/guidance_interface.rb +47 -0
  6. data/lib/morpheus/api/users_interface.rb +7 -0
  7. data/lib/morpheus/cli.rb +1 -0
  8. data/lib/morpheus/cli/account_groups_command.rb +1 -1
  9. data/lib/morpheus/cli/approvals_command.rb +2 -2
  10. data/lib/morpheus/cli/apps.rb +26 -30
  11. data/lib/morpheus/cli/blueprints_command.rb +1 -1
  12. data/lib/morpheus/cli/budgets_command.rb +2 -2
  13. data/lib/morpheus/cli/change_password_command.rb +0 -1
  14. data/lib/morpheus/cli/cli_command.rb +19 -9
  15. data/lib/morpheus/cli/clouds.rb +107 -10
  16. data/lib/morpheus/cli/clusters.rb +12 -12
  17. data/lib/morpheus/cli/commands/standard/curl_command.rb +7 -0
  18. data/lib/morpheus/cli/deployments.rb +2 -2
  19. data/lib/morpheus/cli/environments_command.rb +1 -1
  20. data/lib/morpheus/cli/execution_request_command.rb +1 -1
  21. data/lib/morpheus/cli/groups.rb +1 -1
  22. data/lib/morpheus/cli/guidance_command.rb +529 -0
  23. data/lib/morpheus/cli/hosts.rb +2 -10
  24. data/lib/morpheus/cli/instances.rb +31 -13
  25. data/lib/morpheus/cli/integrations_command.rb +1 -1
  26. data/lib/morpheus/cli/jobs_command.rb +2 -2
  27. data/lib/morpheus/cli/library_container_types_command.rb +4 -4
  28. data/lib/morpheus/cli/library_instance_types_command.rb +3 -3
  29. data/lib/morpheus/cli/library_spec_templates_command.rb +1 -1
  30. data/lib/morpheus/cli/load_balancers.rb +2 -2
  31. data/lib/morpheus/cli/mixins/print_helper.rb +43 -3
  32. data/lib/morpheus/cli/mixins/provisioning_helper.rb +251 -165
  33. data/lib/morpheus/cli/network_routers_command.rb +1 -1
  34. data/lib/morpheus/cli/price_sets_command.rb +2 -2
  35. data/lib/morpheus/cli/provisioning_licenses_command.rb +1 -1
  36. data/lib/morpheus/cli/remote.rb +6 -1
  37. data/lib/morpheus/cli/reports_command.rb +1 -1
  38. data/lib/morpheus/cli/security_group_rules.rb +1 -1
  39. data/lib/morpheus/cli/security_groups.rb +13 -5
  40. data/lib/morpheus/cli/service_plans_command.rb +2 -2
  41. data/lib/morpheus/cli/user_groups_command.rb +2 -6
  42. data/lib/morpheus/cli/user_settings_command.rb +31 -5
  43. data/lib/morpheus/cli/user_sources_command.rb +3 -3
  44. data/lib/morpheus/cli/users.rb +117 -90
  45. data/lib/morpheus/cli/version.rb +1 -1
  46. data/lib/morpheus/cli/virtual_images.rb +2 -2
  47. data/lib/morpheus/cli/whitelabel_settings_command.rb +95 -15
  48. data/lib/morpheus/cli/wiki_command.rb +2 -2
  49. data/lib/morpheus/cli/workflows.rb +2 -3
  50. data/lib/morpheus/formatters.rb +14 -5
  51. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fa057d89b29003c127a3c53616a012aeb2c23368384b85f0bf03b10bfd5124e
4
- data.tar.gz: bc219cef29503224870be7de21a626a2f98c8ed766470ee79e3001ca1c41015f
3
+ metadata.gz: 126814172818496eedcb013dedfd88920675f1646b924b1304aa89986b4883d7
4
+ data.tar.gz: 936e0252a66ee0cd7ad99c691b87ed4e3a608ffd38810fccf4673c79dc53b47f
5
5
  SHA512:
6
- metadata.gz: a93cb277435293503eddbd3abdb9f349b105298cf55820feeba7187d5c1f982b65c1cd5c2c1c4989b56f3e49c861acb8ce28e657fa4a797cd2589e193a858fd9
7
- data.tar.gz: 2e11115d23a8d1d78eeb2214ca3aac06ef8ca92fd25d873c1ef02cb8350e2bfaeaeb25c7eb53c4311820c54266fb1fcd5c8a6fe1a2bacaf7d1e04308532c4821
6
+ metadata.gz: 72ee705d6fa646418aa223fe6ba2ab2558850a8a949ab8d821018878c3288c486bde5175c2ce8d360db8587f5db9a1bd0e760af900216ec9fb82b407270648f2
7
+ data.tar.gz: 6bb390e9947db29cf1e5ead6ea4c1de0ff4f78b11268247616354d677d42b838edf9e87ffc976f75423576b98509bb98462630ce48020300cb3e749a6b4f5f01
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 4.2.6
3
+ RUN gem install morpheus-cli -v 4.2.7
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -686,6 +686,10 @@ class Morpheus::APIClient
686
686
  Morpheus::InvoicesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
687
687
  end
688
688
 
689
+ def guidance
690
+ Morpheus::GuidanceInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
691
+ end
692
+
689
693
  # add new interfaces here
690
694
 
691
695
  end
@@ -73,6 +73,20 @@ class Morpheus::CloudsInterface < Morpheus::APIClient
73
73
  execute(opts)
74
74
  end
75
75
 
76
+ def refresh(id, params={}, payload={})
77
+ url = "#{@base_url}/api/zones/#{id}/refresh"
78
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
79
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
80
+ execute(opts)
81
+ end
82
+
83
+ def sync(id, params={}, payload={})
84
+ url = "#{@base_url}/api/zones/#{id}/sync"
85
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
86
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
87
+ execute(opts)
88
+ end
89
+
76
90
  def firewall_disable(id)
77
91
  url = "#{@base_url}/api/zones/#{id}/security-groups/disable"
78
92
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -0,0 +1,47 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::GuidanceInterface < Morpheus::APIClient
4
+ def initialize(access_token, refresh_token,expires_at = nil, base_url=nil, api='guidance')
5
+ @access_token = access_token
6
+ @refresh_token = refresh_token
7
+ @base_url = base_url
8
+ @api_url = "#{base_url}/api/#{api}"
9
+ @expires_at = expires_at
10
+ end
11
+
12
+ def list(params={})
13
+ url = @api_url
14
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
15
+ execute(method: :get, url: url, headers: headers)
16
+ end
17
+
18
+ def stats()
19
+ url = "#{@api_url}/stats"
20
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
21
+ execute(method: :get, url: url, headers: headers)
22
+ end
23
+
24
+ def types()
25
+ url = "#{@api_url}/types"
26
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
27
+ execute(method: :get, url: url, headers: headers)
28
+ end
29
+
30
+ def get(id, params={})
31
+ url = "#{@api_url}/#{id}"
32
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
33
+ execute(method: :get, url: url, headers: headers)
34
+ end
35
+
36
+ def exec(id, params={})
37
+ url = "#{@api_url}/#{id}/execute"
38
+ headers = { params: params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
39
+ execute(method: :put, url: url, headers: headers)
40
+ end
41
+
42
+ def ignore(id, params={})
43
+ url = "#{@api_url}/#{id}/ignore"
44
+ headers = { params: params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
45
+ execute(method: :put, url: url, headers: headers)
46
+ end
47
+ end
@@ -31,6 +31,13 @@ class Morpheus::UsersInterface < Morpheus::APIClient
31
31
  execute(opts)
32
32
  end
33
33
 
34
+ def permissions(account_id, id)
35
+ url = build_url(account_id, id) + "/permissions"
36
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
37
+ opts = {method: :get, url: url, timeout: 10, headers: headers}
38
+ execute(opts)
39
+ end
40
+
34
41
  def available_roles(account_id, id=nil, options={})
35
42
  url = build_url(account_id, id) + "/available-roles"
36
43
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
@@ -165,6 +165,7 @@ module Morpheus
165
165
  load 'morpheus/cli/budgets_command.rb'
166
166
  load 'morpheus/cli/health_command.rb'
167
167
  load 'morpheus/cli/invoices_command.rb'
168
+ load 'morpheus/cli/guidance_command.rb'
168
169
  # add new commands here...
169
170
 
170
171
  end
@@ -83,7 +83,7 @@ class Morpheus::Cli::AccountGroupsCommand
83
83
  subtitles += parse_list_subtitles(options)
84
84
  print_h1 title, subtitles, options
85
85
  if groups.empty?
86
- print yellow,"No groups currently configured.",reset,"\n"
86
+ print cyan,"No groups found.",reset,"\n"
87
87
  else
88
88
  print_groups_table(groups, options)
89
89
  print_results_pagination(json_response)
@@ -52,7 +52,7 @@ class Morpheus::Cli::ApprovalsCommand
52
52
 
53
53
  approvals = json_response['approvals']
54
54
  if approvals.empty?
55
- print yellow,"No approvals found.",reset,"\n"
55
+ print cyan,"No approvals found.",reset,"\n"
56
56
  else
57
57
  rows = approvals.collect do |it|
58
58
  {
@@ -159,7 +159,7 @@ class Morpheus::Cli::ApprovalsCommand
159
159
  ]
160
160
  print as_pretty_table(rows, columns, options)
161
161
  else
162
- print yellow,"No requested items.",reset,"\n"
162
+ print cyan,"No requested items.",reset,"\n"
163
163
  end
164
164
 
165
165
  print reset,"\n"
@@ -298,15 +298,24 @@ class Morpheus::Cli::Apps
298
298
  end
299
299
 
300
300
  # Environment
301
+ selected_environment = nil
302
+ available_environments = get_available_environments()
301
303
  if options[:environment]
302
304
  payload['environment'] = options[:environment]
303
305
  else
304
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'environment', 'fieldLabel' => 'Environment', 'type' => 'text', 'required' => false}], options[:options])
306
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'environment', 'fieldLabel' => 'Environment', 'type' => 'select', 'selectOptions' => available_environments}], options[:options], @api_client)
305
307
  payload['environment'] = v_prompt['environment'] unless v_prompt['environment'].to_s.empty?
306
308
  end
309
+ selected_environment = nil
310
+ if payload['environment']
311
+ selected_environment = available_environments.find {|it| it['code'] == payload['environment'] || it['name'] == payload['environment'] }
312
+ if selected_environment.nil?
313
+ print_red_alert "Environment not found by name or code '#{payload['environment']}'"
314
+ return 1
315
+ end
316
+ end
307
317
  # payload['appContext'] = payload['environment'] if payload['environment']
308
318
 
309
-
310
319
  if !payload['tiers']
311
320
  if payload['blueprintId'] != 'existing'
312
321
 
@@ -376,19 +385,21 @@ class Morpheus::Cli::Apps
376
385
 
377
386
  # prompt for the cloud for this instance
378
387
  # the cloud is part of finding the scoped config in the blueprint
379
- scoped_instance_config = get_scoped_instance_config(instance_config.clone, payload['environment'], group ? group['name'] : nil, cloud ? cloud['name'] : nil)
388
+ scoped_instance_config = get_scoped_instance_config(instance_config.clone, selected_environment ? selected_environment['name'] : nil, group ? group['name'] : nil, cloud ? cloud['name'] : nil)
380
389
 
381
390
  # now configure an instance like normal, use the config as default options with :always_prompt
382
391
  instance_prompt_options = {}
383
392
  instance_prompt_options[:group] = group ? group['id'] : nil
384
393
  #instance_prompt_options[:cloud] = cloud ? cloud['name'] : nil
385
394
  instance_prompt_options[:default_cloud] = cloud ? cloud['name'] : nil
395
+ instance_prompt_options[:environment] = selected_environment ? selected_environment['code'] : nil
396
+ instance_prompt_options[:default_security_groups] = scoped_instance_config['securityGroups'] ? scoped_instance_config['securityGroups'] : nil
397
+
386
398
  instance_prompt_options[:no_prompt] = options[:no_prompt]
387
399
  #instance_prompt_options[:always_prompt] = options[:no_prompt] != true # options[:always_prompt]
388
400
  instance_prompt_options[:options] = scoped_instance_config # meh, actually need to make these default values instead..
389
401
  #instance_prompt_options[:options][:always_prompt] = instance_prompt_options[:no_prompt] != true
390
402
  instance_prompt_options[:options][:no_prompt] = instance_prompt_options[:no_prompt]
391
-
392
403
  # also allow arbritrary options passed as tierName.instanceIndex like Web.0.instance.layout.id=75
393
404
  instance_extra_options = {}
394
405
  if tier_extra_options && tier_extra_options[instance_index.to_s]
@@ -402,6 +413,7 @@ class Morpheus::Cli::Apps
402
413
  help_field_prefix = "#{tier_name}.#{instance_index}"
403
414
  instance_prompt_options[:help_field_prefix] = help_field_prefix
404
415
  instance_prompt_options[:options][:help_field_prefix] = help_field_prefix
416
+ instance_prompt_options[:locked_fields] = scoped_instance_config['lockedFields']
405
417
  # this provisioning helper method handles all (most) of the parsing and prompting
406
418
  instance_config_payload = prompt_new_instance(instance_prompt_options)
407
419
 
@@ -414,6 +426,7 @@ class Morpheus::Cli::Apps
414
426
  final_config.delete('environments')
415
427
  final_config.delete('groups')
416
428
  final_config.delete('clouds')
429
+ final_config.delete('lockedFields')
417
430
  # add config to payload
418
431
  payload['tiers'][tier_name]['instances'] ||= []
419
432
  payload['tiers'][tier_name]['instances'] << final_config
@@ -531,7 +544,12 @@ class Morpheus::Cli::Apps
531
544
  rescue TypeError, JSON::ParserError => ex
532
545
  print_error red, "Failed to parse JSON response: #{ex}", reset, "\n"
533
546
  end
534
-
547
+ # The default way to print errors, except instances => []
548
+ (json_response['errors'] || {}).each do |error_key, error_msg|
549
+ if error_key != 'instances'
550
+ print_error red, " * #{error_key} : #{error_msg}", reset, "\n"
551
+ end
552
+ end
535
553
  # looks for special error format like instances.instanceErrors
536
554
  if json_response['errors'] && json_response['errors']['instances']
537
555
  json_response['errors']['instances'].each do |error_obj|
@@ -545,13 +563,6 @@ class Morpheus::Cli::Apps
545
563
  end
546
564
  end
547
565
  end
548
- else
549
- # a default way to print errors
550
- (json_response['errors'] || {}).each do |error_key, error_msg|
551
- if error_key != 'instances'
552
- print_error red, " * #{error_key} : #{error_msg}", reset, "\n"
553
- end
554
- end
555
566
  end
556
567
  exit 1
557
568
  end
@@ -613,6 +624,7 @@ class Morpheus::Cli::Apps
613
624
  "Description" => 'description',
614
625
  "Blueprint" => lambda {|it| it['blueprint'] ? it['blueprint']['name'] : '' },
615
626
  "Group" => lambda {|it| it['group'] ? it['group']['name'] : it['siteId'] },
627
+ "Environment" => lambda {|it| it['appContext'] },
616
628
  "Account" => lambda {|it| it['account'] ? it['account']['name'] : '' },
617
629
  "Tiers" => lambda {|it|
618
630
  # it['instanceCount']
@@ -1938,6 +1950,7 @@ class Morpheus::Cli::Apps
1938
1950
  id: app['id'],
1939
1951
  name: app['name'],
1940
1952
  group: app['group'] ? app['group']['name'] : app['siteId'],
1953
+ environment: app['appContext'],
1941
1954
  tiers: tiers_str,
1942
1955
  instances: instances_str,
1943
1956
  containers: containers_str,
@@ -1954,6 +1967,7 @@ class Morpheus::Cli::Apps
1954
1967
  :id,
1955
1968
  :name,
1956
1969
  :group,
1970
+ :environment,
1957
1971
  :tiers,
1958
1972
  :instances,
1959
1973
  :containers,
@@ -2025,24 +2039,6 @@ class Morpheus::Cli::Apps
2025
2039
  return @available_blueprints
2026
2040
  end
2027
2041
 
2028
- def get_available_environments(refresh=false)
2029
- if !@available_environments || refresh
2030
- # results = @options_interface.options_for_source('environments',{})
2031
- # @available_environments = results['data'].collect {|it|
2032
- # {"id" => it["value"], "name" => it["name"], "value" => it["value"]}
2033
- # }
2034
- # todo: api call
2035
- @available_environments = [
2036
- {'name' => 'Dev', 'value' => 'Dev'},
2037
- {'name' => 'Test', 'value' => 'Test'},
2038
- {'name' => 'Staging', 'value' => 'Staging'},
2039
- {'name' => 'Production', 'value' => 'Production'}
2040
- ]
2041
- end
2042
- #puts "get_available_environments() rtn: #{@available_environments.inspect}"
2043
- return @available_environments
2044
- end
2045
-
2046
2042
  def find_blueprint_by_name_or_id(val)
2047
2043
  if val.to_s =~ /\A\d{1,}\Z/
2048
2044
  return find_blueprint_by_id(val)
@@ -1733,7 +1733,7 @@ class Morpheus::Cli::BlueprintsCommand
1733
1733
  else
1734
1734
  print_h1 "Available Tiers"
1735
1735
  if tiers.empty?
1736
- print yellow,"No tiers found.",reset,"\n"
1736
+ print cyan,"No tiers found.",reset,"\n"
1737
1737
  else
1738
1738
  print cyan
1739
1739
  tiers.each do |tier_name|
@@ -46,7 +46,7 @@ class Morpheus::Cli::BudgetsCommand
46
46
  subtitles += parse_list_subtitles(options)
47
47
  print_h1 title, subtitles
48
48
  if budgets.empty?
49
- print yellow,"No budgets found.",reset,"\n"
49
+ print cyan,"No budgets found.",reset,"\n"
50
50
  else
51
51
  columns = [
52
52
  {"ID" => lambda {|budget| budget['id'] } },
@@ -264,7 +264,7 @@ class Morpheus::Cli::BudgetsCommand
264
264
  print red,"Failed to render budget summary.",reset,"\n"
265
265
  end
266
266
  else
267
- print yellow,"No budget stat data found.",reset,"\n"
267
+ print cyan,"No budget stat data found.",reset,"\n"
268
268
  end
269
269
  return 0
270
270
  rescue RestClient::Exception => e
@@ -56,7 +56,6 @@ class Morpheus::Cli::ChangePasswordCommand
56
56
 
57
57
  connect(options)
58
58
  @current_remote = @appliance_name ? ::Morpheus::Cli::Remote.load_remote(@appliance_name) : ::Morpheus::Cli::Remote.load_active_remote()
59
- puts "args is #{args}"
60
59
  begin
61
60
  if args[0]
62
61
  username = args[0]
@@ -258,8 +258,8 @@ module Morpheus
258
258
  case option_key.to_sym
259
259
 
260
260
  when :account
261
- opts.on('-a','--account ACCOUNT', "Account Name") do |val|
262
- options[:account_name] = val
261
+ opts.on('-a','--account ACCOUNT', "Account Name or ID") do |val|
262
+ options[:account] = val
263
263
  end
264
264
  opts.on('-A','--account-id ID', "Account ID") do |val|
265
265
  options[:account_id] = val
@@ -602,18 +602,28 @@ module Morpheus
602
602
  end
603
603
 
604
604
  when :fields
605
- opts.on('-f', '--fields x,y,z', Array, "Filter Output to a limited set of fields. Default is all fields.") do |val|
606
- options[:include_fields] = val
605
+ opts.on('-f', '--fields x,y,z', Array, "Filter Output to a limited set of fields. Default is all fields for json,csv,yaml.") do |val|
606
+ if val.size == 1 && val[0].downcase == 'all'
607
+ options[:all_fields] = true
608
+ else
609
+ options[:include_fields] = val
610
+ end
607
611
  end
608
612
  opts.on('-F', '--old-fields x,y,z', Array, "alias for -f, --fields") do |val|
609
- options[:include_fields] = val
613
+ if val.size == 1 && val[0].downcase == 'all'
614
+ options[:all_fields] = true
615
+ else
616
+ options[:include_fields] = val
617
+ end
610
618
  end
611
- opts.on(nil, '--all-fields', "Show all fields. Useful for showing hidden columns on wide tables.") do
619
+ opts.add_hidden_option('-F,') if opts.is_a?(Morpheus::Cli::OptionParser)
620
+ opts.on(nil, '--all-fields', "Show all fields present in the data.") do
612
621
  options[:all_fields] = true
613
622
  end
614
- opts.add_hidden_option('--all-fields') if opts.is_a?(Morpheus::Cli::OptionParser)
615
- opts.add_hidden_option('-F,') if opts.is_a?(Morpheus::Cli::OptionParser)
616
-
623
+ #opts.add_hidden_option('--all-fields') if opts.is_a?(Morpheus::Cli::OptionParser)
624
+ opts.on(nil, '--wrap', "Wrap table columns instead hiding them when terminal is not wide enough.") do
625
+ options[:responsive_table] = false
626
+ end
617
627
  when :thin
618
628
  opts.on( '--thin', '--thin', "Format headers and columns with thin borders." ) do |val|
619
629
  options[:border_style] = :thin
@@ -12,7 +12,7 @@ class Morpheus::Cli::Clouds
12
12
  include Morpheus::Cli::InfrastructureHelper
13
13
  include Morpheus::Cli::ProvisioningHelper
14
14
 
15
- register_subcommands :list, :count, :get, :add, :update, :remove, :security_groups, :apply_security_groups, :types => :list_cloud_types
15
+ register_subcommands :list, :count, :get, :add, :update, :remove, :refresh, :security_groups, :apply_security_groups, :types => :list_cloud_types
16
16
  register_subcommands :wiki, :update_wiki
17
17
  #register_subcommands :firewall_disable, :firewall_enable
18
18
  alias_subcommand :details, :get
@@ -335,12 +335,11 @@ class Morpheus::Cli::Clouds
335
335
  json_response = @clouds_interface.create(payload)
336
336
  cloud = json_response['zone']
337
337
  if options[:json]
338
- print JSON.pretty_generate(json_response)
339
- print "\n"
338
+ puts as_json(json_response, options)
340
339
  else
341
- #list([])
342
- get([cloud["id"]])
340
+ get([cloud['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
343
341
  end
342
+ return 0
344
343
  rescue RestClient::Exception => e
345
344
  print_rest_exception(e, options)
346
345
  exit 1
@@ -405,12 +404,11 @@ class Morpheus::Cli::Clouds
405
404
  end
406
405
  json_response = @clouds_interface.update(cloud['id'], payload)
407
406
  if options[:json]
408
- print JSON.pretty_generate(json_response)
409
- print "\n"
407
+ puts as_json(json_response, options)
410
408
  else
411
- #list([])
412
- get([cloud["id"]])
409
+ get([cloud['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
413
410
  end
411
+ return 0
414
412
  rescue RestClient::Exception => e
415
413
  print_rest_exception(e, options)
416
414
  exit 1
@@ -458,6 +456,105 @@ class Morpheus::Cli::Clouds
458
456
  end
459
457
  end
460
458
 
459
+ def refresh(args)
460
+ options = {}
461
+ query_params = {}
462
+ params = {}
463
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
464
+ opts.banner = subcommand_usage("[name] [options]")
465
+ opts.on( '-f', '--force', "Force Delete" ) do
466
+ query_params[:force] = 'true'
467
+ end
468
+ build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
469
+ opts.footer = "Refresh a cloud." + "\n" +
470
+ "[cloud] is required. This is the name or id of a cloud."
471
+ end
472
+ optparse.parse!(args)
473
+ if args.count != 1
474
+ raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
475
+ end
476
+ connect(options)
477
+ begin
478
+ cloud = find_cloud_by_name_or_id(args[0])
479
+ return 1 if cloud.nil?
480
+ passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
481
+ payload = nil
482
+ if options[:payload]
483
+ payload = options[:payload]
484
+ payload.deep_merge!(passed_options) unless passed_options.empty?
485
+ else
486
+ payload = {}
487
+ payload.deep_merge!(passed_options) unless passed_options.empty?
488
+ end
489
+ @clouds_interface.setopts(options)
490
+ if options[:dry_run]
491
+ print_dry_run @clouds_interface.dry.refresh(cloud['id'], query_params, payload)
492
+ return
493
+ end
494
+ json_response = @clouds_interface.refresh(cloud['id'], query_params, payload)
495
+ if options[:json]
496
+ puts as_json(json_response, options)
497
+ else
498
+ print_green_success "Refreshing cloud #{cloud['name']}..."
499
+ #get([cloud['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
500
+ end
501
+ return 0
502
+ rescue RestClient::Exception => e
503
+ print_rest_exception(e, options)
504
+ exit 1
505
+ end
506
+ end
507
+
508
+ # not exposed yet, refresh should be all that's needed.
509
+ def sync(args)
510
+ options = {}
511
+ query_params = {}
512
+ params = {}
513
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
514
+ opts.banner = subcommand_usage("[name] [options]")
515
+ opts.on( '-f', '--force', "Force Delete" ) do
516
+ query_params[:force] = 'true'
517
+ end
518
+ build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
519
+ opts.footer = "Sync a cloud." + "\n" +
520
+ "[cloud] is required. This is the name or id of a cloud."
521
+ end
522
+ optparse.parse!(args)
523
+ if args.count != 1
524
+ raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
525
+ end
526
+ connect(options)
527
+ begin
528
+ cloud = find_cloud_by_name_or_id(args[0])
529
+ return 1 if cloud.nil?
530
+ passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
531
+ payload = nil
532
+ if options[:payload]
533
+ payload = options[:payload]
534
+ payload.deep_merge!(passed_options) unless passed_options.empty?
535
+ else
536
+ payload = {}
537
+ payload.deep_merge!(passed_options) unless passed_options.empty?
538
+ end
539
+ @clouds_interface.setopts(options)
540
+ if options[:dry_run]
541
+ print_dry_run @clouds_interface.dry.sync(cloud['id'], query_params, payload)
542
+ return
543
+ end
544
+ json_response = @clouds_interface.sync(cloud['id'], query_params, payload)
545
+ if options[:json]
546
+ puts as_json(json_response, options)
547
+ else
548
+ print_green_success "Syncing cloud #{cloud['name']}..."
549
+ #get([cloud['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
550
+ end
551
+ return 0
552
+ rescue RestClient::Exception => e
553
+ print_rest_exception(e, options)
554
+ exit 1
555
+ end
556
+ end
557
+
461
558
  def firewall_disable(args)
462
559
  options = {}
463
560
  clear_or_secgroups_specified = false
@@ -643,7 +740,7 @@ class Morpheus::Cli::Clouds
643
740
  print_h1 title, subtitles
644
741
 
645
742
  if cloud_types.empty?
646
- print yellow,"No cloud types found.",reset,"\n"
743
+ print cyan,"No cloud types found.",reset,"\n"
647
744
  else
648
745
  print cyan
649
746
  cloud_types = cloud_types.select {|it| it['enabled'] }