morpheus-cli 3.4.1.2 → 3.4.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efb715b7f77375167099ebac68e98850cfa8986f
4
- data.tar.gz: 254eeeccb861eb78b9ef53e8fb8ce40c7bcfea32
3
+ metadata.gz: 8d494a00b196af210b1c23ccf1de41b2e069f0ad
4
+ data.tar.gz: dabfc1813d542df60e0905187499f7dbe8b210ee
5
5
  SHA512:
6
- metadata.gz: 5733564843f2afa6e9d464c542425583973676a5f32b7b6efe34a2f92a5f8292a6246575f1d5bc4834bf06cfbb39c9d7aed73342757aa38eb32cc631f8c08422
7
- data.tar.gz: a34905dff786cd7024ecfb4cf00c76f847bf7ccdd322cba36b06d0487af062bec2071db98688029c13f37ad9291c7533b65a7c8c36c1b313b6e0edb1048203ee
6
+ metadata.gz: dd186cffdf47d09863722bdcc0fd8f5e62f247afb49195d7b900d1315594c063ddaeee13bbcfa7169778218d0a8f130296f42da1018727559dc1b1e13def9d3a
7
+ data.tar.gz: e396de94d79b666b423c4745f5e4c04f62aa2fcbb14f9ad972058fb7e88f43b9e115f81127b74ad1b2a8fc162e531d22d16f516401c502b99483cdf33d46ed06
@@ -474,130 +474,146 @@ class Morpheus::Cli::Hosts
474
474
  opts.on( '-t', '--type TYPE', "Server Type Code" ) do |val|
475
475
  options[:server_type_code] = val
476
476
  end
477
- build_common_options(opts, options, [:options, :json, :dry_run, :quiet, :remote])
477
+ build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
478
478
  end
479
479
  optparse.parse!(args)
480
480
  connect(options)
481
+ begin
482
+ payload = nil
483
+ if options[:payload]
484
+ payload = options[:payload]
485
+ else
486
+ # support old format of `hosts add CLOUD NAME`
487
+ if args[0]
488
+ options[:cloud] = args[0]
489
+ end
490
+ if args[1]
491
+ options[:host_name] = args[1]
492
+ end
493
+ # use active group by default
494
+ options[:group] ||= @active_group_id
481
495
 
482
- # support old format of `hosts add CLOUD NAME`
483
- if args[0]
484
- options[:cloud] = args[0]
485
- end
486
- if args[1]
487
- options[:host_name] = args[1]
488
- end
489
- # use active group by default
490
- options[:group] ||= @active_group_id
496
+ params = {}
491
497
 
492
- params = {}
498
+ # Group
499
+ group_id = nil
500
+ group = options[:group] ? find_group_by_name_or_id_for_provisioning(options[:group]) : nil
501
+ if group
502
+ group_id = group["id"]
503
+ else
504
+ # print_red_alert "Group not found or specified!"
505
+ # exit 1
506
+ group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group', 'selectOptions' => get_available_groups(), 'required' => true, 'description' => 'Select Group.'}],options[:options],@api_client,{})
507
+ group_id = group_prompt['group']
508
+ end
493
509
 
494
- # Group
495
- group_id = nil
496
- group = options[:group] ? find_group_by_name_or_id_for_provisioning(options[:group]) : nil
497
- if group
498
- group_id = group["id"]
499
- else
500
- # print_red_alert "Group not found or specified!"
501
- # exit 1
502
- group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group', 'selectOptions' => get_available_groups(), 'required' => true, 'description' => 'Select Group.'}],options[:options],@api_client,{})
503
- group_id = group_prompt['group']
504
- end
510
+ # Cloud
511
+ cloud_id = nil
512
+ cloud = options[:cloud] ? find_cloud_by_name_or_id_for_provisioning(group_id, options[:cloud]) : nil
513
+ if cloud
514
+ cloud_id = cloud["id"]
515
+ else
516
+ available_clouds = get_available_clouds(group_id)
517
+ if available_clouds.empty?
518
+ print_red_alert "Group #{group['name']} has no available clouds"
519
+ exit 1
520
+ end
521
+ cloud_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'cloud', 'type' => 'select', 'fieldLabel' => 'Cloud', 'selectOptions' => available_clouds, 'required' => true, 'description' => 'Select Cloud.'}],options[:options],@api_client,{groupId: group_id})
522
+ cloud_id = cloud_prompt['cloud']
523
+ cloud = find_cloud_by_id_for_provisioning(group_id, cloud_id)
524
+ end
505
525
 
506
- # Cloud
507
- cloud_id = nil
508
- cloud = options[:cloud] ? find_cloud_by_name_or_id_for_provisioning(group_id, options[:cloud]) : nil
509
- if cloud
510
- cloud_id = cloud["id"]
511
- else
512
- available_clouds = get_available_clouds(group_id)
513
- if available_clouds.empty?
514
- print_red_alert "Group #{group['name']} has no available clouds"
515
- exit 1
516
- end
517
- cloud_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'cloud', 'type' => 'select', 'fieldLabel' => 'Cloud', 'selectOptions' => available_clouds, 'required' => true, 'description' => 'Select Cloud.'}],options[:options],@api_client,{groupId: group_id})
518
- cloud_id = cloud_prompt['cloud']
519
- cloud = find_cloud_by_id_for_provisioning(group_id, cloud_id)
520
- end
526
+ # Zone Type
527
+ cloud_type = cloud_type_for_id(cloud['zoneTypeId'])
521
528
 
522
- # Zone Type
523
- cloud_type = cloud_type_for_id(cloud['zoneTypeId'])
529
+ # Server Type
530
+ cloud_server_types = cloud_type['serverTypes'].select{|b| b['creatable'] == true }.sort { |x,y| x['displayOrder'] <=> y['displayOrder'] }
531
+ if options[:server_type_code]
532
+ server_type_code = options[:server_type_code]
533
+ else
534
+ server_type_options = cloud_server_types.collect {|it| {'name' => it['name'], 'value' => it['code']} }
535
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => "Server Type", 'selectOptions' => server_type_options, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a server type.'}], options[:options])
536
+ server_type_code = v_prompt['type']
537
+ end
538
+ server_type = cloud_server_types.find {|it| it['code'] == server_type_code }
539
+ if server_type.nil?
540
+ print_red_alert "Server Type #{server_type_code} not found cloud #{cloud['name']}"
541
+ exit 1
542
+ end
524
543
 
