morpheus-cli 4.1.3 → 4.1.4

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
  SHA256:
3
- metadata.gz: b5b4dd8489e5b1b5ba7161972495bafb0267a735718da283fbfd9cb4c1013955
4
- data.tar.gz: 9206c9bd953acc94ef919078f52136068e58716ccbf083abe4afa903ce0fd08c
3
+ metadata.gz: b4dacc032b0f2cb81ba8c3941c374298747f2c8d75ab3307382b9f95e7247df6
4
+ data.tar.gz: 9aa05d08d822f72fb7c3c93c6fc34154390f4073f32b4157e7503329a4a4b868
5
5
  SHA512:
6
- metadata.gz: 413a0d0b72fedc846244a85d06ba92792e6bbde16c27c8f8ce8aaaae7d5dab461640898c121d6bdeaf020640fa833306032a58e4ad3858726c8ee2e47d8244ac
7
- data.tar.gz: aa77f2f657cb7a3842c696df46668b5416d29f703976ace1018dc8f726e9c79be2df9283f92c4099c86b3e4d27b9032e1a1a63a6b981bbeaf95b3a79ecc5adc7
6
+ metadata.gz: 5e63a7b794f281f737b86fea28c5d220875b8e2d30c802fb099fb7e2be0516e6c8afbb4a6ab6cc209421adf3adbba2d64c3f5cc28d525cd35174569837c9c360
7
+ data.tar.gz: 0eac4da8d373956f7468923d25efb8e5010ce107beeafc6cf9355f8efd9648cb4efedf43be0feeae80b3123dd20f0bad561343ec59f6d6896ea6214423960e3b
@@ -593,9 +593,9 @@ class Morpheus::Cli::BlueprintsCommand
593
593
  end
594
594
  optparse.parse!(args)
595
595
 
596
- if args.count < 1
596
+ if args.count < 1 || args.count > 3
597
597
  print_error Morpheus::Terminal.angry_prompt
598
- puts_error "#{command_name} add-instance expects 3 arguments and received #{args.count}: #{args}\n#{optparse}"
598
+ puts_error "#{command_name} add-instance expects 2-3 arguments and received #{args.count}: #{args}\n#{optparse}"
599
599
  return 1
600
600
  end
601
601
 
@@ -635,13 +635,9 @@ class Morpheus::Cli::BlueprintsCommand
635
635
  end
636
636
  tier_config = tiers[tier_name]
637
637
 
638
+ instance_config = {'instance' => {'type' => instance_type['code']} }
638
639
  tier_config['instances'] ||= []
639
- instance_config = tier_config['instances'].find {|it| it["instance"] && it["instance"]["type"] && it["instance"]["type"] == instance_type["code"] }
640
- if !instance_config
641
- instance_config = {'instance' => {'type' => instance_type['code']} }
642
- tier_config['instances'].push(instance_config)
643
- end
644
- instance_config['instance'] ||= {}
640
+ tier_config['instances'].push(instance_config)
645
641
 
646
642
  # just prompts for Instance Name (optional)
647
643
  instance_name = nil
@@ -680,9 +676,11 @@ class Morpheus::Cli::BlueprintsCommand
680
676
  if !options[:no_prompt]
681
677
  if ::Morpheus::Cli::OptionTypes::confirm("Would you like to add a config now?", options.merge({default: true}))
682
678
  # todo: this needs to work by index, because you can have multiple instances of the same type
683
- add_instance_config([blueprint['id'], tier_name, instance_type['code']])
679
+ # instance_identifier = instance_config['instance']['name'] # instance_type['code']
680
+ instance_identifier = tier_config['instances'].size - 1
681
+ add_instance_config([blueprint['id'], tier_name, instance_identifier])
684
682
  while ::Morpheus::Cli::OptionTypes::confirm("Add another config?", options.merge({default: false})) do
