morpheus-cli 2.10.0 → 2.10.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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/morpheus +27 -32
  3. data/lib/morpheus/api/accounts_interface.rb +36 -47
  4. data/lib/morpheus/api/api_client.rb +141 -110
  5. data/lib/morpheus/api/app_templates_interface.rb +56 -72
  6. data/lib/morpheus/api/apps_interface.rb +111 -132
  7. data/lib/morpheus/api/auth_interface.rb +30 -0
  8. data/lib/morpheus/api/clouds_interface.rb +71 -76
  9. data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
  10. data/lib/morpheus/api/dashboard_interface.rb +10 -17
  11. data/lib/morpheus/api/deploy_interface.rb +60 -72
  12. data/lib/morpheus/api/deployments_interface.rb +53 -71
  13. data/lib/morpheus/api/groups_interface.rb +55 -45
  14. data/lib/morpheus/api/instance_types_interface.rb +19 -23
  15. data/lib/morpheus/api/instances_interface.rb +179 -177
  16. data/lib/morpheus/api/key_pairs_interface.rb +11 -17
  17. data/lib/morpheus/api/license_interface.rb +18 -23
  18. data/lib/morpheus/api/load_balancers_interface.rb +54 -69
  19. data/lib/morpheus/api/logs_interface.rb +25 -29
  20. data/lib/morpheus/api/options_interface.rb +13 -17
  21. data/lib/morpheus/api/provision_types_interface.rb +19 -22
  22. data/lib/morpheus/api/roles_interface.rb +75 -94
  23. data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
  24. data/lib/morpheus/api/security_groups_interface.rb +39 -51
  25. data/lib/morpheus/api/servers_interface.rb +113 -115
  26. data/lib/morpheus/api/setup_interface.rb +31 -0
  27. data/lib/morpheus/api/task_sets_interface.rb +36 -38
  28. data/lib/morpheus/api/tasks_interface.rb +56 -69
  29. data/lib/morpheus/api/users_interface.rb +67 -76
  30. data/lib/morpheus/api/virtual_images_interface.rb +61 -61
  31. data/lib/morpheus/api/whoami_interface.rb +12 -15
  32. data/lib/morpheus/cli.rb +71 -60
  33. data/lib/morpheus/cli/accounts.rb +254 -315
  34. data/lib/morpheus/cli/alias_command.rb +219 -0
  35. data/lib/morpheus/cli/app_templates.rb +264 -272
  36. data/lib/morpheus/cli/apps.rb +608 -671
  37. data/lib/morpheus/cli/cli_command.rb +259 -21
  38. data/lib/morpheus/cli/cli_registry.rb +99 -14
  39. data/lib/morpheus/cli/clouds.rb +599 -372
  40. data/lib/morpheus/cli/config_file.rb +126 -0
  41. data/lib/morpheus/cli/credentials.rb +141 -117
  42. data/lib/morpheus/cli/dashboard_command.rb +48 -56
  43. data/lib/morpheus/cli/deployments.rb +254 -268
  44. data/lib/morpheus/cli/deploys.rb +150 -142
  45. data/lib/morpheus/cli/error_handler.rb +38 -0
  46. data/lib/morpheus/cli/groups.rb +551 -179
  47. data/lib/morpheus/cli/hosts.rb +862 -617
  48. data/lib/morpheus/cli/instance_types.rb +103 -95
  49. data/lib/morpheus/cli/instances.rb +1335 -1009
  50. data/lib/morpheus/cli/key_pairs.rb +82 -90
  51. data/lib/morpheus/cli/library.rb +498 -499
  52. data/lib/morpheus/cli/license.rb +83 -101
  53. data/lib/morpheus/cli/load_balancers.rb +314 -300
  54. data/lib/morpheus/cli/login.rb +66 -44
  55. data/lib/morpheus/cli/logout.rb +47 -46
  56. data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
  57. data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
  58. data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
  59. data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
  60. data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
  61. data/lib/morpheus/cli/option_parser.rb +35 -0
  62. data/lib/morpheus/cli/option_types.rb +232 -192
  63. data/lib/morpheus/cli/recent_activity_command.rb +61 -65
  64. data/lib/morpheus/cli/remote.rb +446 -199
  65. data/lib/morpheus/cli/roles.rb +884 -906
  66. data/lib/morpheus/cli/security_group_rules.rb +213 -203
  67. data/lib/morpheus/cli/security_groups.rb +237 -192
  68. data/lib/morpheus/cli/shell.rb +338 -231
  69. data/lib/morpheus/cli/tasks.rb +326 -308
  70. data/lib/morpheus/cli/users.rb +457 -462
  71. data/lib/morpheus/cli/version.rb +1 -1
  72. data/lib/morpheus/cli/version_command.rb +16 -18
  73. data/lib/morpheus/cli/virtual_images.rb +526 -345
  74. data/lib/morpheus/cli/whoami.rb +125 -111
  75. data/lib/morpheus/cli/workflows.rb +338 -185
  76. data/lib/morpheus/formatters.rb +8 -1
  77. data/lib/morpheus/logging.rb +1 -1
  78. data/lib/morpheus/rest_client.rb +17 -8
  79. metadata +9 -3
  80. data/lib/morpheus/api/custom_instance_types.rb +0 -55