525
- # Server Type
526
- cloud_server_types = cloud_type['serverTypes'].select{|b| b['creatable'] == true }.sort { |x,y| x['displayOrder'] <=> y['displayOrder'] }
527
- if options[:server_type_code]
528
- server_type_code = options[:server_type_code]
529
- else
530
- server_type_options = cloud_server_types.collect {|it| {'name' => it['name'], 'value' => it['code']} }
531
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => "Server Type", 'selectOptions' => server_type_options, 'required' => true, 'skipSingleOption' => true, 'description' => 'Choose a server type.'}], options[:options])
532
- server_type_code = v_prompt['type']
533
- end
534
- server_type = cloud_server_types.find {|it| it['code'] == server_type_code }
535
- if server_type.nil?
536
- print_red_alert "Server Type #{server_type_code} not found cloud #{cloud['name']}"
537
- exit 1
538
- end
544
+ # Server Name
545
+ host_name = nil
546
+ if options[:host_name]
547
+ host_name = options[:host_name]
548
+ else
549
+ name_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Server Name', 'type' => 'text', 'required' => true}], options[:options])
550
+ host_name = name_prompt['name'] || ''
551
+ end
539
552
 
540
- # Server Name
541
- host_name = nil
542
- if options[:host_name]
543
- host_name = options[:host_name]
544
- else
545
- name_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Server Name', 'type' => 'text', 'required' => true}], options[:options])
546
- host_name = name_prompt['name'] || ''
547
- end
553
+ payload = {}
554
+ # prompt for service plan
555
+ service_plans_json = @servers_interface.service_plans({zoneId: cloud['id'], serverTypeId: server_type["id"]})
556
+ service_plans = service_plans_json["plans"]
557
+ service_plans_dropdown = service_plans.collect {|sp| {'name' => sp["name"], 'value' => sp["id"]} } # already sorted
558
+ plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'plan', 'type' => 'select', 'fieldLabel' => 'Plan', 'selectOptions' => service_plans_dropdown, 'required' => true, 'description' => 'Choose the appropriately sized plan for this server'}],options[:options])
559
+ service_plan = service_plans.find {|sp| sp["id"] == plan_prompt['plan'].to_i }
560
+
561
+ payload['server'] = {
562
+ 'name' => host_name,
563
+ 'zone' => {'id' => cloud['id']},
564
+ 'computeServerType' => {'id' => server_type['id']},
565
+ 'plan' => {'id' => service_plan["id"]}
566
+ }
567
+
568
+ # prompt for resource pool
569
+ has_zone_pools = server_type["provisionType"] && server_type["provisionType"]["hasZonePools"]
570
+ if has_zone_pools
571
+ resource_pool_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'resourcePool', 'type' => 'select', 'fieldLabel' => 'Resource Pool', 'optionSource' => 'zonePools', 'required' => true, 'skipSingleOption' => true, 'description' => 'Select resource pool.'}],options[:options],api_client,{groupId: group_id, zoneId: cloud_id, cloudId: cloud_id, planId: service_plan["id"]})
572
+ if resource_pool_prompt['config'] && resource_pool_prompt['config']['resourcePool']
573
+ payload['config'] ||= {}
574
+ payload['config']['resourcePool'] = resource_pool_prompt['config']['resourcePool']
575
+ end
576
+ end
548
577
 
549
- payload = {}
550
- # prompt for service plan
551
- service_plans_json = @servers_interface.service_plans({zoneId: cloud['id'], serverTypeId: server_type["id"]})
552
- service_plans = service_plans_json["plans"]
553
- service_plans_dropdown = service_plans.collect {|sp| {'name' => sp["name"], 'value' => sp["id"]} } # already sorted
554
- plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'plan', 'type' => 'select', 'fieldLabel' => 'Plan', 'selectOptions' => service_plans_dropdown, 'required' => true, 'description' => 'Choose the appropriately sized plan for this server'}],options[:options])
555
- service_plan = service_plans.find {|sp| sp["id"] == plan_prompt['plan'].to_i }
556
-
557
- # prompt for volumes
558
- volumes = prompt_volumes(service_plan, options, @api_client, {})
559
- if !volumes.empty?
560
- payload[:volumes] = volumes
561
- end
578
+ # prompt for volumes
579
+ volumes = prompt_volumes(service_plan, options, @api_client, {})
580
+ if !volumes.empty?
581
+ payload['volumes'] = volumes
582
+ end
562
583
 
563
- # prompt for network interfaces (if supported)
564
- if server_type["provisionType"] && server_type["provisionType"]["id"] && server_type["provisionType"]["hasNetworks"]
565
- begin
566
- network_interfaces = prompt_network_interfaces(cloud['id'], server_type["provisionType"]["id"], options)
567
- if !network_interfaces.empty?
568
- payload[:networkInterfaces] = network_interfaces
584
+ # prompt for network interfaces (if supported)
585
+ if server_type["provisionType"] && server_type["provisionType"]["id"] && server_type["provisionType"]["hasNetworks"]
586
+ begin
587
+ network_interfaces = prompt_network_interfaces(cloud['id'], server_type["provisionType"]["id"], options)
588
+ if !network_interfaces.empty?
589
+ payload['networkInterfaces'] = network_interfaces
590
+ end
591
+ rescue RestClient::Exception => e
592
+ print yellow,"Unable to load network options. Proceeding...",reset,"\n"
593
+ print_rest_exception(e, options) if Morpheus::Logging.debug?
594
+ end
569
595
  end
570
- rescue RestClient::Exception => e
571
- print yellow,"Unable to load network options. Proceeding...",reset,"\n"
572
- print_rest_exception(e, options) if Morpheus::Logging.debug?
573
- end
574
- end
575
596
 
576
- server_type_option_types = server_type['optionTypes']
577
- # remove volume options if volumes were configured
578
- if !payload[:volumes].empty?
579
- server_type_option_types = reject_volume_option_types(server_type_option_types)
580
- end
581
- # remove networkId option if networks were configured above
582
- if !payload[:networkInterfaces].empty?
583
- server_type_option_types = reject_networking_option_types(server_type_option_types)
584
- end
585
- # remove cpu and memory option types, which now come from the plan
586
- server_type_option_types = reject_service_plan_option_types(server_type_option_types)
597
+ server_type_option_types = server_type['optionTypes']
598
+ # remove volume options if volumes were configured
599
+ if !payload['volumes'].empty?
600
+ server_type_option_types = reject_volume_option_types(server_type_option_types)
601
+ end
602
+ # remove networkId option if networks were configured above
603
+ if !payload['networkInterfaces'].empty?
604
+ server_type_option_types = reject_networking_option_types(server_type_option_types)
605
+ end
606
+ # remove resourcePoolId if it was configured above
607
+ if has_zone_pools
608
+ server_type_option_types = server_type_option_types.reject {|opt| ['resourcePool','resourcePoolId','azureResourceGroupId'].include?(opt['fieldName']) }
609
+ end
610
+ # remove cpu and memory option types, which now come from the plan
611
+ server_type_option_types = reject_service_plan_option_types(server_type_option_types)
587
612
 
