@@ -26,22 +26,24 @@ def create_stack(template, stack_name, parameters)
2626 stack_name : stack_name ,
2727 parameters : parameters ,
2828 disable_rollback : true ) . stack_id
29- puts "Creating stack #{ stack_name } (#{ stack_id } )"
29+
30+ printf "%-30s : %s\n " , Rainbow ( "CREATING STACK" ) . white . underline , stack_name
31+ printf "%-30s : %s\n " , Rainbow ( "STACK ID" ) . white . underline , stack_id
3032
3133 stack = @cf . describe_stacks ( stack_name : stack_id ) . stacks . pop
32- while stack and stack . stack_status == CREATE_IN_PROGRESS
34+ while stack and stack . stack_status == STATUS [ :CIP ]
3335 sleep 30
3436 stack = @cf . describe_stacks ( stack_name : stack_id ) . stacks . pop
3537 puts stack . stack_status
3638 end
3739
38- if stack . stack_status == CREATE_COMPLETE
40+ if stack . stack_status == STATUS [ :CC ]
3941 output = stack . outputs . pop
4042 if output
41- return output . output_value
43+ return Rainbow ( " #{ output . output_value } " ) . green
4244 end
4345 else
44- puts "Stack creation failed ( #{ stack . stack_status } )"
46+ printf "%-30s : %s \n " , Rainbow ( "CREATE_FAILED" ) . red , stack . stack_status
4547 end
4648 rescue Aws ::CloudFormation ::Errors ::ServiceError => e
4749 puts e . message
@@ -50,30 +52,34 @@ def create_stack(template, stack_name, parameters)
5052
5153 def delete_stack ( stack_name )
5254 begin
53- puts "Deleting stack #{ stack_name } "
5455 resp = @cf . describe_stacks ( stack_name : stack_name )
5556 stack_id = resp . stacks . pop . stack_id
5657 @cf . delete_stack ( stack_name : stack_name )
5758 stack = @cf . describe_stacks ( stack_name : stack_id ) . stacks . pop
58- while stack and stack . stack_status == DELETE_IN_PROGRESS
59+ while stack and stack . stack_status == STATUS [ :DIP ]
5960 sleep 30
6061 stack = @cf . describe_stacks ( stack_name : stack_id ) . stacks . pop
61- puts stack . stack_status
62+ puts Rainbow ( stack . stack_status ) . white
6263 end
63- puts "Stack #{ stack_name } deleted: #{ stack_id } "
64+ printf "%-30s : %s\n " , Rainbow ( "STACK DELETED" ) . green , stack_name
65+ printf "%-30s : %s\n " , Rainbow ( "STACK ID" ) . green , stack_id
6466 rescue Aws ::CloudFormation ::Errors ::ValidationError => e
6567 puts e . message
6668 end
6769 end
6870
6971
7072 def list_stacks
71- resp = @cf . list_stacks
72- stacks = resp . stack_summaries . select { |stack | stack . stack_status != DELETE_COMPLETE }
73+ resp = @cf . list_stacks . stack_summaries
74+ stacks = resp . select { |stack | stack . stack_status != STATUS [ :DC ] }
7375 stacks . each do |stack |
74- puts "#{ Rainbow ( stack . stack_status ) . red . bright } : #{ stack . stack_name } " if stack . stack_status . match ( 'FAILED' )
75- puts "#{ Rainbow ( stack . stack_status ) . green . bright } : #{ stack . stack_name } " if stack . stack_status . match ( 'CREATE_COMPLETE' )
76- puts "#{ Rainbow ( stack . stack_status ) . blue . bright } : #{ stack . stack_name } " if stack . stack_status . match ( 'UPDATE_COMPLETE' )
76+ if stack . stack_status . match ( STATUS [ :CF ] )
77+ printf ( "%-30s : %s\n " , Rainbow ( stack . stack_status ) . red , stack . stack_name )
78+ elsif stack . stack_status . match ( STATUS [ :CC ] )
79+ printf ( "%-30s : %s\n " , Rainbow ( stack . stack_status ) . green , stack . stack_name )
80+ elsif stack . stack_status . match ( STATUS [ :UC ] )
81+ printf ( "%-30s : %s\n " , Rainbow ( stack . stack_status ) . blue , stack . stack_name )
82+ end
7783 end
7884 end
7985
@@ -93,32 +99,38 @@ def print_resources(resources)
9399 end
94100
95101 def print_desc ( stack )
96- puts " \n Name: #{ stack . stack_name } "
97- puts "ID: #{ stack . stack_id } "
98- puts "Description: #{ stack . description } "
99- puts " Creation Time: #{ stack . creation_time } "
100- puts "Status: #{ stack . stack_status } "
102+ printf "%-30s : %s \n " , Rainbow ( "Name" ) . white , stack . stack_name
103+ printf "%-30s : %s \n " , Rainbow ( "ID" ) . white , stack . stack_id
104+ printf "%-30s : %s \n " , Rainbow ( "Description" ) . white , stack . description
105+ printf "%-30s : %s \n " , Rainbow ( " Creation Time" ) . white , stack . creation_time
106+ printf "%-30s : %s \n " , Rainbow ( "Status" ) . white , stack . stack_status
101107
102108 if not stack . tags . empty?
103- puts "\n Tags:"
104- stack . tags . each { |tag | puts "\t #{ tag [ :key ] } :\t #{ tag [ :value ] } " }
109+ printf "%-30s :\n " , Rainbow ( "Tags" ) . white
110+ stack . tags . each do |tag |
111+ printf "\t %-30s : %s\n " , Rainbow ( tag [ :key ] ) . white , tag [ :value ]
112+ end
105113 end
106114
107- puts "\n Parameters:" unless stack . parameters . empty?
108- stack . parameters . each do |param |
109- puts "\t #{ param . parameter_key } :\t #{ param . parameter_value } "
115+ if not stack . parameters . empty?
116+ printf "%-30s :\n " , Rainbow ( "Parameters" ) . white
117+ stack . parameters . each do |param |
118+ printf "\t %-40s : %s\n " , Rainbow ( param . parameter_key ) . white , param . parameter_value
119+ end
110120 end
111121
112- puts "\n Outputs:" unless stack . outputs . empty?
113- stack . outputs . each do |out |
114- puts "\t #{ out . output_key } : #{ out . output_value } \t -- #{ out . description } "
122+ if not stack . outputs . empty?
123+ printf "%-30s :\n " , Rainbow ( "Outputs" ) . white
124+ stack . outputs . each do |out |
125+ printf "\t %-30s : %30s -- %s\n " , Rainbow ( out . output_key ) . white , out . output_value , out . description
126+ end
115127 end
116128 end
117129
118130 def describe_stack ( stack_name )
119131 begin
120132 @cf . describe_stacks ( stack_name : stack_name ) . stacks . each do |stack |
121- if stack . stack_status != DELETE_COMPLETE
133+ if stack . stack_status != STATUS [ :DC ]
122134 print_desc ( stack )
123135 if @options [ :verbose ]
124136 puts "\n "
@@ -295,50 +307,8 @@ def self.dump_stack_params(options)
295307 end
296308 end
297309
298- def self . configure ( location )
299- puts "config file location: #{ CONFIG_FILE } "
300- config = YAML . load_file ( CONFIG_FILE )
301- if !config
302- puts "Make sure your ~/.restacker/restacker.yml file is configured. \n
303- See source/restacker-sample.yml for example."
304- exit ( 1 )
305- end
306- target = config . fetch ( location , { } ) . fetch ( :target )
307-
308- new_account_number , new_role_name , new_role_prefix = ""
309-
310- old_account_number = target [ :account_number ] . to_s
311- # old_account_number[0...7] = "********"
312-
313- print "Label [\" #{ target [ :label ] } \" ]: "
314- new_label = gets . chomp
315-
316- loop do
317- print "Account Number [#{ old_account_number } ]: "
318-
319- new_account_number = gets . chomp
320- break if ( new_account_number =~ /\d {12,}/ || new_account_number . empty? )
321- end
322-
323- loop do
324- print "Role Name [#{ target [ :role_name ] } ]: "
325- new_role_name = gets . chomp
326- break if ( new_role_name =~ /[\w &&\S \- ]/ || new_role_name . empty? )
327- end
328-
329- loop do
330- print "Role Prefix [#{ target [ :role_prefix ] } ]: "
331- new_role_prefix = gets . chomp
332- break if ( new_role_prefix =~ /[\w &&\S \- \/ ]/ || new_role_prefix . empty? )
333- end
334-
335- target [ :label ] = new_label . empty? ? target [ :label ] : new_label
336- target [ :account_number ] = new_account_number . empty? ? target [ :account_number ] : new_account_number
337- target [ :role_name ] = new_role_name . empty? ? target [ :role_name ] : new_role_name
338- target [ :role_prefix ] = new_role_prefix . empty? ? target [ :role_prefix ] : new_role_prefix
339-
340- File . open ( CONFIG_FILE , 'w' ) do |f |
341- f . write config . to_yaml
342- end
310+ def self . amis
311+ puts RestackerConfig . latest_amis
312+ # puts RestackerConfig.latest_amis("rhel6")
343313 end
344314end
0 commit comments