morpheus-cli 5.4.0 → 5.4.3.1

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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/account_users_interface.rb +68 -0
  4. data/lib/morpheus/api/api_client.rb +55 -10
  5. data/lib/morpheus/api/audit_interface.rb +9 -0
  6. data/lib/morpheus/api/catalog_item_types_interface.rb +20 -0
  7. data/lib/morpheus/api/instances_interface.rb +49 -0
  8. data/lib/morpheus/api/load_balancer_monitors_interface.rb +9 -0
  9. data/lib/morpheus/api/load_balancer_pools_interface.rb +4 -4
  10. data/lib/morpheus/api/load_balancer_profiles_interface.rb +4 -5
  11. data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +13 -4
  12. data/lib/morpheus/api/load_balancers_interface.rb +5 -0
  13. data/lib/morpheus/api/network_routers_interface.rb +9 -0
  14. data/lib/morpheus/api/network_static_routes_interface.rb +36 -0
  15. data/lib/morpheus/api/ping_interface.rb +2 -0
  16. data/lib/morpheus/api/read_interface.rb +4 -3
  17. data/lib/morpheus/api/rest_interface.rb +3 -3
  18. data/lib/morpheus/api/secondary_read_interface.rb +1 -1
  19. data/lib/morpheus/api/secondary_rest_interface.rb +19 -19
  20. data/lib/morpheus/api/setup_interface.rb +4 -0
  21. data/lib/morpheus/api/snapshots_interface.rb +19 -0
  22. data/lib/morpheus/api/storage_server_types_interface.rb +14 -0
  23. data/lib/morpheus/api/storage_servers_interface.rb +9 -0
  24. data/lib/morpheus/api/storage_volume_types_interface.rb +9 -0
  25. data/lib/morpheus/api/storage_volumes_interface.rb +9 -0
  26. data/lib/morpheus/api/users_interface.rb +16 -63
  27. data/lib/morpheus/cli/cli_command.rb +253 -5
  28. data/lib/morpheus/cli/cli_registry.rb +1 -1
  29. data/lib/morpheus/cli/commands/alias_command.rb +1 -1
  30. data/lib/morpheus/cli/commands/apps.rb +14 -78
  31. data/lib/morpheus/cli/commands/audit.rb +188 -0
  32. data/lib/morpheus/cli/commands/blueprints_command.rb +1 -1
  33. data/lib/morpheus/cli/commands/catalog_item_types_command.rb +88 -0
  34. data/lib/morpheus/cli/commands/change_password_command.rb +4 -4
  35. data/lib/morpheus/cli/commands/clusters.rb +96 -58
  36. data/lib/morpheus/cli/commands/hosts.rb +27 -15
  37. data/lib/morpheus/cli/commands/image_builder_command.rb +4 -8
  38. data/lib/morpheus/cli/commands/instances.rb +359 -3
  39. data/lib/morpheus/cli/commands/integrations_command.rb +1 -12
  40. data/lib/morpheus/cli/commands/library_instance_types_command.rb +3 -0
  41. data/lib/morpheus/cli/commands/load_balancer_monitors.rb +70 -0
  42. data/lib/morpheus/cli/commands/load_balancer_pools.rb +29 -50
  43. data/lib/morpheus/cli/commands/load_balancer_profiles.rb +64 -0
  44. data/lib/morpheus/cli/commands/load_balancer_types.rb +9 -4
  45. data/lib/morpheus/cli/commands/load_balancer_virtual_servers.rb +69 -58
  46. data/lib/morpheus/cli/commands/load_balancers.rb +109 -6
  47. data/lib/morpheus/cli/commands/network_firewalls_command.rb +22 -5
  48. data/lib/morpheus/cli/commands/network_routers_command.rb +96 -45
  49. data/lib/morpheus/cli/commands/network_static_routes_command.rb +451 -0
  50. data/lib/morpheus/cli/commands/network_transport_zones_command.rb +4 -4
  51. data/lib/morpheus/cli/commands/networks_command.rb +2 -2
  52. data/lib/morpheus/cli/commands/open_command.rb +30 -0
  53. data/lib/morpheus/cli/commands/options.rb +98 -0
  54. data/lib/morpheus/cli/commands/ping.rb +3 -5
  55. data/lib/morpheus/cli/commands/policies_command.rb +2 -2
  56. data/lib/morpheus/cli/commands/prices_command.rb +7 -7
  57. data/lib/morpheus/cli/commands/provisioning_settings_command.rb +1 -0
  58. data/lib/morpheus/cli/commands/remote.rb +20 -12
  59. data/lib/morpheus/cli/commands/roles.rb +1 -1
  60. data/lib/morpheus/cli/commands/security_groups.rb +2 -2
  61. data/lib/morpheus/cli/commands/service_plans_command.rb +1 -1
  62. data/lib/morpheus/cli/commands/setup.rb +1 -1
  63. data/lib/morpheus/cli/commands/shell.rb +2 -2
  64. data/lib/morpheus/cli/commands/snapshots.rb +139 -0
  65. data/lib/morpheus/cli/commands/storage_server_types.rb +50 -0
  66. data/lib/morpheus/cli/commands/storage_servers.rb +122 -0
  67. data/lib/morpheus/cli/commands/storage_volume_types.rb +50 -0
  68. data/lib/morpheus/cli/commands/storage_volumes.rb +103 -0
  69. data/lib/morpheus/cli/commands/tasks.rb +5 -5
  70. data/lib/morpheus/cli/commands/tenants_command.rb +1 -1
  71. data/lib/morpheus/cli/commands/user_groups_command.rb +1 -1
  72. data/lib/morpheus/cli/commands/user_settings_command.rb +3 -2
  73. data/lib/morpheus/cli/commands/user_sources_command.rb +1 -1
  74. data/lib/morpheus/cli/commands/users.rb +28 -28
  75. data/lib/morpheus/cli/commands/view.rb +102 -0
  76. data/lib/morpheus/cli/commands/virtual_images.rb +4 -1
  77. data/lib/morpheus/cli/mixins/accounts_helper.rb +5 -5
  78. data/lib/morpheus/cli/mixins/load_balancers_helper.rb +24 -4
  79. data/lib/morpheus/cli/mixins/print_helper.rb +50 -18
  80. data/lib/morpheus/cli/mixins/processes_helper.rb +1 -2
  81. data/lib/morpheus/cli/mixins/provisioning_helper.rb +96 -6
  82. data/lib/morpheus/cli/mixins/rest_command.rb +148 -74
  83. data/lib/morpheus/cli/mixins/secondary_rest_command.rb +174 -82
  84. data/lib/morpheus/cli/mixins/storage_servers_helper.rb +156 -0
  85. data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +119 -0
  86. data/lib/morpheus/cli/option_types.rb +95 -28
  87. data/lib/morpheus/cli/version.rb +1 -1
  88. data/lib/morpheus/cli.rb +1 -0
  89. data/lib/morpheus/ext/string.rb +29 -6
  90. data/lib/morpheus/routes.rb +238 -0
  91. data/lib/morpheus/util.rb +6 -1
  92. metadata +26 -2