588
- params = Morpheus::Cli::OptionTypes.prompt(server_type_option_types,options[:options],@api_client, {zoneId: cloud['id']})
589
- begin
590
- params['server'] = params['server'] || {}
591
- payload = payload.merge({
592
- server: {
593
- name: host_name,
594
- zone: {id: cloud['id']},
595
- computeServerType: {id: server_type['id']},
596
- plan: {id: service_plan["id"]}
597
- }.merge(params['server'])
598
- })
599
- payload[:network] = params['network'] if params['network']
600
- payload[:config] = params['config'] if params['config']
613
+ params = Morpheus::Cli::OptionTypes.prompt(server_type_option_types,options[:options],@api_client, {zoneId: cloud['id']})
614
+ payload.deep_merge!(params)
615
+
616
+ end
601
617
  if options[:dry_run]
602
618
  print_dry_run @servers_interface.dry.create(payload)
603
619
  return
@@ -317,6 +317,16 @@ module Morpheus::Cli::ProvisioningHelper
317
317
  end
318
318
  payload['instance']['plan'] = {'id' => service_plan["id"]}
319
319
 
320
+ # prompt for resource pool
321
+ has_zone_pools = layout["provisionType"] && layout["provisionType"]["id"] && layout["provisionType"]["hasZonePools"]
322
+ if has_zone_pools
323
+ resource_pool_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'resourcePoolId', 'type' => 'select', 'fieldLabel' => 'Resource Pool', 'optionSource' => 'zonePools', 'required' => true, 'skipSingleOption' => true, 'description' => 'Select resource pool.'}],options[:options],api_client,{groupId: group_id, zoneId: cloud_id, cloudId: cloud_id, instanceTypeId: instance_type['id'], planId: service_plan["id"]})
324
+ if resource_pool_prompt['config'] && resource_pool_prompt['config']['resourcePoolId']
325
+ payload['config'] ||= {}
326
+ payload['config']['resourcePoolId'] = resource_pool_prompt['config']['resourcePoolId']
327
+ end
328
+ end
329
+
320
330
  # prompt for volumes
321
331
  volumes = prompt_volumes(service_plan, options, api_client, {})
322
332
  if !volumes.empty?
@@ -354,6 +364,10 @@ module Morpheus::Cli::ProvisioningHelper
354
364
  if !payload['networkInterfaces'].empty?
355
365
  option_type_list = reject_networking_option_types(option_type_list)
356
366
  end
367
+ # remove resourcePoolId if it was configured above
368
+ if has_zone_pools
369
+ option_type_list = option_type_list.reject {|opt| ['resourcePool','resourcePoolId','azureResourceGroupId'].include?(opt['fieldName']) }
370
+ end
357
371
 
358
372
  instance_config_payload = Morpheus::Cli::OptionTypes.prompt(option_type_list, options[:options], @api_client, {groupId: group_id, cloudId: cloud_id, zoneId: cloud_id, instanceTypeId: instance_type['id'], version: version_prompt['version']})
359
373
  payload.deep_merge!(instance_config_payload)
@@ -864,7 +878,7 @@ module Morpheus::Cli::ProvisioningHelper
864
878
  network_interface_types = (zone_network_data['networkTypes'] || []).sort { |x,y| x['displayOrder'] <=> y['displayOrder'] }
865
879
  enable_network_type_selection = (zone_network_data['enableNetworkTypeSelection'] == 'on' || zone_network_data['enableNetworkTypeSelection'] == true)
866
880
  has_networks = zone_network_data["hasNetworks"] == true
867
- max_networks = zone_network_data["maxNetworks"] ? zone_network_data["maxNetworks"].to_i : nil
881
+ max_networks = (zone_network_data["maxNetworks"].to_i > 0) ? zone_network_data["maxNetworks"].to_i : nil
868
882
 
869
883
  # skip unless provision type supports networks
870
884
  if !has_networks
@@ -941,10 +955,11 @@ module Morpheus::Cli::ProvisioningHelper
941
955
 
942
956
  network_interfaces << network_interface
943
957
  interface_index += 1
944
- has_another_interface = options[:options] && options[:options]["networkInterface#{interface_index}"]
945
- add_another_interface = has_another_interface || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another network interface?", {:default => false}))
946
958
  if max_networks && network_interfaces.size >= max_networks
947
959
  add_another_interface = false
960
+ else
961
+ has_another_interface = options[:options] && options[:options]["networkInterface#{interface_index}"]
962
+ add_another_interface = has_another_interface || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another network interface?", {:default => false}))
948
963
  end
949
964
 
950
965
  end
@@ -33,47 +33,50 @@ class Morpheus::Cli::Roles
33
33
 
34
34
  def list(args)
35
35
  options = {}
36
- optparse = OptionParser.new do|opts|
36
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
37
37
  opts.banner = subcommand_usage()
38
- build_common_options(opts, options, [:list, :json, :dry_run])
38
+ build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
39
+ opts.footer = "List roles."
39
40
  end
40
41
  optparse.parse!(args)
41
42
 
42
43
  connect(options)
43
44
  begin
44
- load_whoami()
45
-
46
45
  account = find_account_from_options(options)
47
46
  account_id = account ? account['id'] : nil
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
 
53
51
  if options[:dry_run]
54
52
  print_dry_run @roles_interface.dry.list(account_id, params)
55
53
  return
56
54
  end
55
+ load_whoami()
57
56
  json_response = @roles_interface.list(account_id, params)
58
- roles = json_response['roles']
59
57
  if options[:json]
60
- print JSON.pretty_generate(json_response)
61
- print "\n"
58
+ puts as_json(json_response, options, "roles")
59
+ return 0
60
+ elsif options[:yaml]
61
+ puts as_yaml(json_response, options, "roles")
62
+ return 0
63
+ elsif options[:csv]
64
+ puts records_as_csv(json_response['roles'], options)
65
+ return 0
66
+ end
67
+ roles = json_response['roles']
68
+ title = "Morpheus Roles"
69
+ subtitles = []
70
+ subtitles += parse_list_subtitles(options)
71
+ print_h1 title, subtitles
72
+ if roles.empty?
73
+ print cyan,"No roles found.",reset,"\n"
62
74
  else
63
- title = "Morpheus Roles"
64
- subtitles = []
65
- if params[:phrase]
66
- subtitles << "Search: #{params[:phrase]}".strip
67
- end
68
- print_h1 title, subtitles
69
- if roles.empty?
70
- print cyan,"No roles found.",reset,"\n"
71
- else
72
- print_roles_table(roles, {is_master_account: @is_master_account})
73
- print_results_pagination(json_response)
74
- end
75
- print reset,"\n"
75
+ print_roles_table(roles, {is_master_account: @is_master_account})
76
+ print_results_pagination(json_response)
76
77
  end
78
+ print reset,"\n"
79
+ return 0
77
80
  rescue RestClient::Exception => e
78
81
  print_rest_exception(e, options)
79
82
  exit 1
@@ -82,7 +85,7 @@ class Morpheus::Cli::Roles
82
85
 
83
86
  def get(args)
84
87
  options = {}
85
- optparse = OptionParser.new do|opts|
88
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
86
89
  opts.banner = subcommand_usage("[name]")
87
90
  opts.on(nil,'--feature-access', "Display Feature Access") do |val|
88
91
  options[:include_feature_access] = true