685
- add_instance_config([blueprint['id'], tier_name, instance_type['code']])
683
+ add_instance_config([blueprint['id'], tier_name, instance_identifier])
686
684
  end
687
685
  else
688
686
  # print details
@@ -736,15 +734,13 @@ class Morpheus::Cli::BlueprintsCommand
736
734
 
737
735
  blueprint_name = args[0]
738
736
  tier_name = args[1]
739
- instance_type_code = args[2]
740
- # we also need consider when there is multiple instances of the same type in
741
- # a template/tier.. so maybe split instance_type_code as [type-code]:[index].. or...errr
737
+ instance_identifier = args[2]
742
738
 
743
739
  blueprint = find_blueprint_by_name_or_id(blueprint_name)
744
740
  return 1 if blueprint.nil?
745
741
 
746
- instance_type = find_instance_type_by_code(instance_type_code)
747
- return 1 if instance_type.nil?
742
+ # instance_type = find_instance_type_by_code(instance_type_code)
743
+ # return 1 if instance_type.nil?
748
744
 
749
745
  tier_config = nil
750
746
  instance_config = nil
@@ -757,20 +753,38 @@ class Morpheus::Cli::BlueprintsCommand
757
753
  tiers[tier_name] = {}
758
754
  end
759
755
  tier_config = tiers[tier_name]
760
-
761
756
  tier_config['instances'] ||= []
762
- instance_config = tier_config['instances'].find {|it| it["instance"] && it["instance"]["type"] && it["instance"]["type"] == instance_type["code"] }
763
- if !instance_config
764
- instance_config = {'instance' => {'type' => instance_type['code']} }
765
- tier_config['instances'].push(instance_config)
757
+ matching_instance_configs = []
758
+ if tier_config['instances']
759
+ if instance_identifier.to_s =~ /\A\d{1,}\Z/
760
+ matching_instance_configs = [tier_config['instances'][instance_identifier.to_i]].compact
761
+ else
762
+ tier_config['instances'] ||= []
763
+ matching_instance_configs = []
764
+ matching_instance_configs = (tier_config['instances'] || []).select {|instance_config| instance_config['instance'] && instance_config['instance']['name'] == instance_identifier }
765
+ if matching_instance_configs.empty?
766
+ matching_instance_configs = (tier_config['instances'] || []).select {|instance_config| instance_config['instance'] && instance_config['instance']['type'].to_s.downcase == instance_identifier.to_s.downcase }
767
+ end
768
+ end
769
+ end
770
+
771
+ if matching_instance_configs.size == 0
772
+ print_red_alert "Instance not found by tier: #{tier_name}, type: #{instance_identifier}"
773
+ return 1
774
+ elsif matching_instance_configs.size > 1
775
+ #print_error Morpheus::Terminal.angry_prompt
776
+ print_red_alert "More than one instance found by tier: #{tier_name}, type: #{instance_identifier}"
777
+ puts_error "Try passing the name or index to identify the instance you wish to add a config to."
778
+ puts_error optparse
779
+ return 1
766
780
  end
767
- instance_config['instance'] ||= {}
781
+
782
+ instance_config = matching_instance_configs[0]
768
783
 
769
784
  # group prompt
770
785
 
771
786
  # use active group by default
772
- options[:group] ||= @active_group_id
773
-
787
+ #options[:group] ||= @active_group_id
774
788
 
775
789
  # available_groups = get_available_groups()
776
790
  # group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'fieldLabel' => 'Group', 'type' => 'select', 'selectOptions' => get_available_groups(), 'required' => true, 'defaultValue' => @active_group_id}],options[:options],@api_client,{})
@@ -785,7 +799,7 @@ class Morpheus::Cli::BlueprintsCommand
785
799
  # look for existing config for group + cloud
786
800
 
787
801
  options[:name_required] = false
788
- options[:instance_type_code] = instance_type["code"]
802
+ options[:instance_type_code] = instance_config['instance']['type'] #instance_type["code"]
789
803
 