@@ -9,49 +9,71 @@ class Morpheus::Cli::Login
9
9
  include Morpheus::Cli::CliCommand
10
10
  # include Morpheus::Cli::WhoamiHelper
11
11
  # include Morpheus::Cli::AccountsHelper
12
-
13
- def initialize()
14
- @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
15
- end
16
-
17
- def connect(opts)
18
- #@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
19
- #@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
20
- end
21
-
22
- def usage
23
- "Usage: morpheus login"
24
- end
25
-
26
- def handle(args)
27
- login(args)
28
- end
29
-
30
- # def login
31
- # Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).login()
32
- # end
33
-
34
- def login(args)
35
- options = {}
36
- optparse = OptionParser.new do|opts|
37
- opts.banner = usage
38
- build_common_options(opts, options, [:json]) # todo: support :remote too perhaps
39
- end
40
- optparse.parse(args)
41
-
42
- connect(options)
43
-
44
- begin
45
-
46
- Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).login(options)
47
-
48
- rescue RestClient::Exception => e
49
- print_rest_exception(e, options)
50
- exit 1
51
- end
52
-
53
- end
54
-
55
-
12
+ def initialize()
13
+
14
+ end
15
+
16
+ def connect(opts)
17
+ #@api_client = establish_remote_appliance_connection(opts)
18
+ end
19
+
20
+ def usage
21
+ "Usage: morpheus login"
22
+ end
23
+
24
+ def handle(args)
25
+ login(args)
26
+ end
27
+
28
+ def login(args)
29
+ options = {}
30
+ username, password = nil, nil
31
+ optparse = OptionParser.new do|opts|
32
+ opts.banner = usage
33
+ opts.on( '-u', '--username USERNAME', "Username" ) do |val|
34
+ username = val
35
+ end
36
+ opts.on( '-p', '--password PASSWORD', "Password" ) do |val|
37
+ password = val
38
+ end
39
+ build_common_options(opts, options, [:json, :remote, :quiet])
40
+ end
41
+ optparse.parse!(args)
42
+
43
+ # connect(options)
44
+ if options[:remote]
45
+ appliance = Morpheus::Cli::Remote.appliances[options[:remote].to_sym]
46
+ if appliance
47
+ @appliance_name, @appliance_url = options[:remote].to_sym, appliance[:host]
48
+ else
49
+ @appliance_name, @appliance_url = nil, nil
50
+ end
51
+ else
52
+ @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
53
+ end
54
+
55
+ begin
56
+ if !@appliance_name
57
+ print yellow,"Please specify a remote appliance with -r or see the command `remote use`#{reset}\n"
58
+ return false
59
+ end
60
+ if options[:quiet]
61
+ if username.empty? || password.empty?
62
+ print yellow,"You have not specified username and password\n"
63
+ return false
64
+ end
65
+ end
66
+ options[:remote_username] = username if username
67
+ options[:remote_password] = password if password
68
+ #options[:remote_url] = true # will skip credentials save
69
+ Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).login(options)
70
+
71
+ rescue RestClient::Exception => e
72
+ print_rest_exception(e, options)
73
+ exit 1
74
+ end
75
+
76
+ end
77
+
56
78
 
57
79
  end
@@ -11,51 +11,52 @@ class Morpheus::Cli::Logout
11
11
  include Morpheus::Cli::CliCommand
12
12
  # include Morpheus::Cli::WhoamiHelper
13
13
  # include Morpheus::Cli::AccountsHelper
14
-
15
- def initialize()
16
- @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
17
- end
18
-
19
- def connect(opts)
20
- #@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
21
- #@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
22
- end
23
-
24
- def usage
25
- "Usage: morpheus login"
26
- end
27
-
28
- def handle(args)
29
- logout(args)
30
- end
31
-
32
- def logout(args)
33
- options = {}
34
- optparse = OptionParser.new do|opts|
35
- opts.banner = usage
36
- build_common_options(opts, options, []) # todo: support :remote too perhaps
37
- end
38
- optparse.parse(args)
39
-
40
- connect(options)
41
-
42
- begin
43
-
44
- creds = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials()
45
- if !creds
46
- print yellow,"\nYou are not logged in to #{@appliance_name} - #{@appliance_url}.\n\n",reset
47
- # exit 0
48
- else
49
- Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).logout()
50
- end
51
-
52
- rescue RestClient::Exception => e
53
- print_rest_exception(e, options)
54
- exit 1
55
- end
56
-
57
- end
58
-
59
-
14
+ def initialize()
15
+ @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
16
+ end
17
+
18
+ def connect(opts)
19
+ #@api_client = establish_remote_appliance_connection(opts)
20
+ #@access_token = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials(options)
21
+ end
22
+
23
+ def usage
24
+ "Usage: morpheus logout"
25
+ end
26
+
27
+ def handle(args)
28
+ logout(args)
29
+ end
30
+
31
+ def logout(args)
32
+ options = {}
33
+ optparse = OptionParser.new do|opts|
34
+ opts.banner = usage
35
+ build_common_options(opts, options, [:remote]) # todo: support :remote too perhaps
36
+ end
37
+ optparse.parse!(args)
38
+ connect(options)
39
+
40
+ begin
41
+ if !@appliance_name
42
+ print yellow,"Please specify a Morpheus Appliance to logout of with -r or see the command `remote use`#{reset}\n"
43
+ return
44
+ end
45
+ creds = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials()
46
+ if !creds
47
+ print yellow,"You are not currently logged in to #{display_appliance(@appliance_name, @appliance_url)}\n",reset
48
+ return 0
49
+ else
50
+ Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).logout()
51
+ print cyan,"Goodbye\n",reset
52
+ end
53
+
54
+ rescue RestClient::Exception => e
55
+ print_rest_exception(e, options)
56
+ return 1
57
+ end
58
+
59
+ end
60
+
60
61
 
61
62
  end
@@ -1,7 +1,7 @@
1
1
  require 'table_print'
2
2
  require 'morpheus/cli/mixins/print_helper'
3
3
 
4
- # Mixin for Morpheus::Cli command classes
4
+ # Mixin for Morpheus::Cli command classes
5
5
  # Provides common methods for fetching and printing accounts, roles, and users.
6
6
  # The including class must establish @accounts_interface, @roles_interface, @users_interface
7
7
  module Morpheus::Cli::AccountsHelper
@@ -10,10 +10,35 @@ module Morpheus::Cli::AccountsHelper
10
10
  klass.send :include, Morpheus::Cli::PrintHelper
11
11
  end
12
12
 
13
- def find_account_by_id(id)
13
+ def accounts_interface
14
+ # @api_client.accounts
14
15
  raise "#{self.class} has not defined @accounts_interface" if @accounts_interface.nil?
16
+ @accounts_interface
17
+ end
18
+
19
+ def users_interface
20
+ # @api_client.users
21
+ raise "#{self.class} has not defined @users_interface" if @users_interface.nil?
22
+ @users_interface
23
+ end
24
+
25
+ def roles_interface
26
+ # @api_client.roles
27
+ raise "#{self.class} has not defined @roles_interface" if @roles_interface.nil?
28
+ @roles_interface
29
+ end
30
+
31
+ def find_account_by_name_or_id(val)
32
+ if val.to_s =~ /\A\d{1,}\Z/
33
+ return find_account_by_id(val)
34
+ else
35
+ return find_account_by_name(val)
36
+ end
37
+ end
38
+
39
+ def find_account_by_id(id)
15
40
  begin
16
- json_response = @accounts_interface.get(id.to_i)
41
+ json_response = accounts_interface.get(id.to_i)
17
42
  return json_response['account']
18
43
  rescue RestClient::Exception => e
19
44
  if e.response && e.response.code == 404
@@ -25,8 +50,7 @@ module Morpheus::Cli::AccountsHelper
25
50
  end
26
51
 
27
52
  def find_account_by_name(name)
28
- raise "#{self.class} has not defined @accounts_interface" if @accounts_interface.nil?
29
- accounts = @accounts_interface.list({name: name.to_s})['accounts']
53
+ accounts = accounts_interface.list({name: name.to_s})['accounts']
30
54
  if accounts.empty?
31
55
  print_red_alert "Account not found by name #{name}"
32
56
  return nil
@@ -43,7 +67,10 @@ module Morpheus::Cli::AccountsHelper
43
67
 
44
68
  def find_account_from_options(options)
45
69
  account = nil
46
- if options[:account_name]
70
+ if options[:account]
71
+ account = find_account_by_name_or_id(options[:account])
72
+ exit 1 if account.nil?
73
+ elsif options[:account_name]
47
74
  account = find_account_by_name(options[:account_name])
48
75
  exit 1 if account.nil?
49
76
  elsif options[:account_id]
@@ -55,10 +82,17 @@ module Morpheus::Cli::AccountsHelper
55
82
  return account
56
83
  end
57
84
 
85
+ def find_role_by_name_or_id(account_id, val)
86
+ if val.to_s =~ /\A\d{1,}\Z/
87
+ return find_role_by_id(account_id, val)
88
+ else
89
+ return find_role_by_name(account_id, val)
90
+ end
91
+ end
92
+
58
93
  def find_role_by_id(account_id, id)
59
- raise "#{self.class} has not defined @roles_interface" if @roles_interface.nil?
60
94
  begin
61
- json_response = @roles_interface.get(account_id, id.to_i)
95
+ json_response = roles_interface.get(account_id, id.to_i)
62
96
  return json_response['role']
63
97
  rescue RestClient::Exception => e
64
98
  if e.response && e.response.code == 404
@@ -70,8 +104,7 @@ module Morpheus::Cli::AccountsHelper
70
104
  end
71
105
 
72
106
  def find_role_by_name(account_id, name)
73
- raise "#{self.class} has not defined @roles_interface" if @roles_interface.nil?
74
- roles = @roles_interface.list(account_id, {authority: name.to_s})['roles']
107
+ roles = roles_interface.list(account_id, {authority: name.to_s})['roles']
75
108
  if roles.empty?
76
109
  print_red_alert "Role not found by name #{name}"
77
110
  return nil
@@ -87,10 +120,17 @@ module Morpheus::Cli::AccountsHelper
87
120
 
88
121
  alias_method :find_role_by_authority, :find_role_by_name
89
122
 
123
+ def find_user_by_username_or_id(account_id, val)
124
+ if val.to_s =~ /\A\d{1,}\Z/
125
+ return find_user_by_id(account_id, val)
126
+ else
127
+ return find_user_by_username(account_id, val)
128
+ end
129
+ end
130
+
90
131
  def find_user_by_id(account_id, id)
91
- raise "#{self.class} has not defined @users_interface" if @users_interface.nil?
92
132
  begin
93
- json_response = @users_interface.get(account_id, id.to_i)
133
+ json_response = users_interface.get(account_id, id.to_i)
94
134
  return json_response['user']
95
135
  rescue RestClient::Exception => e
96
136
  if e.response && e.response.code == 404
@@ -102,8 +142,7 @@ module Morpheus::Cli::AccountsHelper
102
142
  end
103
143
 
104
144
  def find_user_by_username(account_id, username)
105
- raise "#{self.class} has not defined @users_interface" if @users_interface.nil?
106
- users = @users_interface.list(account_id, {username: username.to_s})['users']
145
+ users = users_interface.list(account_id, {username: username.to_s})['users']
107
146
  if users.empty?
108
147
  print_red_alert "User not found by username #{username}"
109
148
  return nil
@@ -127,21 +166,20 @@ module Morpheus::Cli::AccountsHelper
127
166
  status_state = "#{red}INACTIVE#{table_color}"
128
167
  end
129
168
  {
130
- id: account['id'],
131
- name: account['name'],
132
- description: account['description'],
133
- role: account['role'] ? account['role']['authority'] : nil,
169
+ id: account['id'],
170
+ name: account['name'],
171
+ description: account['description'],
172
+ role: account['role'] ? account['role']['authority'] : nil,
134
173
  status: status_state,
135
- dateCreated: format_local_dt(account['dateCreated'])
174
+ dateCreated: format_local_dt(account['dateCreated'])
136
175
  }
137
176
  end
138
-
139
177
  print table_color
140
178
  tp rows, [
141
- :id,
142
- :name,
143
- :description,
144
- :role,
179
+ :id,
180
+ :name,
181
+ :description,
182
+ :role,
145
183
  {:dateCreated => {:display_name => "Date Created"} },
146
184
  :status
147
185
  ]
@@ -178,21 +216,21 @@ module Morpheus::Cli::AccountsHelper
178
216
  # ]
179
217
  rows = roles.collect do |role|