@@ -102,13 +105,15 @@ class Morpheus::Cli::Roles
102
105
  options[:include_cloud_access] = true
103
106
  options[:include_instance_type_access] = true
104
107
  end
105
- build_common_options(opts, options, [:json, :dry_run])
108
+ build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
109
+ opts.footer = "Get details about a role.\n" +
110
+ "[name] is required. This is the name or id of a role."
106
111
  end
107
112
  optparse.parse!(args)
108
113
 
109
114
  if args.count < 1
110
115
  puts optparse
111
- exit 1
116
+ return 1
112
117
  end
113
118
 
114
119
  connect(options)
@@ -143,103 +148,110 @@ class Morpheus::Cli::Roles
143
148
  end
144
149
 
145
150
  if options[:json]
146
- print JSON.pretty_generate(json_response)
147
- print "\n"
151
+ puts as_json(json_response, options, "role")
152
+ return 0
153
+ elsif options[:yaml]
154
+ puts as_yaml(json_response, options, "role")
155
+ return 0
156
+ elsif options[:csv]
157
+ puts records_as_csv([json_response['role']], options)
158
+ return 0
159
+ end
160
+
161
+ print cyan
162
+ print_h1 "Role Details"
163
+ print cyan
164
+ description_cols = {
165
+ "ID" => 'id',
166
+ "Name" => 'authority',
167
+ "Description" => 'description',
168
+ "Scope" => lambda {|it| it['scope'] },
169
+ "Type" => lambda {|it| format_role_type(it) },
170
+ "Multitenant" => lambda {|it| format_boolean(it['multitenant']) },
171
+ "Owner" => lambda {|it| role['owner'] ? role['owner']['name'] : '' },
172
+ #"Account" => lambda {|it| it['account'] ? it['account']['name'] : '' },
173
+ "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
174
+ "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
175
+ }
176
+ print_description_list(description_cols, role)
177
+
178
+ print_h2 "Role Instance Limits"
179
+ print cyan
180
+ print_description_list({
181
+ "Max Storage" => lambda {|it| (it && it['maxStorage'].to_i != 0) ? Filesize.from("#{it['maxStorage']} B").pretty : "no limit" },
182
+ "Max Memory" => lambda {|it| (it && it['maxMemory'].to_i != 0) ? Filesize.from("#{it['maxMemory']} B").pretty : "no limit" },
183
+ "CPU Count" => lambda {|it| (it && it['maxCpu'].to_i != 0) ? it['maxCpu'] : "no limit" }
184
+ }, role['instanceLimits'])
185
+
186
+ print_h2 "Feature Access"
187
+ print cyan
188
+
189
+ if options[:include_feature_access]
190
+ rows = json_response['featurePermissions'].collect do |it|
191
+ {
192
+ code: it['code'],
193
+ name: it['name'],
194
+ access: get_access_string(it['access']),
195
+ }
196
+ end
197
+ tp rows, [:code, :name, :access]
148
198
  else
149
- print cyan
150
- print_h1 "Role Details"
151
- print cyan
152
- description_cols = {
153
- "ID" => 'id',
154
- "Name" => 'authority',
155
- "Description" => 'description',
156
- "Scope" => lambda {|it| it['scope'] },
157
- "Type" => lambda {|it| format_role_type(it) },
158
- "Multitenant" => lambda {|it| format_boolean(it['multitenant']) },
159
- "Owner" => lambda {|it| role['owner'] ? role['owner']['name'] : '' },
160
- #"Account" => lambda {|it| it['account'] ? it['account']['name'] : '' },
161
- "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
162
- "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
163
- }
164
- print_description_list(description_cols, role)
165
-
166
- print_h2 "Role Instance Limits"
167
- print cyan
168
- print_description_list({
169
- "Max Storage" => lambda {|it| (it && it['maxStorage'].to_i != 0) ? Filesize.from("#{it['maxStorage']} B").pretty : "no limit" },
170
- "Max Memory" => lambda {|it| (it && it['maxMemory'].to_i != 0) ? Filesize.from("#{it['maxMemory']} B").pretty : "no limit" },
171
- "CPU Count" => lambda {|it| (it && it['maxCpu'].to_i != 0) ? it['maxCpu'] : "no limit" }
172
- }, role['instanceLimits'])
173
-
174
- print_h2 "Feature Access"
175
- print cyan
176
-
177
- if options[:include_feature_access]
178
- rows = json_response['featurePermissions'].collect do |it|
199
+ puts "Use --feature-access to list feature access"
200
+ end
201
+
202
+ print_h2 "Group Access"
203
+ print cyan
204
+ puts "Global Group Access: #{get_access_string(json_response['globalSiteAccess'])}\n\n"
205
+ if json_response['globalSiteAccess'] == 'custom'
206
+ if options[:include_group_access]
207
+ rows = json_response['sites'].collect do |it|
179
208
  {
180
- code: it['code'],
181
209
  name: it['name'],
182
210
  access: get_access_string(it['access']),
183
211
  }
184
212
  end
185
- tp rows, [:code, :name, :access]
213
+ tp rows, [:name, :access]
186
214
  else
187
- puts "Use --feature-access to list feature access"
188
- end
189
-
190
- print_h2 "Group Access"
191
- print cyan
192
- puts "Global Group Access: #{get_access_string(json_response['globalSiteAccess'])}\n\n"
193
- if json_response['globalSiteAccess'] == 'custom'
194
- if options[:include_group_access]
195
- rows = json_response['sites'].collect do |it|
196
- {
197
- name: it['name'],
198
- access: get_access_string(it['access']),
199
- }
200
- end
201
- tp rows, [:name, :access]
202
- else
203
- puts "Use --group-access to list custom access"
204
- end
215
+ puts "Use --group-access to list custom access"
205
216
  end
217
+ end
206
218
 
207
- print_h2 "Cloud Access"
208
- print cyan
209
- puts "Global Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}\n\n"
210
- if json_response['globalZoneAccess'] == 'custom'
211
- if options[:include_cloud_access]
212
- rows = json_response['zones'].collect do |it|
213
- {
214
- name: it['name'],
215
- access: get_access_string(it['access']),
216
- }
217
- end
218
- tp rows, [:name, :access]
219
- else
220
- puts "Use --cloud-access to list custom access"
219
+ print_h2 "Cloud Access"
220
+ print cyan
221
+ puts "Global Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}\n\n"
222
+ if json_response['globalZoneAccess'] == 'custom'
223
+ if options[:include_cloud_access]
224
+ rows = json_response['zones'].collect do |it|
225
+ {
226
+ name: it['name'],
227
+ access: get_access_string(it['access']),
228
+ }
221
229
  end
230
+ tp rows, [:name, :access]
231
+ else
232
+ puts "Use --cloud-access to list custom access"
222
233
  end
234
+ end
223
235
 