790
804
  #options[:options].deep_merge!(specific_config)
791
805
  # this provisioning helper method handles all (most) of the parsing and prompting
@@ -866,12 +880,12 @@ class Morpheus::Cli::BlueprintsCommand
866
880
  opts.footer = "Update a blueprint, removing a specified instance config." + "\n" +
867
881
  "[id] is required. This is the name or id of a blueprint." + "\n" +
868
882
  "[tier] is required. This is the name of the tier." + "\n" +
869
- "[instance] is required. This is the type of instance." + "\n" +
883
+ "[instance] is required. This is the instance identifier, which may be the type, the name, or the index (starting with 0." + "\n" +
870
884
  "The config scope is specified with the -g GROUP, -c CLOUD and -e ENV. The -g and -c options are required."
871
885
  end
872
886
  optparse.parse!(args)
873
887
 
874
- if args.count < 3
888
+ if args.count != 3
875
889
  print_error Morpheus::Terminal.angry_prompt
876
890
  puts_error "Wrong number of arguments"
877
891
  puts_error optparse
@@ -885,7 +899,7 @@ class Morpheus::Cli::BlueprintsCommand
885
899
  end
886
900
  if !options[:cloud]
887
901
  print_error Morpheus::Terminal.angry_prompt
888
- puts_error "Missing required argument -g CLOUD"
902
+ puts_error "Missing required argument -c CLOUD"
889
903
  puts_error optparse
890
904
  return 1
891
905
  end
@@ -895,15 +909,13 @@ class Morpheus::Cli::BlueprintsCommand
895
909
 
896
910
  blueprint_name = args[0]
897
911
  tier_name = args[1]
898
- instance_type_code = args[2]
899
- # we also need consider when there is multiple instances of the same type in
900
- # a template/tier.. so maybe split instance_type_code as [type-code]:[index].. or...errr
912
+ instance_identifier = args[2]
901
913
 
902
914
  blueprint = find_blueprint_by_name_or_id(blueprint_name)
903
915
  return 1 if blueprint.nil?
904
916
 
905
- instance_type = find_instance_type_by_code(instance_type_code)
906
- return 1 if instance_type.nil?
917
+ # instance_type = find_instance_type_by_code(instance_type_code)
918
+ # return 1 if instance_type.nil?
907
919
 
908
920
  tier_config = nil
909
921
  # instance_config = nil
@@ -928,25 +940,27 @@ class Morpheus::Cli::BlueprintsCommand
928
940
 
929
941
  matching_indices = []
930
942
  if tier_config['instances']
931
- if instance_index
932
- matching_indices = [instance_index].compact
943
+ if instance_identifier.to_s =~ /\A\d{1,}\Z/
944
+ matching_indices = [instance_identifier.to_i].compact
933
945
  else
934
946
  tier_config['instances'].each_with_index do |instance_config, index|
935
- is_match = instance_config['instance'] && instance_config['instance']['type'] == instance_type['code']
936
- if is_match
947
+ if instance_config['instance'] && instance_config['instance']['type'].to_s.downcase == instance_identifier.to_s.downcase
948
+ matching_indices << index
949
+ elsif instance_config['instance'] && instance_config['instance']['name'] == instance_identifier
937
950
  matching_indices << index
938
951
  end
939
952
  end
940
953
  end
941
954
  end
942
955
 
956
+
943
957
  if matching_indices.size == 0
944
- print_red_alert "Instance not found by tier: #{tier_name}, type: #{instance_type_code}"
958
+ print_red_alert "Instance not found by tier: #{tier_name}, type: #{instance_identifier}"
945
959
  return 1
946
960
  elsif matching_indices.size > 1
947
961
  #print_error Morpheus::Terminal.angry_prompt