@@ -3,33 +3,43 @@ require 'morpheus/cli/cli_command'
3
3
  class Morpheus::Cli::LoadBalancerPools
4
4
  include Morpheus::Cli::CliCommand
5
5
  include Morpheus::Cli::RestCommand
6
+ include Morpheus::Cli::SecondaryRestCommand
6
7
  include Morpheus::Cli::LoadBalancersHelper
7
8
 
8
- set_command_hidden # hide until ready
9
+ set_command_description "View and manage load balancer pools."
9
10
  set_command_name :'load-balancer-pools'
10
11
  register_subcommands :list, :get, :add, :update, :remove
11
-
12
12
  register_interfaces :load_balancer_pools,
13
- :load_balancers, :load_balancer_pools
13
+ :load_balancers, :load_balancer_types
14
+
15
+ set_rest_parent_name :load_balancers
16
+
17
+ # set_rest_interface_name :load_balancer_pools
18
+ # set_parent_rest_interface_name :load_balancers
19
+
20
+ # todo: a configurable way to load the optionTypes
21
+ # option_types = loadBalancer['poolOptionTypes']
22
+ # set_rest_has_type true
23
+ # set_rest_type :load_balancer_virtual_server_types
14
24
 
15
25
  protected
16
26
 
17
- def load_balancer_pool_list_column_definitions()
27
+ def load_balancer_pool_list_column_definitions(options)
18
28
  {
19
29
  "ID" => 'id',
20
30
  "Name" => 'name',
31
+ #"Load Balancer" => lambda {|it| it['loadBalancer'] ? it['loadBalancer']['name'] : '' },
21
32
  "Balancer Mode" => lambda {|it| it['vipBalance'] },
22
- "LB" => lambda {|it| it['loadBalancer'] ? it['loadBalancer']['name'] : '' },
23
33
  }
24
34
  end
25
35
 
26
- def load_balancer_pool_column_definitions()
36
+ def load_balancer_pool_column_definitions(options)
27
37
  {
28
38
  "ID" => 'id',
29
39
  "Name" => 'name',
40
+ "Load Balancer" => lambda {|it| it['loadBalancer'] ? it['loadBalancer']['name'] : '' },
30
41
  "Description" => 'description',
31
42
  "Balancer Mode" => lambda {|it| it['vipBalance'] },
32
- "LB" => lambda {|it| it['loadBalancer'] ? it['loadBalancer']['name'] : '' },
33
43
  # todo: more properties to show here
34
44
  "Status" => lambda {|it| format_load_balancer_pool_status(it) },
35
45
  "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
@@ -53,49 +63,9 @@ class Morpheus::Cli::LoadBalancerPools
53
63
  'Load Balancer Pools'
54
64
  end
55
65
 
56
- def find_load_balancer_pool_by_name_or_id(val)
57
- if val.to_s =~ /\A\d{1,}\Z/
58
- return find_load_balancer_pool_by_id(val)
59
- else
60
- return find_load_balancer_pool_by_name(val)
61
- end
62
- end
63
-
64
- def find_load_balancer_pool_by_id(id)
65
- begin
66
- json_response = load_balancer_pools_interface.get(id.to_i)
67
- return json_response[load_balancer_pool_object_key]
68
- rescue RestClient::Exception => e
69
- if e.response && e.response.code == 404
70
- print_red_alert "#{load_balancer_pool_label} not found by id #{id}"
71
- return nil
72
- else
73
- raise e
74
- end
75
- end
76
- end
77
-
78
- def find_load_balancer_pool_by_name(name)
79
- json_response = load_balancer_pools_interface.list({name: name.to_s})
80
- load_balancer_pools = json_response[load_balancer_pool_list_key]
81
- if load_balancer_pools.empty?
82
- print_red_alert "#{load_balancer_pool_label_plural} not found by name #{name}"
83
- return load_balancer_pools
84
- elsif load_balancer_pools.size > 1
85
- print_red_alert "#{load_balancer_pools.size} #{load_balancer_pool_label_plural.downcase} found by name #{name}"
86
- rows = load_balancer_pools.collect do |it|
87
- {id: it['id'], name: it['name']}
88
- end
89
- puts as_pretty_table(rows, [:id, :name], {color:red})
90
- return nil
91
- else
92
- return load_balancer_pools[0]
93
- end
94
- end
95
-
96
- def format_load_balancer_pool_status(pool, return_color=cyan)
66
+ def format_load_balancer_pool_status(record, return_color=cyan)
97
67
  out = ""
98
- status_string = pool['vipStatus'] || pool['status']
68
+ status_string = record['status']
99
69
  if status_string.nil? || status_string.empty? || status_string == "unknown"
100
70
  out << "#{white}UNKNOWN#{return_color}"
101
71
  elsif status_string == 'ok'
@@ -103,9 +73,18 @@ class Morpheus::Cli::LoadBalancerPools
103
73
  elsif status_string == 'syncing'
104
74
  out << "#{yellow}#{status_string.upcase}#{return_color}"
105
75
  else
106
- out << "#{red}#{status_string ? status_string.upcase : 'N/A'}#{pool['statusMessage'] ? "#{return_color} - #{pool['statusMessage']}" : ''}#{return_color}"
76
+ out << "#{red}#{status_string ? status_string.upcase : 'N/A'}#{record['statusMessage'] ? "#{return_color} - #{record['statusMessage']}" : ''}#{return_color}"
107
77
  end
108
78
  out
109
79
  end
110
80
 
81
+ def load_option_types_for_load_balancer_pool(type_record, parent_record)
82
+ load_balancer = parent_record
83
+ load_balancer_type_id = load_balancer['type']['id']
84
+ load_balancer_type = find_by_id(:load_balancer_type, load_balancer_type_id)
85
+ load_balancer_type['poolOptionTypes']
86
+ end
87
+
88
+ ## using CliCommand's generic find_by methods
89
+
111
90
  end
@@ -0,0 +1,64 @@
1
+ require 'morpheus/cli/cli_command'
2
+
3
+ class Morpheus::Cli::LoadBalancerProfiles
4
+ include Morpheus::Cli::CliCommand
5
+ include Morpheus::Cli::RestCommand
6
+ include Morpheus::Cli::SecondaryRestCommand
7
+ include Morpheus::Cli::LoadBalancersHelper
8
+
9
+ set_command_description "View and manage load balancer profiles."
10
+ set_command_name :'load-balancer-profiles'
11
+ register_subcommands :list, :get, :add, :update, :remove
12
+ register_interfaces :load_balancer_profiles,
13
+ :load_balancers, :load_balancer_types
14
+
15
+ set_rest_parent_name :load_balancers
16
+
17
+ protected
18
+
19
+ def load_balancer_profile_list_column_definitions(options)
20
+ {
21
+ "ID" => 'id',
22
+ "Name" => 'name',
23
+ # "Profile Type" => lambda {|it| it['config']['profileType'] rescue '' },
24
+ "Service Type" => lambda {|it| it['serviceTypeDisplay'] || it['serviceType'] },
25
+ }
26
+ end
27
+
28
+ def load_balancer_profile_column_definitions(options)
29
+ {
30
+ "ID" => 'id',
31
+ "Name" => 'name',
32
+ "Load Balancer" => lambda {|it| it['loadBalancer'] ? it['loadBalancer']['name'] : '' },
33
+ "Description" => 'description',
34
+ # "Profile Type" => lambda {|it| it['config']['profileType'] rescue '' },
35
+ "Service Type" => lambda {|it| it['serviceTypeDisplay'] || it['serviceType'] },
36
+ "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
37
+ "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
38
+ }
39
+ end
40
+
41
+ def load_balancer_profile_object_key
42
+ 'loadBalancerProfile'
43
+ end
44
+
45
+ def load_balancer_profile_list_key
46
+ 'loadBalancerProfiles'
47
+ end
48
+
49
+ def load_balancer_profile_label
50
+ 'Load Balancer Profile'
51
+ end
52
+
53
+ def load_balancer_profile_label_plural
54
+ 'Load Balancer Profiles'
55
+ end
56
+
57
+ def load_option_types_for_load_balancer_profile(type_record, parent_record)
58
+ load_balancer = parent_record
59
+ load_balancer_type_id = load_balancer['type']['id']
60
+ load_balancer_type = find_by_id(:load_balancer_type, load_balancer_type_id)
61
+ load_balancer_type['profileOptionTypes']
62
+ end
63
+
64
+ end
@@ -12,16 +12,21 @@ class Morpheus::Cli::LoadBalancerTypes
12
12
 
13
13
  protected
14
14
 
15
- def load_balancer_type_column_definitions
15
+ def load_balancer_type_list_column_definitions(options)
16
16
  {
17
17
  "ID" => 'id',
18
18
  "Name" => 'name',
19
- "Code" => 'code'
19
+ "Code" => 'code',
20
20
  }
21
21
  end
22
22
 
23
- def load_balancer_type_list_column_definitions
24
- load_balancer_type_column_definitions
23
+ def load_balancer_type_column_definitions(options)
24
+ {
25
+ "ID" => 'id',
26
+ "Name" => 'name',
27
+ "Code" => 'code',
28
+ "Creatable" => lambda {|it| format_boolean(it['creatable']) },
29
+ }
25
30
  end
26
31
 
27
32
  # overridden to support name or code
@@ -3,31 +3,73 @@ require 'morpheus/cli/cli_command'
3
3
  class Morpheus::Cli::LoadBalancerVirtualServers
4
4
  include Morpheus::Cli::CliCommand
5
5
  include Morpheus::Cli::RestCommand
6
- # include Morpheus::Cli::SecondaryRestCommand
6
+ include Morpheus::Cli::SecondaryRestCommand
7
7
  include Morpheus::Cli::LoadBalancersHelper
8
8
 
9
- set_command_hidden # hide until ready
9
+ set_command_description "View and manage load balancer virtual servers."
10
10
  set_command_name :'load-balancer-virtual-servers'
11
11
  register_subcommands :list, :get, :add, :update, :remove
12
-
13
12
  register_interfaces :load_balancer_virtual_servers,
14
13
  :load_balancers, :load_balancer_types
15
14
 
16
- # set_rest_parent_name :load_balancers
17
-
18
- # set_rest_interface_name :load_balancer_virtual_servers
19
- # set_parent_rest_interface_name :load_balancers
20
-
21
- # todo: a configurable way to load the optionTypes
22
- # option_types = loadBalancer['vipOptionTypes']
23
- # set_rest_has_type true
24
- # set_rest_type :load_balancer_virtual_server_types
25
-
15
+ set_rest_parent_name :load_balancers
26
16
  set_rest_arg 'vipName'
27
17
 
18
+ # overridden to provide global list functionality without requiring parent argument
19
+ =begin
20
+ def list(args)
21
+ parent_id, parent_record = nil, nil
22
+ params = {}
23
+ options = {}
24
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
25
+ opts.banner = subcommand_usage("[#{rest_parent_arg}] [search]")
26
+ build_list_options(opts, options, params)
27
+ opts.footer = <<-EOT
28
+ List #{rest_label_plural.downcase}.
29
+ [#{rest_parent_arg}] is optional. This is the #{rest_parent_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_parent_label)} #{rest_parent_label.downcase}.
30
+ [search] is optional. This is a search phrase to filter the results.
31
+ EOT
32
+ end
33
+ optparse.parse!(args)
34
+ parent_id = args[0]
35
+ connect(options)
36
+ if parent_id
37
+ args = args[1..-1]
38
+ parent_record = rest_parent_find_by_name_or_id(parent_id)
39
+ if parent_record.nil?
40
+ return 1, "#{rest_parent_label} not found for '#{parent_id}"
41
+ end
42
+ parent_id = parent_record['id']
43
+ end
44
+ parse_list_options!(args, options, params)
45
+ rest_interface.setopts(options)
46
+ if options[:dry_run]
47
+ print_dry_run rest_interface.dry.list(parent_id, params)
48
+ return
49
+ end
50
+ json_response = rest_interface.list(parent_id, params)
51
+ render_response(json_response, options, rest_list_key) do
52
+ records = json_response[rest_list_key]
53
+ print_h1 "Morpheus #{rest_label_plural}"
54
+ if records.nil? || records.empty?
55
+ print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
56
+ else
57
+ print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
58
+ print_results_pagination(json_response) if json_response['meta']
59
+ end
60
+ print reset,"\n"
61
+ end
62
+ return 0, nil
63
+ end
64
+ =end
28
65
  protected
29
66
 
30
- def load_balancer_virtual_server_list_column_definitions()
67
+ def parse_list_options!(args, options, params)
68
+ parse_parameter_as_resource_id!(:load_balancer, options, params)
69
+ super
70
+ end
71
+
72
+ def load_balancer_virtual_server_list_column_definitions(options)
31
73
  {
32
74
  "ID" => 'id',
33
75
  "Name" => 'vipName',
@@ -43,7 +85,7 @@ class Morpheus::Cli::LoadBalancerVirtualServers
43
85
  }
44
86
  end
45
87
 
46
- def load_balancer_virtual_server_column_definitions()
88
+ def load_balancer_virtual_server_column_definitions(options)
47
89
  {
48
90
  "ID" => 'id',
49
91
  "Name" => 'vipName',
@@ -63,11 +105,11 @@ class Morpheus::Cli::LoadBalancerVirtualServers
63
105
  end
64
106
 
65
107
  def load_balancer_virtual_server_object_key
66
- 'virtualServer'
108
+ 'loadBalancerInstance'
67
109
  end
68
110
 
69
111
  def load_balancer_virtual_server_list_key
70
- 'virtualServers'
112
+ 'loadBalancerInstances'
71
113
  end
72
114
 
73
115
  def load_balancer_virtual_server_label
@@ -78,52 +120,12 @@ class Morpheus::Cli::LoadBalancerVirtualServers
78
120
  'Virtual Servers'
79
121
  end
80
122
 
81
- def find_load_balancer_virtual_server_by_name_or_id(val)
82
- if val.to_s =~ /\A\d{1,}\Z/
83
- return find_load_balancer_virtual_server_by_id(val)
84
- else
85
- return find_load_balancer_virtual_server_by_name(val)
86
- end
87
- end
88
-
89
- def find_load_balancer_virtual_server_by_id(id)
90
- begin
91
- json_response = load_balancer_virtual_servers_interface.get(id.to_i)
92
- return json_response[load_balancer_virtual_server_object_key]
93
- rescue RestClient::Exception => e
94
- if e.response && e.response.code == 404
95
- print_red_alert "#{load_balancer_virtual_server_label} not found by id #{id}"
96
- return nil
97
- else
98
- raise e
99
- end
100
- end
101
- end
102
-
103
- def find_load_balancer_virtual_server_by_name(name)
104
- json_response = load_balancer_virtual_servers_interface.list({name: name.to_s})
105
- load_balancer_virtual_servers = json_response[load_balancer_virtual_server_list_key]
106
- if load_balancer_virtual_servers.empty?
107
- print_red_alert "#{load_balancer_virtual_server_label_plural} not found by name #{name}"
108
- return load_balancer_virtual_servers
109
- elsif load_balancer_virtual_servers.size > 1
110
- print_red_alert "#{load_balancer_virtual_servers.size} #{load_balancer_virtual_server_label_plural.downcase} found by name #{name}"
111
- rows = load_balancer_virtual_servers.collect do |it|
112
- {id: it['id'], name: it['name']}
113
- end
114
- puts as_pretty_table(rows, [:id, :name], {color:red})
115
- return nil
116
- else
117
- return load_balancer_virtual_servers[0]
118
- end
119
- end
120
-
121
123
  def format_virtual_server_status(virtual_server, return_color=cyan)
122
124
  out = ""
123
125
  status_string = virtual_server['vipStatus'] || virtual_server['status']
124
126
  if status_string.nil? || status_string.empty? || status_string == "unknown"
125
127
  out << "#{white}UNKNOWN#{return_color}"
126
- elsif status_string == 'ok'
128
+ elsif status_string == 'online'
127
129
  out << "#{green}#{status_string.upcase}#{return_color}"
128
130
  elsif status_string == 'syncing'
129
131
  out << "#{yellow}#{status_string.upcase}#{return_color}"
@@ -133,4 +135,13 @@ class Morpheus::Cli::LoadBalancerVirtualServers
133
135
  out
134
136
  end
135
137
 
138
+ def load_option_types_for_load_balancer_virtual_server(type_record, parent_record)
139
+ load_balancer = parent_record
140
+ load_balancer_type_id = load_balancer['type']['id']
141
+ load_balancer_type = find_by_id(:load_balancer_type, load_balancer_type_id)
142
+ load_balancer_type['vipOptionTypes']
143
+ end
144
+
145
+ ## using CliCommand's generic find_by methods
146
+
136
147
  end
@@ -5,8 +5,9 @@ class Morpheus::Cli::LoadBalancers
5
5
  include Morpheus::Cli::RestCommand
6
6
  include Morpheus::Cli::LoadBalancersHelper
7
7
 
8
+ set_command_description "View and manage load balancers."
8
9
  set_command_name :'load-balancers'
9
- register_subcommands :list, :get, :add, :update, :remove
10
+ register_subcommands :list, :get, :add, :update, :remove, :refresh
10
11
 
11
12
  # deprecated the `load-balancers types` command in 5.3.2, it moved to `load-balancer-types list`
12
13
  register_subcommands :types
@@ -22,7 +23,7 @@ class Morpheus::Cli::LoadBalancers
22
23
  record = json_response[rest_object_key]
23
24
  print_h1 rest_label, [], options
24
25
  print cyan
25
- print_description_list(rest_column_definitions, record, options)
26
+ print_description_list(rest_column_definitions(options), record, options)
26
27
  # show LB Ports
27
28
  ports = record['ports']
28
29
  if ports && ports.size > 0
@@ -41,6 +42,48 @@ class Morpheus::Cli::LoadBalancers
41
42
  end
42
43
  end
43
44
 
45
+ def refresh(args)
46
+ id = args[0]
47
+ record_type = nil
48
+ record_type_id = nil
49
+ options = {}
50
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
51
+ opts.banner = subcommand_usage("[#{rest_arg}] [options]")
52
+ build_standard_update_options(opts, options)
53
+ opts.footer = <<-EOT
54
+ Refresh an existing #{rest_label.downcase}.
55
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
56
+ EOT
57
+ end
58
+ optparse.parse!(args)
59
+ verify_args!(args:args, optparse:optparse, count:1)
60
+ connect(options)
61
+ record = rest_find_by_name_or_id(id)
62
+ if record.nil?
63
+ return 1, "#{rest_name} not found for '#{id}'"
64
+ end
65
+ passed_options = parse_passed_options(options)
66
+ payload = {}
67
+ if options[:payload]
68
+ payload = options[:payload]
69
+ payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
70
+ else
71
+ record_payload = passed_options
72
+ payload[rest_object_key] = record_payload
73
+ end
74
+ rest_interface.setopts(options)
75
+ if options[:dry_run]
76
+ print_dry_run rest_interface.dry.refresh(record['id'], payload)
77
+ return
78
+ end
79
+ json_response = rest_interface.refresh(record['id'], payload)
80
+ render_response(json_response, options, rest_object_key) do
81
+ print_green_success "Refreshing #{rest_label.downcase} #{record['name'] || record['id']}"
82
+ _get(record["id"], {}, options)
83
+ end
84
+ return 0, nil
85
+ end
86
+
44
87
  # deprecated, to be removed in the future.
45
88
  def types(args)
46
89
  print_error yellow,"[DEPRECATED] The command `load-balancers types` is deprecated and replaced by `load-balancer-types list`.",reset,"\n"
@@ -49,7 +92,24 @@ class Morpheus::Cli::LoadBalancers
49
92
 
50
93
  protected
51
94
 
52
- def load_balancer_list_column_definitions()
95
+ # filtering for NSX-T only
96
+ def rest_list_types()
97
+ rest_type_interface.list({max:10000, creatable:true})[rest_type_list_key].reject {|it| it['code'] == 'nsx-t'}
98
+ end
99
+
100
+ def load_balancer_type_list_to_options(type_list)
101
+ type_list.reject {|it| it['code'] != 'nsx-t'}.collect {|it| {'name' => it['name'], 'value' => it['code']} }
102
+ end
103
+
104
+ def add_load_balancer_footer_addn
105
+ "#{bold}Available for NSX-T load balancers only#{reset}"
106
+ end
107
+
108
+ def update_load_balancer_footer_addn
109
+ "#{bold}Available for NSX-T load balancers only#{reset}"
110
+ end
111
+
112
+ def load_balancer_list_column_definitions(options)
53
113
  {
54
114
  "ID" => 'id',
55
115
  "Name" => 'name',
@@ -59,7 +119,7 @@ class Morpheus::Cli::LoadBalancers
59
119
  }
60
120
  end
61
121
 
62
- def load_balancer_column_definitions()
122
+ def load_balancer_column_definitions(options)
63
123
  {
64
124
  "ID" => 'id',
65
125
  "Name" => 'name',
@@ -80,10 +140,53 @@ class Morpheus::Cli::LoadBalancers
80
140
  end
81
141
 
82
142
  # overridden to work with name or code
83
- def find_load_balancer_type_by_name_or_id(name)
84
- load_balancer_type_for_name_or_id(name)
143
+ # nope, api works with name=code now too
144
+ # def find_load_balancer_type_by_name_or_id(name)
145
+ # load_balancer_type_for_name_or_id(name)
146
+ # end
147
+
148
+ # def add_load_balancer_option_types()
149
+ # [
150
+ # {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true},
151
+ # {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false},
152
+ # {'fieldName' => 'enabled', 'fieldLabel' => 'Enabled', 'type' => 'checkbox', 'required' => false, 'defaultValue' => true},
153
+ # # {'fieldName' => 'type', 'fieldLabel' => 'Storage Server Type', 'type' => 'select', 'optionSource' => 'loadBalancerTypes', 'required' => true},
154
+ # ]
155
+ # end
156
+
157
+ def add_load_balancer_advanced_option_types()
158
+ [
159
+ {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'fieldGroup' => 'Advanced', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'},{'name' => 'Public', 'value' => 'public'}], 'required' => false, 'description' => 'Visibility', 'category' => 'permissions', 'defaultValue' => 'public'},
160
+ {'fieldName' => 'tenants', 'fieldLabel' => 'Tenants', 'fieldGroup' => 'Advanced', 'type' => 'multiSelect', 'resultValueField' => 'id', 'optionSource' => lambda { |api_client, api_params|
161
+ api_client.options.options_for_source("allTenants", {})['data']
162
+ }},
163
+ ]
85
164
  end
86
165
 
166
+ # def update_load_balancer_option_types()
167
+ # [
168
+ # {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text'},
169
+ # {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text'},
170
+ # {'fieldName' => 'enabled', 'fieldLabel' => 'Enabled', 'type' => 'checkbox'},
171
+ # ]
172
+ # end
87
173
 
174
+ def update_load_balancer_advanced_option_types()
175
+ add_load_balancer_advanced_option_types()
176
+ end
177
+
178
+ def load_option_types_for_load_balancer(type_record, parent_record)
179
+ load_balancer_type = type_record
180
+ # reload it by id to get optionTypes
181
+ option_types = load_balancer_type['optionTypes']
182
+ if option_types.nil?
183
+ load_balancer_type = find_by_id(:load_balancer_type, load_balancer_type['id'])
184
+ if load_balancer_type.nil?
185
+ raise_command_error("Load balancer type not found for id '#{id}'")
186
+ end
187
+ option_types = load_balancer_type['optionTypes']
188
+ end
189
+ return option_types
190
+ end
88
191
 
89
192
  end
@@ -4,7 +4,7 @@ class Morpheus::Cli::NetworkFirewallsCommand
4
4
  include Morpheus::Cli::CliCommand
5
5
  include Morpheus::Cli::ProvisioningHelper
6
6
  include Morpheus::Cli::WhoamiHelper
7
- set_command_hidden #hide until api ready
7
+
8
8
  set_command_name :'network-firewalls'
9
9
  register_subcommands :list_rules, :get_rule, :add_rule, :update_rule, :remove_rule
10
10
  register_subcommands :list_rule_groups, :get_rule_group, :add_rule_group, :update_rule_group, :remove_rule_group
@@ -65,7 +65,7 @@ class Morpheus::Cli::NetworkFirewallsCommand
65
65
  id: it['id'], group: it['groupName'], name: it['name'], description: it['description'],
66
66
  priority: it['priority'], enabled: format_boolean(it['enabled']), policy: it['policy'], direction: it['direction'],
67
67
  source: it['sources'].kind_of?(Array) && it['sources'].count > 0 ? it['sources'].collect {|it| it['name']}.join(', ') : (it['sources'].nil? || it['sources'].empty? ? 'any' : it['source']),
68
- destination: it['destinations'].count > 0 ? it['destinations'].collect {|it| it['name']}.join(', ') : (it['destinations'].nil? || it['destinations'].empty? ? 'any' : it['destination'])
68
+ destination: it['destinations'].kind_of?(Array) && it['destinations'].count > 0 ? it['destinations'].collect {|it| it['name']}.join(', ') : (it['destinations'].nil? || it['destinations'].empty? ? 'any' : it['destination'])
69
69
  }
70
70
 
71
71
  if it['applications'].count
@@ -78,9 +78,9 @@ class Morpheus::Cli::NetworkFirewallsCommand
78
78
 
79
79
  applied_to = []
80
80
  if server['type']['supportsFirewallRuleAppliedTarget']
81
- applied_to << 'All Edges' if row['config']['applyToAllEdges']
82
- applied_to << 'Distributed Firewall' if row['config']['applyToAllDistributed']
83
- applied_to += rule['appliedTargets'].collect {|it| it['name']}
81
+ applied_to << 'All Edges' if it['config']['applyToAllEdges']
82
+ applied_to << 'Distributed Firewall' if it['config']['applyToAllDistributed']
83
+ applied_to += it['appliedTargets'].collect {|target| target['name']}
84
84
  row[:applied_to] = applied_to.join(', ')
85
85
  end
86
86
  row
@@ -483,6 +483,11 @@ class Morpheus::Cli::NetworkFirewallsCommand
483
483
  server['type']['firewallGroupOptionTypes'].reject {|it| it['type'] == 'hidden'}.sort_by {|it| it['displayOrder']}.each do |option_type|
484
484
  description_cols[option_type['fieldLabel']] = lambda {|it| Morpheus::Cli::OptionTypes.get_option_value(it, option_type, true)}
485
485
  end
486
+
487
+ if is_master_account
488
+ description_cols["Visibility"] = lambda {|it| it['visibility']}
489
+ description_cols["Tenants"] = lambda {|it| it['tenants'].collect {|tenant| tenant['name']}.join(', ')}
490
+ end
486
491
  print_description_list(description_cols, group)
487
492
  end
488
493
  else
@@ -505,6 +510,7 @@ class Morpheus::Cli::NetworkFirewallsCommand
505
510
  opts.on('--priority VALUE', Integer, "Priority for this firewall rule group") do |val|
506
511
  options[:options]['priority'] = val
507
512
  end
513
+ add_perms_options(opts, options, ['plans', 'groups'])
508
514
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
509
515
  opts.footer = "Create a network firewall rule group." + "\n" +
510
516
  "[server] is optional. This is the name or id of a network server.\n";
@@ -537,6 +543,11 @@ class Morpheus::Cli::NetworkFirewallsCommand
537
543
 
538
544
  # prompt options
539
545
  option_result = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options].deep_merge({:context_map => {'ruleGroup' => ''}}), @api_client, {'networkServerId' => server['id']}, nil, true)
546
+
547
+ # prompt perms
548
+ if is_master_account
549
+ params.merge!(prompt_permissions_v2(options, ['plans', 'groups']))
550
+ end
540
551
  payload = {'ruleGroup' => params.deep_merge(option_result)}
541
552
  end
542
553
 
@@ -568,6 +579,7 @@ class Morpheus::Cli::NetworkFirewallsCommand
568
579
  opts.on('--priority VALUE', Integer, "Priority for this firewall rule group") do |val|
569
580
  options[:options]['priority'] = val
570
581
  end
582
+ add_perms_options(opts, options, ['plans', 'groups'])
571
583
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
572
584
  opts.footer = "Update a network firewall rule group.\n" +
573
585
  "[server] is optional. This is the name or id of an existing network server.\n" +
@@ -592,6 +604,11 @@ class Morpheus::Cli::NetworkFirewallsCommand
592
604
  group = find_rule_group(server['id'], group_id)
593
605
  return 1 if group.nil?
594
606
 
607
+ if is_master_account
608
+ params['visibility'] = options[:visibility] if !options[:visibility].nil?
609
+ params['tenants'] = options[:tenants].collect {|it| {'id' => it}} if !options[:tenants].nil?
610
+ end
611
+
595
612
  payload = parse_payload(options) || {'ruleGroup' => params}
596
613
  payload['ruleGroup'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options] && !payload['ruleGroup'].nil?
597
614