224
- print_h2 "Instance Type Access"
225
- print cyan
226
- puts "Global Instance Type Access: #{get_access_string(json_response['globalInstanceTypeAccess'])}\n\n"
227
- if json_response['globalInstanceTypeAccess'] == 'custom'
228
- if options[:include_instance_type_access]
229
- rows = json_response['instanceTypePermissions'].collect do |it|
230
- {
231
- name: it['name'],
232
- access: get_access_string(it['access']),
233
- }
234
- end
235
- tp rows, [:name, :access]
236
- else
237
- puts "Use --instance-type-access to list custom access"
236
+ print_h2 "Instance Type Access"
237
+ print cyan
238
+ puts "Global Instance Type Access: #{get_access_string(json_response['globalInstanceTypeAccess'])}\n\n"
239
+ if json_response['globalInstanceTypeAccess'] == 'custom'
240
+ if options[:include_instance_type_access]
241
+ rows = json_response['instanceTypePermissions'].collect do |it|
242
+ {
243
+ name: it['name'],
244
+ access: get_access_string(it['access']),
245
+ }
238
246
  end
247
+ tp rows, [:name, :access]
248
+ else
249
+ puts "Use --instance-type-access to list custom access"
239
250
  end
240
-
241
- print reset,"\n"
242
251
  end
252
+
253
+ print reset,"\n"
254
+ return 0
243
255
  rescue RestClient::Exception => e
244
256
  print_rest_exception(e, options)
245
257
  exit 1
@@ -249,10 +261,10 @@ class Morpheus::Cli::Roles
249
261
  def add(args)
250
262
  usage = "Usage: morpheus roles add [options]"
251
263
  options = {}
252
- optparse = OptionParser.new do|opts|
264
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
253
265
  opts.banner = subcommand_usage("[options]")
254
266
  build_option_type_options(opts, options, add_role_option_types)
255
- build_common_options(opts, options, [:options, :json, :dry_run])
267
+ build_common_options(opts, options, [:options, :json, :dry_run, :remote])
256
268
  end
257
269
  optparse.parse!(args)
258
270
 
@@ -342,10 +354,10 @@ class Morpheus::Cli::Roles
342
354
  def update(args)
343
355
  usage = "Usage: morpheus roles update [name] [options]"
344
356
  options = {}
345
- optparse = OptionParser.new do|opts|
357
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
346
358
  opts.banner = subcommand_usage("[name] [options]")
347
359
  build_option_type_options(opts, options, update_role_option_types)
348
- build_common_options(opts, options, [:options, :json, :dry_run])
360
+ build_common_options(opts, options, [:options, :json, :dry_run, :remote])
349
361
  end
350
362
  optparse.parse!(args)
351
363
 
@@ -424,9 +436,9 @@ class Morpheus::Cli::Roles
424
436
  def remove(args)
425
437
  usage = "Usage: morpheus roles remove [name]"
426
438
  options = {}
427
- optparse = OptionParser.new do|opts|
439
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
428
440
  opts.banner = subcommand_usage("[name]")
429
- build_common_options(opts, options, [:auto_confirm, :json, :dry_run])
441
+ build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
430
442
  end
431
443
  optparse.parse!(args)
432
444
  if args.count < 1
@@ -465,9 +477,9 @@ class Morpheus::Cli::Roles
465
477
  def update_feature_access(args)
466
478
  usage = "Usage: morpheus roles update-feature-access [name] [code] [full|read|user|yes|no|none]"
467
479
  options = {}
468
- optparse = OptionParser.new do|opts|
480
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
469
481
  opts.banner = subcommand_usage("[name] [code] [full|read|user|yes|no|none]")
470
- build_common_options(opts, options, [:json, :dry_run])
482
+ build_common_options(opts, options, [:json, :dry_run, :remote])
471
483
  end
472
484
  optparse.parse!(args)
473
485
 
@@ -513,9 +525,9 @@ class Morpheus::Cli::Roles
513
525
  def update_global_group_access(args)
514
526
  usage = "Usage: morpheus roles update-global-group-access [name] [full|read|custom|none]"
515
527
  options = {}
516
- optparse = OptionParser.new do|opts|
528
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
517
529
  opts.banner = subcommand_usage("[name] [code] [full|read|custom|none]")
518
- build_common_options(opts, options, [:json, :dry_run])
530
+ build_common_options(opts, options, [:json, :dry_run, :remote])
519
531
  end
520
532
  optparse.parse!(args)
521
533
 
@@ -557,24 +569,48 @@ class Morpheus::Cli::Roles
557
569
  end
558
570
 
559
571
  def update_group_access(args)
560
- usage = "Usage: morpheus roles update-group-access [name] [group_name] [full|read|none]"
561
572
  options = {}
562
- optparse = OptionParser.new do|opts|
563
- opts.banner = subcommand_usage("[name] [group] [full|read|none]")
564
- build_common_options(opts, options, [:json, :dry_run])
573
+ name = nil
574
+ group_name = nil
575
+ access_value = nil
576
+ do_all = false
577
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
578
+ opts.banner = subcommand_usage("[name]")
579
+ opts.on( '-g', '--group GROUP', "Group name or id" ) do |val|
580
+ group_name = val
581
+ end
582
+ opts.on( nil, '--all', "Update all groups at once." ) do
583
+ do_all = true
584
+ end
585
+ opts.on( '--access VALUE', String, "Access value [full|read|none]" ) do |val|
586
+ access_value = val
587
+ end
588
+ build_common_options(opts, options, [:json, :dry_run, :remote])
589
+ opts.footer = "Update role access for a group or all groups.\n" +
590
+ "[name] is required. This is the name or id of a role.\n" +
591
+ "--group or --all is required. This is the name or id of a group.\n" +
592
+ "--access is required. This is the new access value."
565
593
  end
566
594
  optparse.parse!(args)
567
-
568
- if args.count < 2
595
+ if args.count < 1
569
596
  puts optparse
570
- exit 1
597
+ return 1
571
598
  end
572
599
  name = args[0]
573
- group_name = args[1]
574
- access_value = args[2].to_s.downcase
600
+ # support old usage: [name] [group] [access]
601
+ group_name ||= args[1]
602
+ access_value ||= args[2]
603
+
604
+ if (!group_name && !do_all) || !access_value
605
+ puts optparse
606
+ return 1
607
+ end
608
+
609
+ access_value = access_value.to_s.downcase
610
+
575
611
  if !['full', 'read', 'none'].include?(access_value)
576
612
  puts optparse
577
- exit 1
613
+ return 1
578
614
  end
579
615
 
580
616
  connect(options)
@@ -582,7 +618,7 @@ class Morpheus::Cli::Roles
582
618
  account = find_account_from_options(options)
583
619
  account_id = account ? account['id'] : nil
584
620
  role = find_role_by_name_or_id(account_id, name)
585
- exit 1 if role.nil?
621
+ return 1 if role.nil?
586
622
 
587
623
  role_json = @roles_interface.get(account_id, role['id'])
588
624
  if role_json['globalSiteAccess'] != 'custom'
@@ -594,11 +630,22 @@ class Morpheus::Cli::Roles
594
630
 
595
631
  # group_id = find_group_id_by_name(group_name)
596
632
  # exit 1 if group_id.nil?
597
- group = find_group_by_name(group_name)
598
- exit 1 if group.nil?
599
- group_id = group['id']
633
+ group = nil
634
+ group_id = nil
635
+ if !do_all
636
+ group = find_group_by_name(group_name)
637
+ return 1 if group.nil?
638
+ group_id = group['id']
639
+ end
600
640
 
601
- params = {groupId: group_id, access: access_value}
641
+ params = {}
642
+ if do_all
643
+ params['allGroups'] = true
644
+ else
645
+ params['groupId'] = group_id
646
+ end
647
+ params['access'] = access_value
648
+
602
649
  if options[:dry_run]
603
650
  print_dry_run @roles_interface.dry.update_group(account_id, role['id'], params)
604
651
  return
@@ -609,8 +656,13 @@ class Morpheus::Cli::Roles
609
656
  print JSON.pretty_generate(json_response)
610
657
  print "\n"
611
658
  else
612
- print_green_success "Role #{role['authority']} global group access updated"
659
+ if do_all
660
+ print_green_success "Role #{role['authority']} access updated for all groups"
661
+ else
662
+ print_green_success "Role #{role['authority']} access updated for group #{group['name']}"
663
+ end
613
664
  end
665
+ return 0
614
666
  rescue RestClient::Exception => e
615
667
  print_rest_exception(e, options)
616
668
  exit 1
@@ -620,9 +672,9 @@ class Morpheus::Cli::Roles
620
672
  def update_global_cloud_access(args)
621
673
  usage = "Usage: morpheus roles update-global-cloud-access [name] [full|custom|none]"
622
674
  options = {}
623
- optparse = OptionParser.new do|opts|
675
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
624
676
  opts.banner = subcommand_usage("[name] [full|custom|none]")
625
- build_common_options(opts, options, [:json, :dry_run])
677
+ build_common_options(opts, options, [:json, :dry_run, :remote])
626
678
  end
627
679
  optparse.parse!(args)
628
680
 
@@ -664,24 +716,50 @@ class Morpheus::Cli::Roles
664
716
  end
665
717
 
666
718
  def update_cloud_access(args)
667
- usage = "Usage: morpheus roles update-cloud-access [name] [cloud_name] [full|none]"
668
719
  options = {}
669
- optparse = OptionParser.new do|opts|
670
- opts.banner = subcommand_usage("[name] [cloud] [full|none]")
720
+ cloud_name = nil
721
+ access_value = nil
722
+ do_all = false
723
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
724
+ opts.banner = subcommand_usage("[name]")
725
+ opts.on( '-c', '--cloud CLOUD', "Cloud name or id" ) do |val|
726
+ puts "val is : #{val}"
727
+ cloud_name = val
728
+ end
729
+ opts.on( nil, '--all', "Update all clouds at once." ) do
730
+ do_all = true
731
+ end
732
+ opts.on( '--access VALUE', String, "Access value [full|read|none]" ) do |val|
733
+ access_value = val
734
+ end
671
735
  opts.on( '-g', '--group GROUP', "Group to find cloud in" ) do |val|
672
736
  options[:group] = val
673
737
  end
674
- build_common_options(opts, options, [:json, :dry_run])
738
+ build_common_options(opts, options, [:json, :dry_run, :remote])
739
+ opts.footer = "Update role access for a cloud or all clouds.\n" +
740
+ "[name] is required. This is the name or id of a role.\n" +
741
+ "--cloud or --all is required. This is the name or id of a cloud.\n" +
742
+ "--access is required. This is the new access value."
675
743
  end
676
744
  optparse.parse!(args)
677
745
 
678
- if args.count < 2
746
+ if args.count < 1
679
747
  puts optparse
680
- exit 1
748
+ return 1
681
749
  end
682
750
  name = args[0]
683
- cloud_name = args[1]
684
- access_value = args[2].to_s.downcase
751
+ # support old usage: [name] [cloud] [access]
752
+ cloud_name ||= args[1]
753
+ access_value ||= args[2]
754
+
755
+ if (!cloud_name && !do_all) || !access_value
756
+ puts optparse
757
+ return 1
758
+ end
759
+ puts "cloud_name is : #{cloud_name}"
760
+ puts "access_value is : #{access_value}"
761
+ access_value = access_value.to_s.downcase
762
+
685
763
  if !['full', 'none'].include?(access_value)
686
764
  puts optparse
687
765
  exit 1
@@ -702,21 +780,30 @@ class Morpheus::Cli::Roles
702
780
  exit 1
703
781
  end
704
782
 
783
+ # crap, group_id is needed for this api, maybe just use infrastructure or some other optionSource instead.
705
784
  group_id = nil
706
- if !options[:group].nil?
707
- group_id = find_group_id_by_name(options[:group])
708
- else
709
- group_id = @active_group_id
785
+ cloud_id = nil
786
+ if !do_all
787
+ group_id = nil
788
+ if !options[:group].nil?
789
+ group_id = find_group_id_by_name(options[:group])
790
+ else
791
+ group_id = @active_group_id
792
+ end
793
+ if group_id.nil?
794
+ print_red_alert "Group not found or specified!"
795
+ return 1
796
+ end
797
+ cloud_id = find_cloud_id_by_name(group_id, cloud_name)
798
+ return 1 if cloud_id.nil?
710
799
  end
711
-
712
- if group_id.nil?
713
- print_red_alert "Group not found or specified!"
714
- exit 1
800
+ params = {}
801
+ if do_all
802
+ params['allClouds'] = true
803
+ else
804
+ params['cloudId'] = cloud_id
715
805
  end
716
-
717
- cloud_id = find_cloud_id_by_name(group_id, cloud_name)
718
- exit 1 if cloud_id.nil?
719
- params = {cloudId: cloud_id, access: access_value}
806
+ params['access'] = access_value
720
807
  if options[:dry_run]
721
808
  print_dry_run @roles_interface.dry.update_cloud(account_id, role['id'], params)
722
809
  return
@@ -727,8 +814,13 @@ class Morpheus::Cli::Roles
727
814
  print JSON.pretty_generate(json_response)
728
815
  print "\n"
729
816
  else
730
- print_green_success "Role #{role['authority']} global cloud access updated"
817
+ if do_all
818
+ print_green_success "Role #{role['authority']} access updated for all clouds"
819
+ else
820
+ print_green_success "Role #{role['authority']} access updated for cloud id #{cloud_id}"
821
+ end
731
822
  end
823
+ return 0
732
824
  rescue RestClient::Exception => e
733
825
  print_rest_exception(e, options)
734
826
  exit 1
@@ -738,9 +830,9 @@ class Morpheus::Cli::Roles
738
830
  def update_global_instance_type_access(args)
739
831
  usage = "Usage: morpheus roles update-global-instance-type-access [name] [full|custom|none]"