948
- print_red_alert "More than one instance found by tier: #{tier_name}, type: #{instance_type_code}"
949
- puts_error "Try using the --index option to identify the instance you wish to remove."
962
+ print_red_alert "More than one instance found by tier: #{tier_name}, type: #{instance_identifier}"
963
+ puts_error "Try passing the name or index to identify the instance you wish to remove."
950
964
  puts_error optparse
951
965
  return 1
952
966
  end
@@ -957,7 +971,7 @@ class Morpheus::Cli::BlueprintsCommand
957
971
  current_config = instance_config
958
972
  delete_key = nil
959
973
 
960
- config_description = "type: #{instance_type['code']}"
974
+ config_description = "type: #{instance_identifier}"
961
975
  config_description << " environment: #{options[:environment]}" if options[:environment]
962
976
  config_description << " group: #{options[:group]}" if options[:group]
963
977
  config_description << " cloud: #{options[:cloud]}" if options[:cloud]
@@ -1046,10 +1060,15 @@ class Morpheus::Cli::BlueprintsCommand
1046
1060
  # instance_index = val.to_i
1047
1061
  # end
1048
1062
  build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
1063
+ opts.footer = "Update a blueprint, removing a specified instance." + "\n" +
1064
+ "[id] is required. This is the name or id of a blueprint." + "\n" +
1065
+ "[tier] is required. This is the name of the tier." + "\n" +
1066
+ "[instance] is required. This is the instance identifier, which may be the type, the name, or the index (starting with 0."
1049
1067
  end
1068
+
1050
1069
  optparse.parse!(args)
1051
1070
 
1052
- if args.count < 3
1071
+ if args.count != 3
1053
1072
  print_error Morpheus::Terminal.angry_prompt
1054
1073
  puts_error "Wrong number of arguments"
1055
1074
  puts_error optparse
@@ -1062,7 +1081,7 @@ class Morpheus::Cli::BlueprintsCommand
1062
1081
 
1063
1082
  blueprint_name = args[0]
1064
1083
  tier_name = args[1]
1065
- instance_identier = args[2]
1084
+ instance_identifier = args[2]
1066
1085
 
1067
1086
  # instance_type_code = args[2]
1068
1087
  # we also need consider when there is multiple instances of the same type in
@@ -1095,25 +1114,25 @@ class Morpheus::Cli::BlueprintsCommand
1095
1114
  # find instance
1096
1115
  matching_indices = []
1097
1116
  if tier_config['instances']
1098
- if instance_identier.to_s =~ /\A\d{1,}\Z/
1099
- matching_indices = [instance_identier.to_i].compact
1117
+ if instance_identifier.to_s =~ /\A\d{1,}\Z/
1118
+ matching_indices = [instance_identifier.to_i].compact
1100
1119
  else
1101
1120
  tier_config['instances'].each_with_index do |instance_config, index|
1102
- if instance_config['instance'] && instance_config['instance']['type'] == instance_identier
1121
+ if instance_config['instance'] && instance_config['instance']['type'].to_s.downcase == instance_identifier.to_s.downcase
1103
1122
  matching_indices << index
1104
- elsif instance_config['instance'] && instance_config['instance']['name'] == instance_identier
1123
+ elsif instance_config['instance'] && instance_config['instance']['name'] == instance_identifier
1105
1124
  matching_indices << index
1106
1125
  end
1107
1126
  end
1108
1127
  end
1109
1128
  end
1110
1129
  if matching_indices.size == 0
1111
- print_red_alert "Instance not found by tier: #{tier_name}, instance: #{instance_identier}"
1130
+ print_red_alert "Instance not found by tier: #{tier_name}, instance: #{instance_identifier}"
1112
1131
  return 1
1113
1132
  elsif matching_indices.size > 1
1114
1133
  #print_error Morpheus::Terminal.angry_prompt
