morpheus-cli 3.3.2.6.2 → 3.3.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/morpheus/api/api_client.rb +4 -0
  3. data/lib/morpheus/api/cloud_datastores_interface.rb +47 -0
  4. data/lib/morpheus/api/virtual_images_interface.rb +2 -2
  5. data/lib/morpheus/cli.rb +1 -0
  6. data/lib/morpheus/cli/app_templates.rb +5 -15
  7. data/lib/morpheus/cli/cli_command.rb +5 -1
  8. data/lib/morpheus/cli/cloud_datastores_command.rb +399 -0
  9. data/lib/morpheus/cli/containers_command.rb +2 -8
  10. data/lib/morpheus/cli/hosts.rb +10 -21
  11. data/lib/morpheus/cli/instance_types.rb +4 -10
  12. data/lib/morpheus/cli/instances.rb +14 -34
  13. data/lib/morpheus/cli/library_container_scripts_command.rb +5 -12
  14. data/lib/morpheus/cli/library_container_templates_command.rb +4 -10
  15. data/lib/morpheus/cli/library_container_types_command.rb +4 -10
  16. data/lib/morpheus/cli/library_instance_types_command.rb +4 -10
  17. data/lib/morpheus/cli/library_layouts_command.rb +4 -10
  18. data/lib/morpheus/cli/library_option_types_command.rb +2 -5
  19. data/lib/morpheus/cli/library_upgrades_command.rb +4 -10
  20. data/lib/morpheus/cli/load_balancers.rb +4 -16
  21. data/lib/morpheus/cli/monitoring_apps_command.rb +5 -14
  22. data/lib/morpheus/cli/monitoring_checks_command.rb +13 -33
  23. data/lib/morpheus/cli/monitoring_contacts_command.rb +10 -11
  24. data/lib/morpheus/cli/monitoring_groups_command.rb +19 -38
  25. data/lib/morpheus/cli/monitoring_incidents_command.rb +37 -66
  26. data/lib/morpheus/cli/network_domains_command.rb +7 -16
  27. data/lib/morpheus/cli/network_groups_command.rb +6 -16
  28. data/lib/morpheus/cli/network_pool_servers_command.rb +6 -16
  29. data/lib/morpheus/cli/network_pools_command.rb +6 -16
  30. data/lib/morpheus/cli/network_proxies_command.rb +6 -16
  31. data/lib/morpheus/cli/network_services_command.rb +4 -11
  32. data/lib/morpheus/cli/networks_command.rb +6 -16
  33. data/lib/morpheus/cli/packages_command.rb +148 -13
  34. data/lib/morpheus/cli/policies_command.rb +6 -16
  35. data/lib/morpheus/cli/power_scheduling_command.rb +6 -24
  36. data/lib/morpheus/cli/recent_activity_command.rb +19 -19
  37. data/lib/morpheus/cli/remote.rb +7 -8
  38. data/lib/morpheus/cli/storage_providers_command.rb +6 -16
  39. data/lib/morpheus/cli/tasks.rb +4 -12
  40. data/lib/morpheus/cli/user_groups_command.rb +7 -25
  41. data/lib/morpheus/cli/user_sources_command.rb +9 -21
  42. data/lib/morpheus/cli/users.rb +6 -17
  43. data/lib/morpheus/cli/version.rb +1 -1
  44. data/lib/morpheus/cli/workflows.rb +4 -12
  45. metadata +4 -2
@@ -64,9 +64,7 @@ class Morpheus::Cli::PoliciesCommand
64
64
  elsif options[:cloud]
65
65
  cloud = find_cloud_by_name_or_id(options[:cloud])
66
66
  end
67
- [:phrase, :offset, :max, :sort, :direction].each do |k|
68
- params[k] = options[k] unless options[k].nil?
69
- end
67
+ params.merge!(parse_list_options(options))
70
68
  if options[:dry_run]
71
69
  if group
72
70
  print_dry_run @group_policies_interface.dry.list(group['id'], params)
@@ -87,14 +85,11 @@ class Morpheus::Cli::PoliciesCommand
87
85
  json_response = @policies_interface.list(params)
88
86
  end
89
87
  policies = json_response["policies"]
90
- if options[:include_fields]
91
- json_response = {"policies" => filter_data(policies, options[:include_fields]) }
92
- end
93
88
  if options[:json]
94
- puts as_json(json_response, options)
89
+ puts as_json(json_response, options, "policies")
95
90
  return 0
96
91
  elsif options[:yaml]
97
- puts as_yaml(json_response, options)
92
+ puts as_yaml(json_response, options, "policies")
98
93
  return 0
99
94
  elsif options[:csv]
100
95
  puts records_as_csv(policies, options)
@@ -111,9 +106,7 @@ class Morpheus::Cli::PoliciesCommand
111
106
  if params[:global]
112
107
  subtitles << "(Global)".strip
113
108
  end
114
- if params[:phrase]
115
- subtitles << "Search: #{params[:phrase]}".strip
116
- end
109
+ subtitles += parse_list_subtitles(options)
117
110
  print_h1 title, subtitles
118
111
  if policies.empty?
119
112
  print cyan,"No policies found.",reset,"\n"
@@ -191,14 +184,11 @@ class Morpheus::Cli::PoliciesCommand
191
184
  json_response = {'policy' => policy} # skip redundant request
192
185
  # json_response = @policies_interface.get(policy['id'])
193
186
  policy = json_response['policy']
194
- if options[:include_fields]
195
- json_response = {'policy' => filter_data(policy, options[:include_fields]) }
196
- end
197
187
  if options[:json]
198
- puts as_json(json_response, options)
188
+ puts as_json(json_response, options, "policy")
199
189
  return 0
200
190
  elsif options[:yaml]
201
- puts as_yaml(json_response, options)
191
+ puts as_yaml(json_response, options, "policy")
202
192
  return 0
203
193
  elsif options[:csv]
204
194
  puts records_as_csv([policy], options)
@@ -36,41 +36,26 @@ class Morpheus::Cli::PowerSchedulingCommand
36
36
  optparse.parse!(args)
37
37
  connect(options)
38
38
  begin
39
- [:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
40
- params[k] = options[k] unless options[k].nil?
41
- end
42
-
39
+ params.merge!(parse_list_options(options))
43
40
  if options[:dry_run]
44
41
  print_dry_run @power_scheduling_interface.dry.list(params)
45
42
  return
46
43
  end
47
-
48
44
  json_response = @power_scheduling_interface.list(params)
49
- if options[:include_fields]
50
- json_response = {"powerScheduleTypes" => filter_data(json_response["powerScheduleTypes"], options[:include_fields]) }
51
- end
52
45
  if options[:json]
53
- puts as_json(json_response, options)
46
+ puts as_json(json_response, options, "powerScheduleTypes")
54
47
  return 0
55
48
  elsif options[:csv]
56
49
  puts records_as_csv(json_response['powerScheduleTypes'], options)
57
50
  return 0
58
51
  elsif options[:yaml]
59
- puts as_yaml(json_response, options)
52
+ puts as_yaml(json_response, options, "powerScheduleTypes")
60
53
  return 0
61
54
  end
62
55
  schedules = json_response['powerScheduleTypes']
63
56
  title = "Morpheus Power Schedules"
64
57
  subtitles = []
65
- # if group
66
- # subtitles << "Group: #{group['name']}".strip
67
- # end
68
- # if cloud
69
- # subtitles << "Cloud: #{cloud['name']}".strip
70
- # end
71
- if params[:phrase]
72
- subtitles << "Search: #{params[:phrase]}".strip
73
- end
58
+ subtitles += parse_list_subtitles(options)
74
59
  print_h1 title, subtitles
75
60
  if schedules.empty?
76
61
  print cyan,"No power schedules found.",reset,"\n"
@@ -129,14 +114,11 @@ class Morpheus::Cli::PowerSchedulingCommand
129
114
  schedule = json_response['powerScheduleType']
130
115
  instances = json_response['instances'] || []
131
116
  servers = json_response['servers'] || []
132
- if options[:include_fields]
133
- json_response = {"powerScheduleType" => filter_data(json_response["powerScheduleType"], options[:include_fields]) }
134
- end
135
117
  if options[:json]
136
- puts as_json(json_response, options)
118
+ puts as_json(json_response, options, "powerScheduleType")
137
119
  return 0
138
120
  elsif options[:yaml]
139
- puts as_yaml(json_response, options)
121
+ puts as_yaml(json_response, options, "powerScheduleType")
140
122
  return 0
141
123
  elsif options[:csv]
142
124
  puts records_as_csv([json_response['schedule']], options)
@@ -44,35 +44,35 @@ class Morpheus::Cli::RecentActivityCommand
44
44
  account = find_account_from_options(options)
45
45
  account_id = account ? account['id'] : nil
46
46
  params = {}
47
- [:phrase, :offset, :max, :sort, :direction, :start, :end].each do |k|
48
- params[k] = options[k] unless options[k].nil?
49
- end
47
+ params.merge!(parse_list_options(options))
50
48
  if options[:dry_run]
51
49
  print_dry_run @dashboard_interface.dry.recent_activity(account_id, params)
52
50
  return
53
51
  end
54
52
  json_response = @dashboard_interface.recent_activity(account_id, params)
53
+
55
54
  if options[:json]
56
- if options[:include_fields]
57
- json_response = {"activity" => filter_data(json_response["activity"], options[:include_fields]) }
58
- end
59
- print JSON.pretty_generate(json_response)
60
- print "\n"
55
+ puts as_json(json_response, options, "activity")
61
56
  return 0
62
- end
63
- if options[:csv]
64
- puts records_as_csv(json_response["activity"], options)
57
+ elsif options[:yaml]
58
+ puts as_yaml(json_response, options, "activity")
65
59
  return 0
66
- end
67
- if options[:yaml]
68
- if options[:include_fields]
69
- json_response = {"activity" => filter_data(json_response["activity"], options[:include_fields]) }
70
- end
71
- puts as_yaml(json_response, options)
60
+ elsif options[:csv]
61
+ # strip date lines
62
+ json_response['activity'] = json_response['activity'].reject {|it| it.keys.size == 1 && it.keys[0] == 'date' }
63
+ puts records_as_csv(json_response['activity'], options)
72
64
  return 0
73
65
  end
74
-
75
- print_h1 "Recent Activity"
66
+ title = "Recent Activity"
67
+ subtitles = []
68
+ subtitles += parse_list_subtitles(options)
69
+ if options[:start]
70
+ subtitles << "Start: #{options[:start]}"
71
+ end
72
+ if options[:end]
73
+ subtitles << "End: #{options[:end]}"
74
+ end
75
+ print_h1 title, subtitles
76
76
  print cyan
77
77
  items = json_response["activity"]
78
78
  if items.empty?
@@ -35,7 +35,7 @@ class Morpheus::Cli::Remote
35
35
  opts.on("-a",'--all', "Show all the appliance activity details") do
36
36
  show_all_activity = true
37
37
  end
38
- build_common_options(opts, options, [:json, :csv, :fields])
38
+ build_common_options(opts, options, [:json, :yaml, :csv, :fields])
39
39
  opts.footer = <<-EOT
40
40
  This outputs a list of the configured remote appliances. It also indicates
41
41
  the current appliance. The current appliance is where morpheus will send
@@ -52,15 +52,14 @@ EOT
52
52
  # raise_command_error "You have no appliances configured. See the `remote add` command."
53
53
  # end
54
54
 
55
+ json_response = {"appliances" => appliances}
55
56
  if options[:json]
56
- json_response = {"appliances" => appliances} # mock payload
57
- if options[:include_fields]
58
- json_response = {"appliances" => filter_data(appliances, options[:include_fields]) }
59
- end
60
- puts as_json(json_response, options)
57
+ puts as_json(json_response, options, "appliances")
61
58
  return 0
62
- end
63
- if options[:csv]
59
+ elsif options[:yaml]
60
+ puts as_yaml(json_response, options, "appliances")
61
+ return 0
62
+ elsif options[:csv]
64
63
  puts records_as_csv(appliances, options)
65
64
  return 0
66
65
  end
@@ -41,23 +41,18 @@ class Morpheus::Cli::StorageProvidersCommand
41
41
  optparse.parse!(args)
42
42
  connect(options)
43
43
  begin
44
- [:phrase, :offset, :max, :sort, :direction].each do |k|
45
- params[k] = options[k] unless options[k].nil?
46
- end
44
+ params.merge!(parse_list_options(options))
47
45
  if options[:dry_run]
48
46
  print_dry_run @storage_providers_interface.dry.list(params)
49
47
  return
50
48
  end
51
49
  json_response = @storage_providers_interface.list(params)
52
50
  storage_providers = json_response["storageProviders"]
53
- if options[:include_fields]
54
- json_response = {"storageProviders" => filter_data(storage_providers, options[:include_fields]) }
55
- end
56
51
  if options[:json]
57
- puts as_json(json_response, options)
52
+ puts as_json(json_response, options, "storageProviders")
58
53
  return 0
59
54
  elsif options[:yaml]
60
- puts as_yaml(json_response, options)
55
+ puts as_yaml(json_response, options, "storageProviders")
61
56
  return 0
62
57
  elsif options[:csv]
63
58
  puts records_as_csv(storage_providers, options)
@@ -65,9 +60,7 @@ class Morpheus::Cli::StorageProvidersCommand
65
60
  end
66
61
  title = "Morpheus Storage Providers"
67
62
  subtitles = []
68
- if params[:phrase]
69
- subtitles << "Search: #{params[:phrase]}".strip
70
- end
63
+ subtitles += parse_list_subtitles(options)
71
64
  print_h1 title, subtitles
72
65
  if storage_providers.empty?
73
66
  print cyan,"No storage providers found.",reset,"\n"
@@ -131,14 +124,11 @@ class Morpheus::Cli::StorageProvidersCommand
131
124
  json_response = {'storageProvider' => storage_provider} # skip redundant request
132
125
  # json_response = @storage_providers_interface.get(storage_provider['id'])
133
126
  storage_provider = json_response['storageProvider']
134
- if options[:include_fields]
135
- json_response = {'storageProvider' => filter_data(storage_provider, options[:include_fields]) }
136
- end
137
127
  if options[:json]
138
- puts as_json(json_response, options)
128
+ puts as_json(json_response, options, "storageProvider")
139
129
  return 0
140
130
  elsif options[:yaml]
141
- puts as_yaml(json_response, options)
131
+ puts as_yaml(json_response, options, "storageProvider")
142
132
  return 0
143
133
  elsif options[:csv]
144
134
  puts records_as_csv([storage_provider], options)
@@ -41,19 +41,13 @@ class Morpheus::Cli::Tasks
41
41
  json_response = @tasks_interface.get(params)
42
42
  # print result and return output
43
43
  if options[:json]
44
- if options[:include_fields]
45
- json_response = {"tasks" => filter_data(json_response["tasks"], options[:include_fields]) }
46
- end
47
- puts as_json(json_response, options)
44
+ puts as_json(json_response, options, "tasks")
48
45
  return 0
49
46
  elsif options[:csv]
50
47
  puts records_as_csv(json_response['tasks'], options)
51
48
  return 0
52
49
  elsif options[:yaml]
53
- if options[:include_fields]
54
- json_response = {"tasks" => filter_data(json_response["tasks"], options[:include_fields]) }
55
- end
56
- puts as_yaml(json_response, options)
50
+ puts as_yaml(json_response, options, "tasks")
57
51
  return 0
58
52
  else
59
53
  title = "Morpheus Tasks"
@@ -113,12 +107,10 @@ class Morpheus::Cli::Tasks
113
107
  json_response = @tasks_interface.get(task['id'])
114
108
  end
115
109
  if options[:json]
116
- json_response = {"task" => filter_data(json_response["task"], options[:include_fields]) } if options[:include_fields]
117
- puts as_json(json_response, options)
110
+ puts as_json(json_response, options, "task")
118
111
  return 0
119
112
  elsif options[:yaml]
120
- json_response = {"task" => filter_data(json_response["task"], options[:include_fields]) } if options[:include_fields]
121
- puts as_yaml(json_response, options)
113
+ puts as_yaml(json_response, options, "task")
122
114
  return 0
123
115
  elsif options[:csv]
124
116
  puts records_as_csv([json_response['task']], options)
@@ -31,41 +31,26 @@ class Morpheus::Cli::UserGroupsCommand
31
31
  optparse.parse!(args)
32
32
  connect(options)
33
33
  begin
34
- [:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
35
- params[k] = options[k] unless options[k].nil?
36
- end
37
-
34
+ params.merge!(parse_list_options(options))
38
35
  if options[:dry_run]
39
36
  print_dry_run @user_groups_interface.dry.list(nil, params)
40
37
  return
41
38
  end
42
-
43
39
  json_response = @user_groups_interface.list(nil, params)
44
- if options[:include_fields]
45
- json_response = {"userGroups" => filter_data(json_response["userGroups"], options[:include_fields]) }
46
- end
47
40
  if options[:json]
48
- puts as_json(json_response, options)
41
+ puts as_json(json_response, options, "userGroups")
49
42
  return 0
50
43
  elsif options[:csv]
51
- puts records_as_csv(json_response['userGroups'], options)
44
+ puts records_as_csv(json_response["userGroups"], options)
52
45
  return 0
53
46
  elsif options[:yaml]
54
- puts as_yaml(json_response, options)
47
+ puts as_yaml(json_response, options, "userGroups")
55
48
  return 0
56
49
  end
57
50
  user_groups = json_response['userGroups']
58
51
  title = "Morpheus User Groups"
59
52
  subtitles = []
60
- # if group
61
- # subtitles << "Group: #{group['name']}".strip
62
- # end
63
- # if cloud
64
- # subtitles << "Cloud: #{cloud['name']}".strip
65
- # end
66
- if params[:phrase]
67
- subtitles << "Search: #{params[:phrase]}".strip
68
- end
53
+ subtitles += parse_list_subtitles(options)
69
54
  print_h1 title, subtitles
70
55
  if user_groups.empty?
71
56
  print cyan,"No user groups found.",reset,"\n"
@@ -113,14 +98,11 @@ class Morpheus::Cli::UserGroupsCommand
113
98
  json_response = @user_groups_interface.get(nil, user_group['id'])
114
99
  user_group = json_response['userGroup']
115
100
  users = user_group['users'] || []
116
- if options[:include_fields]
117
- json_response = {"userGroup" => filter_data(json_response["userGroup"], options[:include_fields]) }
118
- end
119
101
  if options[:json]
120
- puts as_json(json_response, options)
102
+ puts as_json(json_response, options, "userGroup")
121
103
  return 0
122
104
  elsif options[:yaml]
123
- puts as_yaml(json_response, options)
105
+ puts as_yaml(json_response, options, "userGroup")
124
106
  return 0
125
107
  elsif options[:csv]
126
108
  puts records_as_csv([json_response['userGroup']], options)
@@ -70,17 +70,14 @@ class Morpheus::Cli::UserSourcesCommand
70
70
  end
71
71
 
72
72
  json_response = @user_sources_interface.list(account_id, params)
73
- if options[:include_fields]
74
- json_response = {"userSources" => filter_data(json_response["userSources"], options[:include_fields]) }
75
- end
76
73
  if options[:json]
77
- puts as_json(json_response, options)
74
+ puts as_json(json_response, options, "userSources")
78
75
  return 0
79
76
  elsif options[:csv]
80
77
  puts records_as_csv(json_response['userSources'], options)
81
78
  return 0
82
79
  elsif options[:yaml]
83
- puts as_yaml(json_response, options)
80
+ puts as_yaml(json_response, options, "userSources")
84
81
  return 0
85
82
  end
86
83
  user_sources = json_response['userSources']
@@ -155,14 +152,11 @@ class Morpheus::Cli::UserSourcesCommand
155
152
  end
156
153
 
157
154
  #user_source = json_response['userSource']
158
- if options[:include_fields]
159
- json_response = {"userSource" => filter_data(json_response["userSource"], options[:include_fields]) }
160
- end
161
155
  if options[:json]
162
- puts as_json(json_response, options)
156
+ puts as_json(json_response, options, "userSource")
163
157
  return 0
164
158
  elsif options[:yaml]
165
- puts as_yaml(json_response, options)
159
+ puts as_yaml(json_response, options, "userSource")
166
160
  return 0
167
161
  elsif options[:csv]
168
162
  puts records_as_csv([json_response['userSource']], options)
@@ -695,17 +689,14 @@ class Morpheus::Cli::UserSourcesCommand
695
689
  end
696
690
 
697
691
  json_response = @user_sources_interface.list_types(params)
698
- if options[:include_fields]
699
- json_response = {"userSourceTypes" => filter_data(json_response["userSourceTypes"], options[:include_fields]) }
700
- end
701
692
  if options[:json]
702
- puts as_json(json_response, options)
693
+ puts as_json(json_response, options, "userSourceTypes")
703
694
  return 0
704
695
  elsif options[:csv]
705
696
  puts records_as_csv(json_response['userSourceTypes'], options)
706
697
  return 0
707
698
  elsif options[:yaml]
708
- puts as_yaml(json_response, options)
699
+ puts as_yaml(json_response, options, "userSourceTypes")
709
700
  return 0
710
701
  end
711
702
  user_source_types = json_response['userSourceTypes']
@@ -764,15 +755,12 @@ class Morpheus::Cli::UserSourcesCommand
764
755
  return
765
756
  end
766
757
  json_response = @user_sources_interface.get_type(user_source_type_id, params)
767
- user_source_type = json_response['userSourceType']
768
- if options[:include_fields]
769
- json_response = {"userSource" => filter_data(user_source_type, options[:include_fields]) }
770
- end
758
+ user_source_type = json_response["userSourceType"]
771
759
  if options[:json]
772
- puts as_json(json_response, options)
760
+ puts as_json(json_response, options, "userSourceType")
773
761
  return 0
774
762
  elsif options[:yaml]
775
- puts as_yaml(json_response, options)
763
+ puts as_yaml(json_response, options, "userSourceType")
776
764
  return 0
777
765
  elsif options[:csv]
778
766
  puts records_as_csv([user_source_type], options)
@@ -46,23 +46,18 @@ class Morpheus::Cli::Users
46
46
  account_id = account ? account['id'] : nil
47
47
 
48
48
  params = {}
49
- [:phrase, :offset, :max, :sort, :direction].each do |k|
50
- params[k] = options[k] unless options[k].nil?
51
- end
49
+ params.merge!(parse_list_options(options))
52
50
  if options[:dry_run]
53
51
  print_dry_run @users_interface.dry.list(account_id, params)
54
52
  return
55
53
  end
56
54
  json_response = @users_interface.list(account_id, params)
57
55
  users = json_response['users']
58
- if options[:include_fields]
59
- json_response = {"users" => filter_data(users, options[:include_fields]) }
60
- end
61
56
  if options[:json]
62
- puts as_json(json_response, options)
57
+ puts as_json(json_response, options, "users")
63
58
  return 0
64
59
  elsif options[:yaml]
65
- puts as_yaml(json_response, options)
60
+ puts as_yaml(json_response, options, "users")
66
61
  return 0
67
62
  elsif options[:csv]
68
63
  puts records_as_csv(users, options)
@@ -73,9 +68,7 @@ class Morpheus::Cli::Users
73
68
  if account
74
69
  subtitles << "Account: #{account['name']}".strip
75
70
  end
76
- if params[:phrase]
77
- subtitles << "Search: #{params[:phrase]}".strip
78
- end
71
+ subtitles += parse_list_subtitles(options)
79
72
  print_h1 title, subtitles
80
73
  if users.empty?
81
74
  puts yellow,"No users found.",reset
@@ -177,16 +170,12 @@ class Morpheus::Cli::Users
177
170
 
178
171
  json_response = {'user' => user}
179
172
  # json_response['user']['featurePermissions'] = user_feature_permissions if options[:include_feature_access]
180
-
181
- if options[:include_fields]
182
- json_response = {'user' => filter_data(user, options[:include_fields]) }
183
- end
184
173
  if options[:json]
185
- puts as_json(json_response, options)
174
+ puts as_json(json_response, options, "user")
186
175
  puts as_json(@users_interface.feature_permissions(account_id, user['id']), options) if options[:include_feature_access]
187
176
  return 0
188
177
  elsif options[:yaml]
189
- puts as_yaml(json_response, options)
178
+ puts as_yaml(json_response, options, "user")
190
179
  puts as_yaml(@users_interface.feature_permissions(account_id, user['id']), options) if options[:include_feature_access]
191
180
  return 0
192
181
  elsif options[:csv]