740
832
  options = {}
741
- optparse = OptionParser.new do|opts|
833
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
742
834
  opts.banner = subcommand_usage("[name] [full|custom|none]")
743
- build_common_options(opts, options, [:json, :dry_run])
835
+ build_common_options(opts, options, [:json, :dry_run, :remote])
744
836
  end
745
837
  optparse.parse!(args)
746
838
 
@@ -783,24 +875,48 @@ class Morpheus::Cli::Roles
783
875
  end
784
876
 
785
877
  def update_instance_type_access(args)
786
- usage = "Usage: morpheus roles update-instance-type-access [name] [instance_type_name] [full|none]"
787
878
  options = {}
788
- optparse = OptionParser.new do|opts|
789
- opts.banner = subcommand_usage("[name] [instance-type] [full|none]")
790
- build_common_options(opts, options, [:json, :dry_run])
879
+ instance_type_name = nil
880
+ access_value = nil
881
+ do_all = false
882
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
883
+ opts.banner = subcommand_usage("[name]")
884
+ opts.on( '--instance-type INSTANCE_TYPE', String, "Instance Type name" ) do |val|
885
+ instance_type_name = val
886
+ end
887
+ opts.on( nil, '--all', "Update all instance types at once." ) do
888
+ do_all = true
889
+ end
890
+ opts.on( '--access VALUE', String, "Access value [full|read|none]" ) do |val|
891
+ access_value = val
892
+ end
893
+ build_common_options(opts, options, [:json, :dry_run, :remote])
894
+ opts.footer = "Update role access for an instance type or all instance types.\n" +
895
+ "[name] is required. This is the name or id of a role.\n" +
896
+ "--instance-type or --all is required. This is the name of an instance type.\n" +
897
+ "--access is required. This is the new access value."
791
898
  end
792
899
  optparse.parse!(args)
793
900
 
794
- if args.count < 2
901
+ if args.count < 1
795
902
  puts optparse
796
- exit 1
903
+ return 1
797
904
  end
798
905
  name = args[0]
799
- instance_type_name = args[1]
800
- access_value = args[2].to_s.downcase
906
+ # support old usage: [name] [instance-type] [access]
907
+ instance_type_name ||= args[1]
908
+ access_value ||= args[2]
909
+
910
+ if (!instance_type_name && !do_all) || !access_value
911
+ puts optparse
912
+ return 1
913
+ end
914
+
915
+ access_value = access_value.to_s.downcase
916
+
801
917
  if !['full', 'none'].include?(access_value)
802
918
  puts optparse
803
- exit 1
919
+ return 1
804
920
  end
805
921
 
806
922
  connect(options)
@@ -808,20 +924,30 @@ class Morpheus::Cli::Roles
808
924
  account = find_account_from_options(options)
809
925
  account_id = account ? account['id'] : nil
810
926
  role = find_role_by_name_or_id(account_id, name)
811
- exit 1 if role.nil?
927
+ return 1 if role.nil?
812
928
 
813
929
  role_json = @roles_interface.get(account_id, role['id'])
814
930
  if role_json['globalInstanceTypeAccess'] != 'custom'
815
931
  print "\n", red, "Global Instance Type Access is currently: #{role_json['globalInstanceTypeAccess'].capitalize}"
816
932
  print "\n", "You must first set it to Custom via `morpheus roles update-global-instance-type-access \"#{name}\" custom`"
817
933
  print "\n\n", reset
818
- exit 1
934
+ return 1
819
935
  end
820
936
 
821
- instance_type = find_instance_type_by_name(instance_type_name)
822
- exit 1 if instance_type.nil?
937
+ instance_type = nil
938
+ if !do_all
939
+ instance_type = find_instance_type_by_name(instance_type_name)
940
+ return 1 if instance_type.nil?
941
+ end
942
+
943
+ params = {}
944
+ if do_all
945
+ params['allInstanceTypes'] = true
946
+ else
947
+ params['instanceTypeId'] = instance_type['id']
948
+ end
949
+ params['access'] = access_value
823
950
 
824
- params = {instanceTypeId: instance_type['id'], access: access_value}
825
951
  if options[:dry_run]
826
952
  print_dry_run @roles_interface.dry.update_instance_type(account_id, role['id'], params)
827
953
  return
@@ -832,8 +958,13 @@ class Morpheus::Cli::Roles
832
958
  print JSON.pretty_generate(json_response)
833
959
  print "\n"
834
960
  else
835
- print_green_success "Role #{role['authority']} global instance type access updated"
961
+ if do_all
962
+ print_green_success "Role #{role['authority']} access updated for all instance types"
963
+ else
964
+ print_green_success "Role #{role['authority']} access updated for instance type #{instance_type['name']}"
965
+ end
836
966
  end
967
+ return 0
837
968
  rescue RestClient::Exception => e
838
969
  print_rest_exception(e, options)
839
970
  exit 1
@@ -903,7 +1034,7 @@ class Morpheus::Cli::Roles
903
1034
  end
904
1035
 
905
1036
  def find_instance_type_by_name(name)
906
- results = @instance_types_interface.get({name: name})
1037
+ results = @instance_types_interface.list({name: name})
907
1038
  if results['instanceTypes'].empty?
908
1039
  print_red_alert "Instance Type not found by name #{name}"
909
1040
  return nil
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "3.4.1.2"
4
+ VERSION = "3.4.1.3"
5
5
  end
6
6
  end
@@ -657,7 +657,7 @@ class Morpheus::Cli::VirtualImages
657
657
  {'fieldName' => 'osType', 'fieldLabel' => 'OS Type', 'type' => 'select', 'optionSource' => 'osTypes', 'required' => false, 'description' => 'Select OS Type.', 'displayOrder' => 3},
658
658
  {'fieldName' => 'minRam', 'fieldLabel' => 'Minimum Memory (MB)', 'type' => 'number', 'required' => false, 'description' => 'Minimum Memory (MB)', 'displayOrder' => 4},
659
659
  {'fieldName' => 'isCloudInit', 'fieldLabel' => 'Cloud Init Enabled?', 'type' => 'checkbox', 'required' => false, 'description' => 'Cloud Init Enabled?', 'displayOrder' => 4},
660
- {'fieldName' => 'installAgent', 'fieldLabel' => 'Install Agent?', 'type' => 'checkbox', 'required' => false, 'description' => 'Cloud Init Enabled?', 'displayOrder' => 4},
660
+ {'fieldName' => 'installAgent', 'fieldLabel' => 'Install Agent?', 'type' => 'checkbox', 'required' => false, 'description' => 'Install Agent?', 'displayOrder' => 4},
661
661
  {'fieldName' => 'sshUsername', 'fieldLabel' => 'SSH Username', 'type' => 'text', 'required' => false, 'description' => 'Enter an SSH Username', 'displayOrder' => 5},
662
662
  {'fieldName' => 'sshPassword', 'fieldLabel' => 'SSH Password', 'type' => 'password', 'required' => false, 'description' => 'Enter an SSH Password', 'displayOrder' => 6},