1115
- print_red_alert "More than one instance matched tier: #{tier_name}, instance: #{instance_identier}"
1116
- puts_error "Instance can be identified type, name or index within the tier."
1134
+ print_red_alert "More than one instance matched tier: #{tier_name}, instance: #{instance_identifier}"
1135
+ puts_error "Try passing the name or index to identify the instance you wish to remove."
1117
1136
  puts_error optparse
1118
1137
  return 1
1119
1138
  end
@@ -1121,7 +1140,7 @@ class Morpheus::Cli::BlueprintsCommand
1121
1140
  # remove it
1122
1141
  tier_config['instances'].delete_at(matching_indices[0])
1123
1142
 
1124
- unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete this instance #{instance_type_code} instance from tier: #{tier_name}?")
1143
+ unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete this instance #{instance_identifier} instance from tier: #{tier_name}?")
1125
1144
  return 9
1126
1145
  end
1127
1146
 
@@ -2104,7 +2123,7 @@ class Morpheus::Cli::BlueprintsCommand
2104
2123
  puts " * #{config_description}"
2105
2124
  end
2106
2125
  else
2107
- print white," Instance has no configs, see `app-templates add-instance-config \"#{blueprint['name']}\" \"#{tier_name}\" \"#{instance_type_code}\"`",reset,"\n"
2126
+ print white," Instance has no configs, use `blueprints add-instance-config \"#{blueprint['name']}\" \"#{tier_name}\" \"#{instance_name.to_s.empty? ? instance_type_code : instance_name}\"`",reset,"\n"
2108
2127
  end
2109
2128
  rescue => err
2110
2129
  #puts_error "Failed to parse instance scoped instance configs for blueprint #{blueprint['id']} #{blueprint['name']} Exception: #{err.class} #{err.message}"
@@ -2124,7 +2143,7 @@ class Morpheus::Cli::BlueprintsCommand
2124
2143
  end
2125
2144
 
2126
2145
  else
2127
- print white," Tier is empty, see `app-templates add-instance \"#{blueprint['name']}\" \"#{tier_name}\"`",reset,"\n"
2146
+ print white," Tier is empty, use `blueprints add-instance \"#{blueprint['name']}\" \"#{tier_name}\"`",reset,"\n"
2128
2147
  end
2129
2148
  # print "\n"
2130
2149
 
@@ -2132,7 +2151,7 @@ class Morpheus::Cli::BlueprintsCommand
2132
2151
  # print "\n"
2133
2152
 
2134
2153
  else
2135
- print white,"\nTemplate is empty, see `app-templates add-tier \"#{blueprint['name']}\"`",reset,"\n"
2154
+ print white,"\nTemplate is empty, use `blueprints add-tier \"#{blueprint['name']}\"`",reset,"\n"
2136
2155
  end
2137
2156
  end
2138
2157
 
@@ -255,6 +255,7 @@ module Morpheus::Cli::ProvisioningHelper
255
255
  print reset # clear colors
256
256
  options[:options] ||= {}
257
257
  # Group
258
+ default_group = @active_group_id ? find_group_by_name_or_id_for_provisioning(@active_group_id) : nil
258
259
  group_id = nil
259
260
  group = options[:group] ? find_group_by_name_or_id_for_provisioning(options[:group]) : nil
260
261
  if group
@@ -262,7 +263,7 @@ module Morpheus::Cli::ProvisioningHelper
262
263
  else
263
264
  # print_red_alert "Group not found or specified!"
264
265
  # exit 1
265
- 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,{})
266
+ group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group', 'selectOptions' => get_available_groups(), 'required' => true, 'description' => 'Select Group.', 'defaultValue' => (default_group ? default_group['name'] : nil)}],options[:options],api_client,{})
266
267
  group_id = group_prompt['group']
267
268
  end
268
269
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "4.1.3"
4
+ VERSION = "4.1.4"
5
5
  end
6
6
  end
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: 4.1.3
4
+ version: 4.1.4
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: 2019-10-14 00:00:00.000000000 Z
14
+ date: 2019-10-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler