morpheus-cli 0.1.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/morpheus/api/accounts_interface.rb +55 -0
- data/lib/morpheus/api/api_client.rb +48 -3
- data/lib/morpheus/api/apps_interface.rb +13 -13
- data/lib/morpheus/api/{zones_interface.rb → clouds_interface.rb} +10 -10
- data/lib/morpheus/api/deploy_interface.rb +4 -4
- data/lib/morpheus/api/groups_interface.rb +3 -3
- data/lib/morpheus/api/instance_types_interface.rb +2 -2
- data/lib/morpheus/api/instances_interface.rb +35 -19
- data/lib/morpheus/api/key_pairs_interface.rb +60 -0
- data/lib/morpheus/api/license_interface.rb +29 -0
- data/lib/morpheus/api/load_balancers_interface.rb +72 -0
- data/lib/morpheus/api/logs_interface.rb +37 -0
- data/lib/morpheus/api/options_interface.rb +20 -0
- data/lib/morpheus/api/provision_types_interface.rb +27 -0
- data/lib/morpheus/api/roles_interface.rb +73 -0
- data/lib/morpheus/api/security_group_rules_interface.rb +3 -3
- data/lib/morpheus/api/security_groups_interface.rb +5 -5
- data/lib/morpheus/api/servers_interface.rb +67 -3
- data/lib/morpheus/api/task_sets_interface.rb +46 -0
- data/lib/morpheus/api/tasks_interface.rb +72 -0
- data/lib/morpheus/api/users_interface.rb +72 -0
- data/lib/morpheus/cli.rb +27 -4
- data/lib/morpheus/cli/accounts.rb +306 -0
- data/lib/morpheus/cli/apps.rb +58 -1
- data/lib/morpheus/cli/cli_command.rb +87 -0
- data/lib/morpheus/cli/cli_registry.rb +6 -1
- data/lib/morpheus/cli/{zones.rb → clouds.rb} +99 -70
- data/lib/morpheus/cli/credentials.rb +23 -11
- data/lib/morpheus/cli/error_handler.rb +31 -11
- data/lib/morpheus/cli/groups.rb +1 -0
- data/lib/morpheus/cli/hosts.rb +567 -0
- data/lib/morpheus/cli/instances.rb +588 -292
- data/lib/morpheus/cli/key_pairs.rb +393 -0
- data/lib/morpheus/cli/license.rb +118 -0
- data/lib/morpheus/cli/load_balancers.rb +366 -0
- data/lib/morpheus/cli/mixins/accounts_helper.rb +193 -0
- data/lib/morpheus/cli/option_types.rb +260 -0
- data/lib/morpheus/cli/roles.rb +164 -0
- data/lib/morpheus/cli/security_group_rules.rb +4 -9
- data/lib/morpheus/cli/shell.rb +108 -0
- data/lib/morpheus/cli/tasks.rb +370 -0
- data/lib/morpheus/cli/users.rb +325 -0
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/workflows.rb +100 -0
- data/lib/morpheus/formatters.rb +43 -0
- data/morpheus-cli.gemspec +1 -1
- metadata +33 -10
- data/lib/morpheus/cli/servers.rb +0 -265
@@ -12,21 +12,37 @@ class Morpheus::Cli::Instances
|
|
12
12
|
include Term::ANSIColor
|
13
13
|
def initialize()
|
14
14
|
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
15
|
-
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect(opts)
|
19
|
+
if opts[:remote]
|
20
|
+
@appliance_url = opts[:remote]
|
21
|
+
@appliance_name = opts[:remote]
|
22
|
+
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
23
|
+
else
|
24
|
+
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
25
|
+
end
|
26
|
+
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
16
27
|
@instances_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instances
|
28
|
+
@task_sets_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).task_sets
|
29
|
+
@logs_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).logs
|
30
|
+
@tasks_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).tasks
|
17
31
|
@instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
|
18
32
|
@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
|
33
|
+
@provision_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).provision_types
|
34
|
+
@options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).options
|
19
35
|
@active_groups = ::Morpheus::Cli::Groups.load_group_file
|
36
|
+
if @access_token.empty?
|
37
|
+
print red,bold, "\nInvalid Credentials. Unable to acquire access token. Please verify your credentials and try again.\n\n",reset
|
38
|
+
exit 1
|
39
|
+
end
|
20
40
|
end
|
21
41
|
|
22
42
|
|
23
43
|
def handle(args)
|
24
|
-
if @access_token.empty?
|
25
|
-
print red,bold, "\nInvalid Credentials. Unable to acquire access token. Please verify your credentials and try again.\n\n",reset
|
26
|
-
return 1
|
27
|
-
end
|
28
44
|
if args.empty?
|
29
|
-
puts "\nUsage: morpheus instances [list,add,remove,stop,start,restart,resize,upgrade,clone,envs,setenv,delenv,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]\n\n"
|
45
|
+
puts "\nUsage: morpheus instances [list,add,remove,stop,start,restart,backup,run-workflow,resize,upgrade,clone,envs,setenv,delenv,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]\n\n"
|
30
46
|
return
|
31
47
|
end
|
32
48
|
|
@@ -43,8 +59,18 @@ class Morpheus::Cli::Instances
|
|
43
59
|
start(args[1..-1])
|
44
60
|
when 'restart'
|
45
61
|
restart(args[1..-1])
|
62
|
+
when 'stop-service'
|
63
|
+
stop_service(args[1..-1])
|
64
|
+
when 'start-service'
|
65
|
+
start_service(args[1..-1])
|
66
|
+
when 'restart-service'
|
67
|
+
restart_service(args[1..-1])
|
68
|
+
when 'run-workflow'
|
69
|
+
run_workflow(args[1..-1])
|
46
70
|
when 'stats'
|
47
71
|
stats(args[1..-1])
|
72
|
+
when 'logs'
|
73
|
+
logs(args[1..-1])
|
48
74
|
when 'details'
|
49
75
|
details(args[1..-1])
|
50
76
|
when 'envs'
|
@@ -53,37 +79,76 @@ class Morpheus::Cli::Instances
|
|
53
79
|
setenv(args[1..-1])
|
54
80
|
when 'delenv'
|
55
81
|
delenv(args[1..-1])
|
56
|
-
when '
|
82
|
+
when 'firewall-disable'
|
57
83
|
firewall_disable(args[1..-1])
|
58
|
-
when '
|
84
|
+
when 'firewall-enable'
|
59
85
|
firewall_enable(args[1..-1])
|
60
|
-
when '
|
86
|
+
when 'security-groups'
|
61
87
|
security_groups(args[1..-1])
|
62
|
-
when '
|
88
|
+
when 'apply-security-groups'
|
63
89
|
apply_security_groups(args[1..-1])
|
90
|
+
when 'backup'
|
91
|
+
backup(args[1..-1])
|
64
92
|
else
|
65
|
-
puts "\nUsage: morpheus instances [list,add,remove,stop,start,restart,resize,upgrade,clone,envs,setenv,delenv] [name]\n\n"
|
93
|
+
puts "\nUsage: morpheus instances [list,add,remove,stop,start,restart,backup,run-workflow,stop-service,start-service,restart-service,resize,upgrade,clone,envs,setenv,delenv] [name]\n\n"
|
94
|
+
exit 127
|
66
95
|
end
|
67
96
|
end
|
68
97
|
|
69
98
|
def add(args)
|
99
|
+
options = {}
|
100
|
+
optparse = OptionParser.new do|opts|
|
101
|
+
opts.banner = "Usage: morpheus instances add TYPE NAME"
|
102
|
+
opts.on( '-g', '--group GROUP', "Group" ) do |val|
|
103
|
+
options[:group] = val
|
104
|
+
end
|
105
|
+
opts.on( '-c', '--cloud CLOUD', "Cloud" ) do |val|
|
106
|
+
options[:cloud] = val
|
107
|
+
end
|
108
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
109
|
+
|
110
|
+
end
|
111
|
+
|
70
112
|
if args.count < 2
|
71
|
-
puts "\
|
113
|
+
puts "\n#{optparse}\n\n"
|
72
114
|
return
|
73
115
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
116
|
+
optparse.parse(args)
|
117
|
+
connect(options)
|
118
|
+
instance_name = args[1]
|
119
|
+
instance_type_code = args[0]
|
77
120
|
instance_type = find_instance_type_by_code(instance_type_code)
|
78
121
|
if instance_type.nil?
|
79
|
-
|
80
|
-
|
122
|
+
exit 1
|
123
|
+
end
|
124
|
+
groupId = nil
|
125
|
+
if !options[:group].nil?
|
126
|
+
group = find_group_by_name(options[:group])
|
127
|
+
if !group.nil?
|
128
|
+
groupId = group
|
129
|
+
end
|
130
|
+
else
|
131
|
+
groupId = @active_groups[@appliance_name.to_sym]
|
81
132
|
end
|
82
133
|
|
83
|
-
groupId
|
134
|
+
if groupId.nil?
|
135
|
+
puts "Group not found or specified! \n #{optparse}"
|
136
|
+
exit 1
|
137
|
+
end
|
138
|
+
|
139
|
+
if options[:cloud].nil?
|
140
|
+
puts "Cloud not specified! \n #{optparse}"
|
141
|
+
exit 1
|
142
|
+
end
|
143
|
+
cloud = find_cloud_by_name(groupId,options[:cloud])
|
144
|
+
if cloud.nil?
|
145
|
+
puts "Cloud not found! \n #{optparse}"
|
146
|
+
exit 1
|
147
|
+
end
|
84
148
|
|
85
|
-
|
149
|
+
payload = {
|
86
150
|
:servicePlan => nil,
|
151
|
+
zoneId: cloud,
|
87
152
|
:instance => {
|
88
153
|
:name => instance_name,
|
89
154
|
:site => {
|
@@ -95,77 +160,60 @@ class Morpheus::Cli::Instances
|
|
95
160
|
}
|
96
161
|
}
|
97
162
|
|
163
|
+
version_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'version', 'type' => 'select', 'fieldLabel' => 'Version', 'optionSource' => 'instanceVersions', 'required' => true, 'skipSingleOption':true, 'description' => 'Select which version of the instance type to be provisioned.'}],options[:options],@api_client,{groupId: groupId, cloudId: cloud, instanceTypeId: instance_type['id']})
|
164
|
+
layout_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'layout', 'type' => 'select', 'fieldLabel' => 'Layout', 'optionSource' => 'layoutsForCloud', 'required' => true, 'description' => 'Select which configuration of the instance type to be provisioned.'}],options[:options],@api_client,{groupId: groupId, cloudId: cloud, instanceTypeId: instance_type['id'], version: version_prompt['version']})
|
165
|
+
layout_id = layout_prompt['layout']
|
166
|
+
plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'Plan', 'optionSource' => 'instanceServicePlans', 'required' => true, 'description' => 'Choose the appropriately sized plan for this instance'}],options[:options],@api_client,{groupId: groupId, zoneId: cloud, instanceTypeId: instance_type['id'], layoutId: layout_id, version: version_prompt['version']})
|
167
|
+
payload[:servicePlan] = plan_prompt['servicePlan']
|
168
|
+
layout = instance_type['instanceTypeLayouts'].find{ |lt| lt['id'].to_i == layout_id.to_i}
|
98
169
|
instance_type['instanceTypeLayouts'].sort! { |x,y| y['sortOrder'] <=> x['sortOrder'] }
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
layout_selection = $stdin.gets.chomp!
|
108
|
-
if layout_selection.to_i.to_s == layout_selection
|
109
|
-
layout_selection = layout_selection.to_i
|
110
|
-
break
|
111
|
-
end
|
170
|
+
|
171
|
+
payload[:instance][:layout] = {id: layout['id']}
|
172
|
+
|
173
|
+
type_payload = {}
|
174
|
+
if !layout['optionTypes'].nil? && layout['optionTypes'].empty?
|
175
|
+
type_payload = Morpheus::Cli::OptionTypes.prompt(layout['optionTypes'],options[:options],@api_client,{groupId: groupId, cloudId: cloud, zoneId: cloud, instanceTypeId: instance_type['id'], version: version_prompt['version']})
|
176
|
+
elsif !instance_type['optionTypes'].nil? && instance_type['optionTypes'].empty?
|
177
|
+
type_payload = Morpheus::Cli::OptionTypes.prompt(instance_type['optionTypes'],options[:options],@api_client,{groupId: groupId, cloudId: cloud, zoneId: cloud, instanceTypeId: instance_type['id'], version: version_prompt['version']})
|
112
178
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
break
|
129
|
-
end
|
130
|
-
end
|
131
|
-
options[:servicePlan] = plans['servicePlans'][plan_selection-1]['id']
|
132
|
-
print "\n"
|
133
|
-
end
|
134
|
-
|
135
|
-
if !instance_type['config'].nil?
|
136
|
-
instance_type_config = JSON.parse(instance_type['config'])
|
137
|
-
if instance_type_config['options'].nil? == false
|
138
|
-
instance_type_config['options'].each do |opt|
|
139
|
-
print "#{opt['label']}: "
|
140
|
-
if(opt['name'].downcase.include?("password"))
|
141
|
-
options[opt['name']] = STDIN.noecho(&:gets).chomp!
|
142
|
-
print "\n"
|
143
|
-
else
|
144
|
-
options[opt['name']] = $stdin.gets.chomp!
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|
179
|
+
if !type_payload['config'].nil?
|
180
|
+
payload.merge!(type_payload['config'])
|
181
|
+
end
|
182
|
+
|
183
|
+
provision_payload = {}
|
184
|
+
if !layout['provisionType'].nil? && !layout['provisionType']['optionTypes'].nil? && !layout['provisionType']['optionTypes'].empty?
|
185
|
+
puts "Checking for option Types"
|
186
|
+
provision_payload = Morpheus::Cli::OptionTypes.prompt(layout['provisionType']['optionTypes'],options[:options],@api_client,{groupId: groupId, cloudId: cloud, zoneId: cloud, instanceTypeId: instance_type['id'], version: version_prompt['version']})
|
187
|
+
end
|
188
|
+
|
189
|
+
if !provision_payload.nil? && !provision_payload['config'].nil?
|
190
|
+
payload.merge!(provision_payload['config'])
|
191
|
+
end
|
192
|
+
if !provision_payload.nil? && !provision_payload['server'].nil?
|
193
|
+
payload[:server] = provision_payload['server']
|
149
194
|
end
|
195
|
+
|
150
196
|
begin
|
151
|
-
@instances_interface.create(
|
152
|
-
rescue => e
|
153
|
-
|
154
|
-
|
155
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
156
|
-
else
|
157
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
158
|
-
end
|
159
|
-
return nil
|
197
|
+
@instances_interface.create(payload)
|
198
|
+
rescue RestClient::Exception => e
|
199
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
200
|
+
exit 1
|
160
201
|
end
|
161
202
|
list([])
|
162
203
|
end
|
163
204
|
|
164
205
|
def stats(args)
|
206
|
+
options = {}
|
207
|
+
optparse = OptionParser.new do|opts|
|
208
|
+
opts.banner = "Usage: morpheus instances stats [name]"
|
209
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
210
|
+
end
|
165
211
|
if args.count < 1
|
166
|
-
puts "\
|
212
|
+
puts "\n#{optparse.banner}\n\n"
|
167
213
|
return
|
168
214
|
end
|
215
|
+
optparse.parse(args)
|
216
|
+
connect(options)
|
169
217
|
begin
|
170
218
|
instance_results = @instances_interface.get({name: args[0]})
|
171
219
|
if instance_results['instances'].empty?
|
@@ -175,26 +223,85 @@ class Morpheus::Cli::Instances
|
|
175
223
|
instance = instance_results['instances'][0]
|
176
224
|
instance_id = instance['id']
|
177
225
|
stats = instance_results['stats'][instance_id.to_s]
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
226
|
+
if options[:json]
|
227
|
+
print JSON.pretty_generate(stats)
|
228
|
+
print "\n"
|
229
|
+
else
|
230
|
+
print "\n" ,cyan, bold, "#{instance['name']} (#{instance['instanceType']['name']})\n","==================", "\n\n", reset, cyan
|
231
|
+
stats_map = {}
|
232
|
+
stats_map[:memory] = "#{Filesize.from("#{stats['usedMemory']} B").pretty} / #{Filesize.from("#{stats['maxMemory']} B").pretty}"
|
233
|
+
stats_map[:storage] = "#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}"
|
234
|
+
stats_map[:cpu] = "#{stats['usedCpu'].to_f.round(2)}%"
|
235
|
+
tp [stats_map], :memory,:storage,:cpu
|
236
|
+
print reset, "\n"
|
237
|
+
end
|
182
238
|
rescue RestClient::Exception => e
|
183
|
-
|
184
|
-
|
185
|
-
|
239
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
240
|
+
exit 1
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def logs(args)
|
245
|
+
options = {}
|
246
|
+
optparse = OptionParser.new do|opts|
|
247
|
+
opts.banner = "Usage: morpheus instances logs [name]"
|
248
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
249
|
+
opts.on( '-n', '--node NODE_ID', "Scope logs to specific Container or VM" ) do |node_id|
|
250
|
+
options[:node_id] = node_id.to_i
|
251
|
+
end
|
252
|
+
end
|
253
|
+
if args.count < 1
|
254
|
+
puts "\n#{optparse.banner}\n\n"
|
255
|
+
return
|
256
|
+
end
|
257
|
+
optparse.parse(args)
|
258
|
+
connect(options)
|
259
|
+
begin
|
260
|
+
instance = find_instance_by_name(args[0])
|
261
|
+
container_ids = instance['containers']
|
262
|
+
if options[:node_id] && container_ids.include?(options[:node_id])
|
263
|
+
container_ids = [options[:node_id]]
|
264
|
+
end
|
265
|
+
logs = @logs_interface.container_logs(container_ids, { max: options[:max] || 100, offset: options[:offset] || 0, query: options[:phrase]})
|
266
|
+
if options[:json]
|
267
|
+
puts logs
|
186
268
|
else
|
187
|
-
|
269
|
+
logs['data'].reverse.each do |log_entry|
|
270
|
+
log_level = ''
|
271
|
+
case log_entry['level']
|
272
|
+
when 'INFO'
|
273
|
+
log_level = "#{blue}#{bold}INFO#{reset}"
|
274
|
+
when 'DEBUG'
|
275
|
+
log_level = "#{white}#{bold}DEBUG#{reset}"
|
276
|
+
when 'WARN'
|
277
|
+
log_level = "#{yellow}#{bold}WARN#{reset}"
|
278
|
+
when 'ERROR'
|
279
|
+
log_level = "#{red}#{bold}ERROR#{reset}"
|
280
|
+
when 'FATAL'
|
281
|
+
log_level = "#{red}#{bold}FATAL#{reset}"
|
282
|
+
end
|
283
|
+
puts "[#{log_entry['ts']}] #{log_level} - #{log_entry['message']}"
|
284
|
+
end
|
285
|
+
print reset,"\n"
|
188
286
|
end
|
189
|
-
|
287
|
+
rescue RestClient::Exception => e
|
288
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
289
|
+
exit 1
|
190
290
|
end
|
191
291
|
end
|
192
292
|
|
193
293
|
def details(args)
|
294
|
+
options = {}
|
295
|
+
optparse = OptionParser.new do|opts|
|
296
|
+
opts.banner = "Usage: morpheus instances details [name]"
|
297
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
298
|
+
end
|
194
299
|
if args.count < 1
|
195
|
-
puts "\
|
300
|
+
puts "\n#{optparse.banner}\n\n"
|
196
301
|
return
|
197
302
|
end
|
303
|
+
optparse.parse(args)
|
304
|
+
connect(options)
|
198
305
|
begin
|
199
306
|
instance_results = @instances_interface.get({name: args[0]})
|
200
307
|
if instance_results['instances'].empty?
|
@@ -209,30 +316,26 @@ class Morpheus::Cli::Instances
|
|
209
316
|
print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset
|
210
317
|
puts instance
|
211
318
|
rescue RestClient::Exception => e
|
212
|
-
|
213
|
-
|
214
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
215
|
-
else
|
216
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
217
|
-
end
|
218
|
-
return nil
|
319
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
320
|
+
exit 1
|
219
321
|
end
|
220
322
|
end
|
221
323
|
|
222
324
|
def envs(args)
|
325
|
+
options = {}
|
326
|
+
optparse = OptionParser.new do|opts|
|
327
|
+
opts.banner = "Usage: morpheus instances envs [name]"
|
328
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
329
|
+
end
|
223
330
|
if args.count < 1
|
224
|
-
puts "\
|
225
|
-
|
331
|
+
puts "\n#{optparse.banner}\n\n"
|
332
|
+
exit 1
|
226
333
|
end
|
334
|
+
optparse.parse(args)
|
335
|
+
connect(options)
|
227
336
|
begin
|
228
|
-
|
229
|
-
|
230
|
-
puts "Instance not found by name #{args[0]}"
|
231
|
-
return
|
232
|
-
end
|
233
|
-
instance = instance_results['instances'][0]
|
234
|
-
instance_id = instance['id']
|
235
|
-
env_results = @instances_interface.get_envs(instance_id)
|
337
|
+
instance = find_instance_by_name(args[0])
|
338
|
+
env_results = @instances_interface.get_envs(instance['id'])
|
236
339
|
print "\n" ,cyan, bold, "#{instance['name']} (#{instance['instanceType']['name']})\n","==================", "\n\n", reset, cyan
|
237
340
|
envs = env_results['envs'] || {}
|
238
341
|
if env_results['readOnlyEnvs']
|
@@ -245,148 +348,245 @@ class Morpheus::Cli::Instances
|
|
245
348
|
print reset, "\n"
|
246
349
|
|
247
350
|
rescue RestClient::Exception => e
|
248
|
-
|
249
|
-
|
250
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
251
|
-
else
|
252
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
253
|
-
end
|
254
|
-
return nil
|
351
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
352
|
+
exit 1
|
255
353
|
end
|
256
354
|
end
|
257
355
|
|
258
356
|
def setenv(args)
|
357
|
+
options = {}
|
358
|
+
|
359
|
+
optparse = OptionParser.new do|opts|
|
360
|
+
opts.banner = "Usage: morpheus instances setenv INSTANCE NAME VALUE [-e]"
|
361
|
+
opts.on( '-e', "Exportable" ) do |exportable|
|
362
|
+
options[:export] = exportable
|
363
|
+
end
|
364
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
365
|
+
end
|
259
366
|
if args.count < 3
|
260
|
-
puts "\
|
261
|
-
|
367
|
+
puts "\n#{optparse.banner}\n\n"
|
368
|
+
exit 1
|
262
369
|
end
|
370
|
+
optparse.parse(args)
|
371
|
+
connect(options)
|
263
372
|
begin
|
264
|
-
|
265
|
-
|
266
|
-
puts "Instance not found by name #{args[0]}"
|
267
|
-
return
|
268
|
-
end
|
269
|
-
instance = instance_results['instances'][0]
|
270
|
-
instance_id = instance['id']
|
271
|
-
evar = {name: args[1], value: args[2], export: false}
|
373
|
+
instance = find_instance_by_name(args[0])
|
374
|
+
evar = {name: args[1], value: args[2], export: options[:export]}
|
272
375
|
params = {}
|
273
|
-
|
274
|
-
opts.on( '-e', "Exportable" ) do |exportable|
|
275
|
-
evar[:export] = exportable
|
276
|
-
end
|
277
|
-
end
|
278
|
-
optparse.parse(args)
|
279
|
-
|
280
|
-
@instances_interface.create_env(instance_id, [evar])
|
376
|
+
@instances_interface.create_env(instance['id'], [evar])
|
281
377
|
envs([args[0]])
|
282
378
|
rescue RestClient::Exception => e
|
283
|
-
|
284
|
-
|
285
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
286
|
-
else
|
287
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
288
|
-
end
|
289
|
-
return nil
|
379
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
380
|
+
exit 1
|
290
381
|
end
|
291
382
|
end
|
292
383
|
|
293
384
|
def delenv(args)
|
385
|
+
options = {}
|
386
|
+
optparse = OptionParser.new do|opts|
|
387
|
+
opts.banner = "Usage: morpheus instances setenv INSTANCE NAME"
|
388
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
389
|
+
end
|
294
390
|
if args.count < 2
|
295
|
-
puts "\
|
296
|
-
|
391
|
+
puts "\n#{optparse.banner}\n\n"
|
392
|
+
exit 1
|
297
393
|
end
|
394
|
+
optparse.parse(args)
|
395
|
+
connect(options)
|
298
396
|
begin
|
299
|
-
|
300
|
-
|
301
|
-
puts "Instance not found by name #{args[0]}"
|
302
|
-
return
|
303
|
-
end
|
304
|
-
instance = instance_results['instances'][0]
|
305
|
-
instance_id = instance['id']
|
306
|
-
name = args[1]
|
307
|
-
|
308
|
-
@instances_interface.del_env(instance_id, name)
|
397
|
+
instance = find_instance_by_name(args[0])
|
398
|
+
@instances_interface.del_env(instance['id'], args[1])
|
309
399
|
envs([args[0]])
|
310
400
|
rescue RestClient::Exception => e
|
311
|
-
|
312
|
-
|
313
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
314
|
-
else
|
315
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
316
|
-
end
|
317
|
-
return nil
|
401
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
402
|
+
exit 1
|
318
403
|
end
|
319
404
|
end
|
320
405
|
|
321
406
|
def stop(args)
|
407
|
+
options = {}
|
408
|
+
optparse = OptionParser.new do|opts|
|
409
|
+
opts.banner = "Usage: morpheus instances stop [name]"
|
410
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
411
|
+
end
|
322
412
|
if args.count < 1
|
323
|
-
puts "\
|
324
|
-
|
413
|
+
puts "\n#{optparse.banner}\n\n"
|
414
|
+
exit 1
|
325
415
|
end
|
416
|
+
optparse.parse(args)
|
417
|
+
connect(options)
|
326
418
|
begin
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
419
|
+
instance = find_instance_by_name(args[0])
|
420
|
+
json_response = @instances_interface.stop(instance['id'])
|
421
|
+
if options[:json]
|
422
|
+
print JSON.pretty_generate(json_response)
|
423
|
+
print "\n"
|
331
424
|
end
|
332
|
-
|
333
|
-
list([])
|
425
|
+
return
|
334
426
|
rescue RestClient::Exception => e
|
335
|
-
|
336
|
-
|
337
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
338
|
-
else
|
339
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
340
|
-
end
|
341
|
-
return nil
|
427
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
428
|
+
exit 1
|
342
429
|
end
|
343
430
|
end
|
344
431
|
|
345
432
|
def start(args)
|
433
|
+
options = {}
|
434
|
+
optparse = OptionParser.new do|opts|
|
435
|
+
opts.banner = "Usage: morpheus instances start [name]"
|
436
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
437
|
+
end
|
346
438
|
if args.count < 1
|
347
|
-
puts "\
|
439
|
+
puts "\n#{optparse.banner}\n\n"
|
440
|
+
exit 1
|
441
|
+
end
|
442
|
+
optparse.parse(args)
|
443
|
+
connect(options)
|
444
|
+
begin
|
445
|
+
instance = find_instance_by_name(args[0])
|
446
|
+
json_response = @instances_interface.start(instance['id'])
|
447
|
+
if options[:json]
|
448
|
+
print JSON.pretty_generate(json_response)
|
449
|
+
print "\n"
|
450
|
+
end
|
348
451
|
return
|
452
|
+
rescue RestClient::Exception => e
|
453
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
454
|
+
exit 1
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
def restart(args)
|
459
|
+
options = {}
|
460
|
+
optparse = OptionParser.new do|opts|
|
461
|
+
opts.banner = "Usage: morpheus instances restart [name]"
|
462
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
349
463
|
end
|
464
|
+
if args.count < 1
|
465
|
+
puts "\n#{optparse.banner}\n\n"
|
466
|
+
exit 1
|
467
|
+
end
|
468
|
+
optparse.parse(args)
|
469
|
+
connect(options)
|
350
470
|
begin
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
471
|
+
instance = find_instance_by_name(args[0])
|
472
|
+
json_response = @instances_interface.restart(instance['id'])
|
473
|
+
if options[:json]
|
474
|
+
print JSON.pretty_generate(json_response)
|
475
|
+
print "\n"
|
355
476
|
end
|
356
|
-
|
357
|
-
list([])
|
477
|
+
return
|
358
478
|
rescue RestClient::Exception => e
|
359
|
-
|
360
|
-
|
361
|
-
|
479
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
480
|
+
exit 1
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def stop_service(args)
|
485
|
+
options = {}
|
486
|
+
optparse = OptionParser.new do|opts|
|
487
|
+
opts.banner = "Usage: morpheus instances stop-service [name]"
|
488
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
489
|
+
end
|
490
|
+
if args.count < 1
|
491
|
+
puts "\n#{optparse.banner}\n\n"
|
492
|
+
exit 1
|
493
|
+
end
|
494
|
+
optparse.parse(args)
|
495
|
+
connect(options)
|
496
|
+
begin
|
497
|
+
instance = find_instance_by_name(args[0])
|
498
|
+
json_response = @instances_interface.stop(instance['id'],false)
|
499
|
+
if options[:json]
|
500
|
+
print JSON.pretty_generate(json_response)
|
501
|
+
print "\n"
|
362
502
|
else
|
363
|
-
puts "
|
503
|
+
puts "Stopping service on #{args[0]}"
|
364
504
|
end
|
365
|
-
return
|
505
|
+
return
|
506
|
+
rescue RestClient::Exception => e
|
507
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
508
|
+
exit 1
|
366
509
|
end
|
367
510
|
end
|
368
511
|
|
369
|
-
def
|
512
|
+
def start_service(args)
|
513
|
+
options = {}
|
514
|
+
optparse = OptionParser.new do|opts|
|
515
|
+
opts.banner = "Usage: morpheus instances start-service [name]"
|
516
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
517
|
+
end
|
370
518
|
if args.count < 1
|
371
|
-
puts "\
|
519
|
+
puts "\n#{optparse.banner}\n\n"
|
520
|
+
exit 1
|
521
|
+
end
|
522
|
+
optparse.parse(args)
|
523
|
+
connect(options)
|
524
|
+
begin
|
525
|
+
instance = find_instance_by_name(args[0])
|
526
|
+
json_response = @instances_interface.start(instance['id'],false)
|
527
|
+
if options[:json]
|
528
|
+
print JSON.pretty_generate(json_response)
|
529
|
+
print "\n"
|
530
|
+
else
|
531
|
+
puts "Starting service on #{args[0]}"
|
532
|
+
end
|
372
533
|
return
|
534
|
+
rescue RestClient::Exception => e
|
535
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
536
|
+
exit 1
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
def restart_service(args)
|
541
|
+
options = {}
|
542
|
+
optparse = OptionParser.new do|opts|
|
543
|
+
opts.banner = "Usage: morpheus instances restart-service [name]"
|
544
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
545
|
+
end
|
546
|
+
if args.count < 1
|
547
|
+
puts "\n#{optparse.banner}\n\n"
|
548
|
+
exit 1
|
373
549
|
end
|
550
|
+
optparse.parse(args)
|
551
|
+
connect(options)
|
374
552
|
begin
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
553
|
+
instance = find_instance_by_name(args[0])
|
554
|
+
json_response = @instances_interface.restart(instance['id'],false)
|
555
|
+
if options[:json]
|
556
|
+
print JSON.pretty_generate(json_response)
|
557
|
+
print "\n"
|
558
|
+
else
|
559
|
+
puts "Restarting service on instance #{args[0]}"
|
379
560
|
end
|
380
|
-
|
381
|
-
list([])
|
561
|
+
return
|
382
562
|
rescue RestClient::Exception => e
|
383
|
-
|
384
|
-
|
385
|
-
|
563
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
564
|
+
exit 1
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
def backup(args)
|
569
|
+
options = {}
|
570
|
+
optparse = OptionParser.new do|opts|
|
571
|
+
opts.banner = "Usage: morpheus instances backup [name]"
|
572
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
573
|
+
end
|
574
|
+
puts "\n#{optparse.banner}\n\n" and exit 1 if args.count < 1
|
575
|
+
optparse.parse(args)
|
576
|
+
connect(options)
|
577
|
+
begin
|
578
|
+
instance = find_instance_by_name(args[0])
|
579
|
+
json_response = @instances_interface.backup(instance['id'])
|
580
|
+
if options[:json]
|
581
|
+
print JSON.pretty_generate(json_response)
|
582
|
+
print "\n"
|
386
583
|
else
|
387
|
-
puts "
|
584
|
+
puts "Backup initiated."
|
388
585
|
end
|
389
|
-
return
|
586
|
+
return
|
587
|
+
rescue RestClient::Exception => e
|
588
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
589
|
+
exit 1
|
390
590
|
end
|
391
591
|
end
|
392
592
|
|
@@ -396,88 +596,124 @@ class Morpheus::Cli::Instances
|
|
396
596
|
opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
|
397
597
|
options[:group] = group
|
398
598
|
end
|
599
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
399
600
|
end
|
400
601
|
optparse.parse(args)
|
602
|
+
connect(options)
|
401
603
|
begin
|
402
604
|
params = {}
|
403
605
|
if !options[:group].nil?
|
404
606
|
group = find_group_by_name(options[:group])
|
405
607
|
if !group.nil?
|
406
|
-
params['site'] = group
|
608
|
+
params['site'] = group
|
407
609
|
end
|
408
610
|
end
|
611
|
+
if !options[:max].nil?
|
612
|
+
params['max'] = options[:max]
|
613
|
+
end
|
614
|
+
if !options[:offset].nil?
|
615
|
+
params['offset'] = options[:offset]
|
616
|
+
end
|
617
|
+
if !options[:phrase].nil?
|
618
|
+
params['phrase'] = options[:phrase]
|
619
|
+
end
|
409
620
|
|
410
621
|
json_response = @instances_interface.get(params)
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
puts yellow,"No instances currently configured.",reset
|
622
|
+
if options[:json]
|
623
|
+
print JSON.pretty_generate(json_response)
|
624
|
+
print "\n"
|
415
625
|
else
|
416
|
-
instances
|
417
|
-
|
626
|
+
instances = json_response['instances']
|
627
|
+
|
628
|
+
print "\n" ,cyan, bold, "Morpheus Instances\n","==================", reset, "\n\n"
|
629
|
+
if instances.empty?
|
630
|
+
puts yellow,"No instances currently configured.",reset
|
631
|
+
else
|
632
|
+
print cyan
|
633
|
+
instance_table = instances.collect do |instance|
|
634
|
+
status_string = instance['status']
|
635
|
+
if status_string == 'running'
|
636
|
+
status_string = "#{green}#{status_string.upcase}#{cyan}"
|
637
|
+
elsif status_string == 'stopped' or status_string == 'failed'
|
638
|
+
status_string = "#{red}#{status_string.upcase}#{cyan}"
|
639
|
+
elsif status_string == 'unknown'
|
640
|
+
status_string = "#{white}#{status_string.upcase}#{cyan}"
|
641
|
+
else
|
642
|
+
status_string = "#{yellow}#{status_string.upcase}#{cyan}"
|
643
|
+
end
|
644
|
+
connection_string = ''
|
645
|
+
if !instance['connectionInfo'].nil? && instance['connectionInfo'].empty? == false
|
646
|
+
connection_string = "#{instance['connectionInfo'][0]['ip']}:#{instance['connectionInfo'][0]['port']}"
|
647
|
+
end
|
648
|
+
{id: instance['id'], name: instance['name'], connection: connection_string, environment: instance['instanceContext'], nodes: instance['containers'].count, status: status_string, type: instance['instanceType']['name']}
|
649
|
+
end
|
650
|
+
tp instance_table, :id, :name, :type, :environment, :nodes, :connection, :status
|
418
651
|
end
|
652
|
+
print reset,"\n\n"
|
419
653
|
end
|
420
|
-
print reset,"\n\n"
|
421
654
|
|
422
|
-
rescue => e
|
423
|
-
|
424
|
-
|
655
|
+
rescue RestClient::Exception => e
|
656
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
657
|
+
exit 1
|
425
658
|
end
|
426
659
|
end
|
427
660
|
|
428
661
|
def remove(args)
|
662
|
+
options = {}
|
663
|
+
optparse = OptionParser.new do|opts|
|
664
|
+
opts.banner = "Usage: morpheus instances remove [name]"
|
665
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
666
|
+
end
|
429
667
|
if args.count < 1
|
430
|
-
puts "\
|
431
|
-
|
668
|
+
puts "\n#{optparse.banner}\n\n"
|
669
|
+
exit 1
|
432
670
|
end
|
671
|
+
optparse.parse(args)
|
672
|
+
connect(options)
|
433
673
|
begin
|
434
|
-
|
435
|
-
|
436
|
-
puts "Instance not found by name #{args[0]}"
|
437
|
-
return
|
438
|
-
end
|
439
|
-
@instances_interface.destroy(instance_results['instances'][0]['id'])
|
674
|
+
instance = find_instance_by_name(args[0])
|
675
|
+
@instances_interface.destroy(instance['id'])
|
440
676
|
list([])
|
441
677
|
rescue RestClient::Exception => e
|
442
|
-
|
443
|
-
|
444
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
445
|
-
else
|
446
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
447
|
-
end
|
448
|
-
return nil
|
678
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
679
|
+
exit 1
|
449
680
|
end
|
450
681
|
end
|
451
682
|
|
452
683
|
def firewall_disable(args)
|
684
|
+
options = {}
|
685
|
+
optparse = OptionParser.new do|opts|
|
686
|
+
opts.banner = "Usage: morpheus instances firewall-disable [name]"
|
687
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
688
|
+
end
|
453
689
|
if args.count < 1
|
454
|
-
puts "\
|
455
|
-
|
690
|
+
puts "\n#{optparse.banner}\n\n"
|
691
|
+
exit 1
|
456
692
|
end
|
693
|
+
optparse.parse(args)
|
694
|
+
connect(options)
|
457
695
|
begin
|
458
|
-
|
459
|
-
|
460
|
-
puts "Instance not found by name #{args[0]}"
|
461
|
-
return
|
462
|
-
end
|
463
|
-
@instances_interface.firewall_disable(instance_results['instances'][0]['id'])
|
696
|
+
instance = find_instance_by_name(args[0])
|
697
|
+
@instances_interface.firewall_disable(instance['id'])
|
464
698
|
security_groups([args[0]])
|
465
699
|
rescue RestClient::Exception => e
|
466
|
-
|
467
|
-
|
468
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
469
|
-
else
|
470
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
471
|
-
end
|
472
|
-
return nil
|
700
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
701
|
+
exit 1
|
473
702
|
end
|
474
703
|
end
|
475
704
|
|
476
705
|
def firewall_enable(args)
|
706
|
+
options = {}
|
707
|
+
optparse = OptionParser.new do|opts|
|
708
|
+
opts.banner = "Usage: morpheus instances firewall-enable [name]"
|
709
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
710
|
+
end
|
477
711
|
if args.count < 1
|
478
|
-
puts "\
|
479
|
-
|
712
|
+
puts "\n#{optparse.banner}\n\n"
|
713
|
+
exit 1
|
480
714
|
end
|
715
|
+
optparse.parse(args)
|
716
|
+
connect(options)
|
481
717
|
begin
|
482
718
|
instance_results = @instances_interface.get({name: args[0]})
|
483
719
|
if instance_results['instances'].empty?
|
@@ -487,29 +723,26 @@ class Morpheus::Cli::Instances
|
|
487
723
|
@instances_interface.firewall_enable(instance_results['instances'][0]['id'])
|
488
724
|
security_groups([args[0]])
|
489
725
|
rescue RestClient::Exception => e
|
490
|
-
|
491
|
-
|
492
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
493
|
-
else
|
494
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
495
|
-
end
|
496
|
-
return nil
|
726
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
727
|
+
exit 1
|
497
728
|
end
|
498
729
|
end
|
499
730
|
|
500
731
|
def security_groups(args)
|
732
|
+
options = {}
|
733
|
+
optparse = OptionParser.new do|opts|
|
734
|
+
opts.banner = "Usage: morpheus instances security-groups [name]"
|
735
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
736
|
+
end
|
501
737
|
if args.count < 1
|
502
|
-
puts "\
|
503
|
-
|
738
|
+
puts "\n#{optparse.banner}\n\n"
|
739
|
+
exit 1
|
504
740
|
end
|
741
|
+
optparse.parse(args)
|
742
|
+
connect(options)
|
505
743
|
begin
|
506
|
-
|
507
|
-
|
508
|
-
puts "Instance not found by name #{args[0]}"
|
509
|
-
return
|
510
|
-
end
|
511
|
-
|
512
|
-
instance_id = instance_results['instances'][0]['id']
|
744
|
+
instance = find_instance_by_name(args[0])
|
745
|
+
instance_id = instance['id']
|
513
746
|
json_response = @instances_interface.security_groups(instance_id)
|
514
747
|
|
515
748
|
securityGroups = json_response['securityGroups']
|
@@ -525,43 +758,32 @@ class Morpheus::Cli::Instances
|
|
525
758
|
print reset,"\n\n"
|
526
759
|
|
527
760
|
rescue RestClient::Exception => e
|
528
|
-
|
529
|
-
|
530
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
531
|
-
else
|
532
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
533
|
-
end
|
534
|
-
return nil
|
761
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
762
|
+
exit 1
|
535
763
|
end
|
536
764
|
end
|
537
765
|
|
538
766
|
def apply_security_groups(args)
|
539
|
-
usage = <<-EOF
|
540
|
-
Usage: morpheus instances apply_security_groups [name] [options]
|
541
|
-
EOF
|
542
|
-
if args.count < 1
|
543
|
-
puts usage
|
544
|
-
return
|
545
|
-
end
|
546
|
-
|
547
767
|
options = {}
|
548
768
|
clear_or_secgroups_specified = false
|
549
769
|
optparse = OptionParser.new do|opts|
|
550
|
-
opts.banner =
|
770
|
+
opts.banner = "Usage: morpheus instances apply-security-groups [name] [options]"
|
551
771
|
opts.on( '-c', '--clear', "Clear all security groups" ) do
|
552
772
|
options[:securityGroupIds] = []
|
553
773
|
clear_or_secgroups_specified = true
|
554
774
|
end
|
555
|
-
opts.on( '-
|
775
|
+
opts.on( '-S', '--secgroups SECGROUPS', "Apply the specified comma separated security group ids" ) do |secgroups|
|
556
776
|
options[:securityGroupIds] = secgroups.split(",")
|
557
777
|
clear_or_secgroups_specified = true
|
558
778
|
end
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
779
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
780
|
+
end
|
781
|
+
if args.count < 1
|
782
|
+
puts "\n#{optparse.banner}\n\n"
|
783
|
+
exit 1
|
563
784
|
end
|
564
785
|
optparse.parse(args)
|
786
|
+
connect(options)
|
565
787
|
|
566
788
|
if !clear_or_secgroups_specified
|
567
789
|
puts usage
|
@@ -569,33 +791,107 @@ EOF
|
|
569
791
|
end
|
570
792
|
|
571
793
|
begin
|
572
|
-
|
573
|
-
|
574
|
-
puts "Instance not found by name #{args[0]}"
|
575
|
-
return
|
576
|
-
end
|
577
|
-
|
578
|
-
@instances_interface.apply_security_groups(instance_results['instances'][0]['id'], options)
|
794
|
+
instance = find_instance_by_name(args[0])
|
795
|
+
@instances_interface.apply_security_groups(instance['id'], options)
|
579
796
|
security_groups([args[0]])
|
580
797
|
rescue RestClient::Exception => e
|
581
|
-
|
582
|
-
|
583
|
-
|
798
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
799
|
+
exit 1
|
800
|
+
end
|
801
|
+
end
|
802
|
+
|
803
|
+
|
804
|
+
def run_workflow(args)
|
805
|
+
options = {}
|
806
|
+
|
807
|
+
optparse = OptionParser.new do|opts|
|
808
|
+
opts.banner = "Usage: morpheus instances run-workflow [INSTANCE] [name] [options]"
|
809
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
810
|
+
end
|
811
|
+
if args.count < 2
|
812
|
+
puts "\n#{optparse}\n\n"
|
813
|
+
exit 1
|
814
|
+
end
|
815
|
+
|
816
|
+
optparse.parse(args)
|
817
|
+
connect(options)
|
818
|
+
instance = find_instance_by_name(args[0])
|
819
|
+
workflow = find_workflow_by_name(args[1])
|
820
|
+
task_types = @tasks_interface.task_types()
|
821
|
+
editable_options = []
|
822
|
+
workflow['taskSetTasks'].sort{|a,b| a['taskOrder'] <=> b['taskOrder']}.each do |task_set_task|
|
823
|
+
task_type_id = task_set_task['task']['taskType']['id']
|
824
|
+
task_type = task_types['taskTypes'].find{ |current_task_type| current_task_type['id'] == task_type_id}
|
825
|
+
task_opts = task_type['optionTypes'].select { |otype| otype['editable']}
|
826
|
+
if !task_opts.nil? && !task_opts.empty?
|
827
|
+
editable_options += task_opts.collect do |task_opt|
|
828
|
+
new_task_opt = task_opt.clone
|
829
|
+
new_task_opt['fieldContext'] = "#{task_set_task['id']}.#{new_task_opt['fieldContext']}"
|
830
|
+
end
|
831
|
+
end
|
832
|
+
end
|
833
|
+
params = options[:options] || {}
|
834
|
+
|
835
|
+
if params.empty? && !editable_options.empty?
|
836
|
+
puts "\n#{optparse.banner}\n\n"
|
837
|
+
option_lines = editable_options.collect {|it| "\t-O #{it['fieldContext'] ? (it['fieldContext'] + '.') : ''}#{it['fieldName']}=\"value\"" }.join("\n")
|
838
|
+
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
839
|
+
exit 1
|
840
|
+
end
|
841
|
+
|
842
|
+
workflow_payload = {taskSet: {"#{workflow['id']}": params }}
|
843
|
+
begin
|
844
|
+
|
845
|
+
json_response = @instances_interface.workflow(instance['id'],workflow['id'], workflow_payload)
|
846
|
+
if options[:json]
|
847
|
+
print JSON.pretty_generate(json_response)
|
848
|
+
print "\n"
|
584
849
|
else
|
585
|
-
puts "
|
850
|
+
puts "Running workflow..."
|
586
851
|
end
|
587
|
-
|
852
|
+
rescue RestClient::Exception => e
|
853
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
854
|
+
exit 1
|
588
855
|
end
|
589
856
|
end
|
590
857
|
|
591
858
|
private
|
859
|
+
|
860
|
+
def find_instance_by_name(name)
|
861
|
+
instance_results = @instances_interface.get({name: name})
|
862
|
+
if instance_results['instances'].empty?
|
863
|
+
puts "Instance not found by name #{name}"
|
864
|
+
exit 1
|
865
|
+
end
|
866
|
+
return instance_results['instances'][0]
|
867
|
+
end
|
868
|
+
def find_workflow_by_name(name)
|
869
|
+
task_set_results = @task_sets_interface.get(name)
|
870
|
+
if !task_set_results['taskSets'].nil? && !task_set_results['taskSets'].empty?
|
871
|
+
return task_set_results['taskSets'][0]
|
872
|
+
else
|
873
|
+
puts "Workflow not found by name #{name}"
|
874
|
+
exit 1
|
875
|
+
end
|
876
|
+
end
|
592
877
|
def find_group_by_name(name)
|
593
|
-
|
594
|
-
|
595
|
-
|
878
|
+
option_results = @options_interface.options_for_source('groups',{})
|
879
|
+
match = option_results['data'].find { |grp| grp['value'].to_s == name.to_s || grp['name'].downcase == name.downcase}
|
880
|
+
if match.nil?
|
881
|
+
return nil
|
882
|
+
else
|
883
|
+
return match['value']
|
884
|
+
end
|
885
|
+
end
|
886
|
+
|
887
|
+
def find_cloud_by_name(groupId,name)
|
888
|
+
option_results = @options_interface.options_for_source('clouds',{groupId: groupId})
|
889
|
+
match = option_results['data'].find { |grp| grp['value'].to_s == name.to_s || grp['name'].downcase == name.downcase}
|
890
|
+
if match.nil?
|
596
891
|
return nil
|
892
|
+
else
|
893
|
+
return match['value']
|
597
894
|
end
|
598
|
-
return group_results['groups'][0]
|
599
895
|
end
|
600
896
|
|
601
897
|
def find_instance_type_by_code(code)
|