180
218
  {
181
- id: role['id'],
182
- name: role['authority'],
183
- description: role['description'],
219
+ id: role['id'],
220
+ name: role['authority'],
221
+ description: role['description'],
184
222
  scope: role['scope'],
185
223
  multitenant: role['multitenant'] ? 'Yes' : 'No',
186
224
  type: format_role_type(role),
187
225
  owner: role['owner'] ? role['owner']['name'] : "System",
188
- dateCreated: format_local_dt(role['dateCreated'])
226
+ dateCreated: format_local_dt(role['dateCreated'])
189
227
  }
190
228
  end
191
229
  print table_color
192
230
  tp rows, [
193
- :id,
194
- :name,
195
- :description,
231
+ :id,
232
+ :name,
233
+ :description,
196
234
  # opts[:is_master_account] ? :scope : nil,
197
235
  opts[:is_master_account] ? :type : nil,
198
236
  opts[:is_master_account] ? :multitenant : nil,
@@ -0,0 +1,106 @@
1
+ require 'morpheus/cli/mixins/print_helper'
2
+ require 'morpheus/cli/option_types'
3
+ require 'morpheus/rest_client'
4
+ # Mixin for Morpheus::Cli command classes
5
+ # Provides common methods for infrastructure management
6
+ module Morpheus::Cli::InfrastructureHelper
7
+
8
+ def self.included(klass)
9
+ klass.send :include, Morpheus::Cli::PrintHelper
10
+ end
11
+
12
+ def groups_interface
13
+ # @api_client.groups
14
+ raise "#{self.class} has not defined @groups_interface" if @groups_interface.nil?
15
+ @groups_interface
16
+ end
17
+
18
+ def clouds_interface
19
+ # @api_client.clouds
20
+ raise "#{self.class} has not defined @clouds_interface" if @clouds_interface.nil?
21
+ @clouds_interface
22
+ end
23
+
24
+ def find_group_by_name_or_id(val)
25
+ if val.to_s =~ /\A\d{1,}\Z/
26
+ return find_group_by_id(val)
27
+ else
28
+ return find_group_by_name(val)
29
+ end
30
+ end
31
+
32
+ def find_group_by_id(id)
33
+ begin
34
+ json_response = groups_interface.get(id.to_i)
35
+ return json_response['group']
36
+ rescue RestClient::Exception => e
37
+ if e.response && e.response.code == 404
38
+ print_red_alert "Group not found by id #{id}"
39
+ exit 1
40
+ else
41
+ raise e
42
+ end
43
+ end
44
+ end
45
+
46
+ def find_group_by_name(name)
47
+ json_results = groups_interface.get({name: name})
48
+ if json_results['groups'].empty?
49
+ print_red_alert "Group not found by name #{name}"
50
+ exit 1
51
+ end
52
+ group = json_results['groups'][0]
53
+ return group
54
+ end
55
+
56
+ def find_cloud_by_name_or_id(val)
57
+ if val.to_s =~ /\A\d{1,}\Z/
58
+ return find_cloud_by_id(val)
59
+ else
60
+ return find_cloud_by_name(val)
61
+ end
62
+ end
63
+
64
+ def find_cloud_by_id(id)
65
+ json_results = clouds_interface.get(id.to_i)
66
+ if json_results['zone'].empty?
67
+ print_red_alert "Cloud not found by id #{id}"
68
+ exit 1
69
+ end
70
+ cloud = json_results['zone']
71
+ return cloud
72
+ end
73
+
74
+ def find_cloud_by_name(name)
75
+ json_results = clouds_interface.get({name: name})
76
+ if json_results['zones'].empty?
77
+ print_red_alert "Cloud not found by name #{name}"
78
+ exit 1
79
+ end
80
+ cloud = json_results['zones'][0]
81
+ return cloud
82
+ end
83
+
84
+ def get_available_cloud_types(refresh=false)
85
+ if !@available_cloud_types || refresh
86
+ @available_cloud_types = clouds_interface.cloud_types['zoneTypes']
87
+ end
88
+ return @available_cloud_types
89
+ end
90
+
91
+ def cloud_type_for_name_or_id(val)
92
+ if val.to_s =~ /\A\d{1,}\Z/
93
+ return cloud_type_for_id(val)
94
+ else
95
+ return cloud_type_for_name(val)
96
+ end
97
+ end
98
+ def cloud_type_for_id(id)
99
+ return get_available_cloud_types().find { |z| z['id'].to_i == id.to_i}
100
+ end
101
+
102
+ def cloud_type_for_name(name)
103
+ return get_available_cloud_types().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
104
+ end
105
+
106
+ end