Class: Stackr::Cli
- Inherits:
-
Thor
- Object
- Thor
- Stackr::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/stackr/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_project(name) ⇒ Object
-
#create_stack(template_name) ⇒ Object
TODO: log parameters and their values.
- #create_template(name) ⇒ Object
- #delete_stack(stack_name) ⇒ Object
- #generate_template(template_name) ⇒ Object
- #list_stacks ⇒ Object
-
#update_stack(template_name) ⇒ Object
TODO: log parameters and their values.
- #validate_template(template_name) ⇒ Object
-
#version ⇒ Object
version.
Class Method Details
.source_root ⇒ Object
45 46 47 |
# File 'lib/stackr/cli.rb', line 45 def self.source_root File.join(File.dirname(__FILE__),'..','..') end |
Instance Method Details
#create_project(name) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/stackr/cli.rb', line 50 def create_project(name) @project_name = name say "Creating stackr project: #{name}\n" directory 'templates/project', name end |
#create_stack(template_name) ⇒ Object
TODO: log parameters and their values
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/stackr/cli.rb', line 115 def create_stack(template_name) return if !validate_template(template_name) template = load_template(template_name) if !template say "There is no template named \'#{template_name}\'." return end name = [:name] || template.name launcher = Stackr::CloudFormation.new say "Creating CloudFormation stack #{name} from template #{template.name}\n" begin launcher.create_stack(template, ) rescue Stackr::StackAlreadyExistsError => e say e. end end |
#create_template(name) ⇒ Object
59 60 61 62 63 |
# File 'lib/stackr/cli.rb', line 59 def create_template(name) @template_name = name say "Creating template generator #{name}\n" template 'templates/generator.rb.tt', File.join(templates_path, "#{name}.rb") end |
#delete_stack(stack_name) ⇒ Object
166 167 168 169 170 171 172 173 174 |
# File 'lib/stackr/cli.rb', line 166 def delete_stack(stack_name) say "Deleting CloudFormation stack #{stack_name}\n" launcher = Stackr::CloudFormation.new begin launcher.delete_stack(stack_name) rescue Stackr::StackMissingError => e say e. end end |
#generate_template(template_name) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stackr/cli.rb', line 67 def generate_template(template_name) template = load_template(template_name) if !template say "There is no template named \'#{template_name}\'." return end json_file = json_template_path(template_name) say "Writing #{template_name} to #{json_file}\n" File.open(json_file, 'w') do |f| f.write(template.body) end end |
#list_stacks ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/stackr/cli.rb', line 178 def list_stacks launcher = Stackr::CloudFormation.new rows = [] launcher.list_stacks.each do |stack| rows << [ stack.name, stack.stack_status, stack.creation_time ? stack.creation_time.iso8601 : '', stack.last_updated_time ? stack.last_updated_time.iso8601 : '' ] end print_table rows end |
#update_stack(template_name) ⇒ Object
TODO: log parameters and their values
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/stackr/cli.rb', line 141 def update_stack(template_name) return if !validate_template(template_name) template = load_template(template_name) if !template say "There is no template named \'#{template_name}\'." return end name = [:name] || template.name say "Updating CloudFormation stack #{name} from template #{template.name}\n" launcher = Stackr::CloudFormation.new begin launcher.update_stack(template, ) rescue Stackr::StackMissingError => e say e. rescue Stackr::StackUpdateNotRequiredError => e say e. rescue Stackr::InsufficientCapabilitiesError => e say e. end end |
#validate_template(template_name) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/stackr/cli.rb', line 84 def validate_template(template_name) template = load_template(template_name) if !template say "There is no template named \'#{template_name}\'." return end launcher = Stackr::CloudFormation.new begin launcher.validate_template(template) rescue Aws::S3::Errors::ServiceError => e say e. return false else say "Template #{template_name} validates." return true end end |
#version ⇒ Object
version
38 |
# File 'lib/stackr/cli.rb', line 38 desc 'version', 'show version' |