Class: Chef::Knife::CloudformationCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::CloudformationCreate
- Includes:
- KnifeCloudformation::Knife::Base, KnifeCloudformation::Knife::Stack, KnifeCloudformation::Knife::Template
- Defined in:
- lib/chef/knife/cloudformation_create.rb
Overview
Cloudformation create command
Constant Summary
Constants included from KnifeCloudformation::Knife::Template
KnifeCloudformation::Knife::Template::TEMPLATE_IGNORE_DIRECTORIES
Instance Method Summary collapse
-
#_run ⇒ Object
Run the stack creation command.
-
#apply_stacks!(stack) ⇒ Miasma::Models::Orchestration::Stack
Apply any defined remote stacks.
Methods included from KnifeCloudformation::Knife::Stack
Methods included from KnifeCloudformation::Knife::Template
Methods included from KnifeCloudformation::Knife::Base
Instance Method Details
#_run ⇒ Object
Run the stack creation command
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/chef/knife/cloudformation_create.rb', line 64 def _run name = name_args.first unless(name) ui.fatal "Formation name must be specified!" exit 1 end if(Chef::Config[:knife][:cloudformation][:template]) file = Chef::Config[:knife][:cloudformation][:template] else file = load_template_file end ui.info "#{ui.color('Cloud Formation:', :bold)} #{ui.color('create', :green)}" stack_info = "#{ui.color('Name:', :bold)} #{name}" if(Chef::Config[:knife][:cloudformation][:path]) stack_info << " #{ui.color('Path:', :bold)} #{Chef::Config[:knife][:cloudformation][:file]}" if(Chef::Config[:knife][:cloudformation][:disable_processing]) stack_info << " #{ui.color('(not pre-processed)', :yellow)}" end end unless(config[:print_only]) ui.info " -> #{stack_info}" end stack = provider.connection.stacks.build( Chef::Config[:knife][:cloudformation][:options].dup.merge( :name => name, :template => file ) ) apply_stacks!(stack) stack.template = KnifeCloudformation::Utils::StackParameterScrubber.scrub!(stack.template) if(config[:print_only]) ui.info _format_json(translate_template(stack.template)) exit 0 end # TODO: if nested stacks and not extracted (based on config # option, break resources out and iterate each stack and use # apply-stack as we iterate the list populate_parameters!(stack.template) stack.parameters = Chef::Config[:knife][:cloudformation][:options][:parameters] stack.template = translate_template(stack.template) stack.save if(Chef::Config[:knife][:cloudformation][:poll]) poll_stack(stack.name) stack = provider.connection.stacks.get(name) if(stack.reload.success?) ui.info "Stack create complete: #{ui.color('SUCCESS', :green)}" knife_output = Chef::Knife::CloudformationDescribe.new knife_output.name_args.push(name) knife_output.config[:outputs] = true knife_output.run else ui.fatal "Create of new stack #{ui.color(name, :bold)}: #{ui.color('FAILED', :red, :bold)}" ui.info "" knife_inspect = Chef::Knife::CloudformationInspect.new knife_inspect.name_args.push(name) knife_inspect.config[:instance_failure] = true knife_inspect.run exit 1 end else ui.warn 'Stack state polling has been disabled.' ui.info "Stack creation initialized for #{ui.color(name, :green)}" end end |
#apply_stacks!(stack) ⇒ Miasma::Models::Orchestration::Stack
Apply any defined remote stacks
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/chef/knife/cloudformation_create.rb', line 142 def apply_stacks!(stack) remote_stacks = Chef::Config[:knife][:cloudformation]. fetch(:create, {}).fetch(:apply_stacks, []) remote_stacks.each do |stack_name| remote_stack = provider.connection.stacks.get(stack_name) if(remote_stack) stack.apply_stack(remote_stack) else ui.error "Failed to apply requested stack. Unable to locate. (#{stack_name})" exit 1 end end stack end |