663
663
  {'fieldName' => 'storageProviderId', 'type' => 'select', 'fieldLabel' => 'Storage Provider', 'optionSource' => 'storageProviders', 'required' => false, 'description' => 'Select Storage Provider.', 'displayOrder' => 7},
@@ -77,27 +77,56 @@ class Morpheus::Cli::Workflows
77
77
 
78
78
  def add(args)
79
79
  options = {}
80
+ params = {}
81
+ task_arg_list = nil
80
82
  optparse = OptionParser.new do|opts|
81
- opts.banner = subcommand_usage("[name] --tasks x,y,z")
82
- opts.on("--tasks x,y,z", Array, "List of tasks to run in order") do |list|
83
- options[:task_names] = list
83
+ opts.banner = subcommand_usage("[name] --tasks taskId:phase,taskId2:phase,taskId3:phase")
84
+ opts.on("--name NAME", String, "Name for workflow") do |val|
85
+ params['name'] = val
84
86
  end
85
- build_common_options(opts, options, [:options, :json, :dry_run, :quiet, :remote])
87
+ opts.on("--tasks x,y,z", Array, "List of tasks to run in order, in the format <Task ID>:<Task Phase> Task Phase is optional, the default is 'provision'.") do |list|
88
+ task_arg_list = []
89
+ list.each do |it|
90
+ task_id, task_phase = it.split(":")
91
+ task_arg_list << {task_id: task_id.to_s.strip, task_phase: task_phase.to_s.strip}
92
+ end
93
+ end
94
+ build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
86
95
  end
87
96
  optparse.parse!(args)
88
- if args.count < 1 || options[:task_names].empty?
89
- puts optparse
90
- exit 1
91
- end
92
- workflow_name = args[0]
97
+
93
98
  connect(options)
94
99
  begin
95
- tasks = []
96
- options[:task_names].each do |task_name|
97
- tasks << find_task_by_name_or_id(task_name.to_s.strip)['id']
100
+ payload = nil
101
+ if options[:payload]
102
+ payload = options[:payload]
103
+ else
104
+ if args[0] && !params['name']
105
+ params['name'] = args[0]
106
+ end
107
+ if (!params['name'] || task_arg_list.nil?)
108
+ puts optparse
109
+ return 1
110
+ end
111
+ tasks = []
112
+ if task_arg_list
113
+ task_arg_list.each do |task_arg|
114
+ found_task = find_task_by_name_or_id(task_arg[:task_id])
115
+ return 1 if found_task.nil?
116
+ row = {'taskId' => found_task['id']}
117
+ if !task_arg[:task_phase].to_s.strip.empty?
118
+ row['taskPhase'] = task_arg[:task_phase]
119
+ end
120
+ tasks << row
121
+ end
122
+ end
123
+ payload = {'taskSet' => {}}
124
+ params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
125
+ payload['taskSet'].deep_merge!(params)
126
+ if !tasks.empty?
127
+ payload['taskSet']['tasks'] = tasks
128
+ end
98
129
  end
99
-
100
- payload = {taskSet: {name: workflow_name, tasks: tasks}}
101
130
  if options[:dry_run]
102
131
  print_dry_run @task_sets_interface.dry.create(payload)
103
132
  return
@@ -200,7 +229,7 @@ class Morpheus::Cli::Workflows
200
229
  print cyan
201
230
  puts as_pretty_table(tasks, task_set_task_columns)
202
231
  end
203
- print reset,"\n"
232
+ print reset
204
233
  end
205
234
  rescue RestClient::Exception => e
206
235
  print_rest_exception(e, options)
@@ -210,18 +239,24 @@ class Morpheus::Cli::Workflows
210
239
 
211
240
  def update(args)
212
241
  options = {}
242
+ params = {}
243
+ task_arg_list = nil
213
244
  optparse = OptionParser.new do|opts|
214
- opts.banner = subcommand_usage("[name] --tasks x,y,z")
215
- opts.on("--tasks x,y,z", Array, "New list of tasks to run in order") do |list|
216
- options[:task_names]= list
245
+ opts.banner = subcommand_usage("[name] --tasks taskId:phase,taskId2:phase,taskId3:phase")
246
+ opts.on("--tasks x,y,z", Array, "New list of tasks to run in the format <Task ID>:<Phase>. Phase is optional, the default is 'provision'.") do |list|
247
+ task_arg_list = []
248
+ list.each do |it|
249
+ task_id, task_phase = it.split(":")
250
+ task_arg_list << {task_id: task_id.to_s.strip, task_phase: task_phase.to_s.strip}
251
+ end
217
252
  end
218
253
  opts.on("--name NAME", String, "New name for workflow") do |val|
219
- options[:new_name] = val
254
+ params['name'] = val
220
255
  end
221
- build_common_options(opts, options, [:json, :dry_run, :quiet, :remote])
256
+ build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
222
257
  end
223
258
  optparse.parse!(args)
224
- if args.count < 1 || (options[:new_name].empty? && options[:task_names].empty?)
259
+ if args.count < 1
225
260
  puts optparse
226
261
  exit 1
227
262
  end
@@ -229,18 +264,29 @@ class Morpheus::Cli::Workflows
229
264
  connect(options)
230
265
  begin
231
266
  workflow = find_workflow_by_name_or_id(workflow_name)
232
- payload = {taskSet: {id: workflow['id']} }
233
- tasks = []
234
- if options[:task_names]
235
- options[:task_names].each do |task_name|
236
- tasks << find_task_by_name_or_id(task_name)['id']
237
- end
238
- payload[:taskSet][:tasks] = tasks
267
+ return 1 if workflow.nil?
268
+ payload = nil
269
+ if options[:payload]
270
+ payload = options[:payload]
239
271
  else
240
- payload[:taskSet][:tasks] = workflow['tasks']
241
- end
242
- if options[:new_name]
243
- payload[:taskSet][:name] = options[:new_name]
272
+ tasks = []
273
+ if task_arg_list
274
+ task_arg_list.each do |task_arg|
275
+ found_task = find_task_by_name_or_id(task_arg[:task_id])
276
+ return 1 if found_task.nil?
277
+ row = {'taskId' => found_task['id']}
278
+ if !task_arg[:task_phase].to_s.strip.empty?
279
+ row['taskPhase'] = task_arg[:task_phase]
280
+ end
281
+ tasks << row
282
+ end
283
+ end
284
+ payload = {'taskSet' => {}}
285
+ params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
286
+ payload['taskSet'].deep_merge!(params)
287
+ if !tasks.empty?
288
+ payload['taskSet']['tasks'] = tasks
289
+ end
244
290
  end
245
291
  if options[:dry_run]
246
292
  print_dry_run @task_sets_interface.dry.update(workflow['id'], payload)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpheus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1.2
4
+ version: 3.4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Estes
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-06-18 00:00:00.000000000 Z
14
+ date: 2018-07-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler