813: add ability to change stack's stack_template

This commit is contained in:
Anton Chuchkalov 2015-11-17 18:08:38 +03:00
parent 2611f5bb7c
commit 1166e5a90c
7 changed files with 68 additions and 1 deletions

View File

@ -41,6 +41,9 @@ class Stack < Handler
else
output
end
when :change_stack_template
change_stack_template_handler
output
end
end
@ -136,6 +139,16 @@ class Stack < Handler
puts response.inspect
end
def change_stack_template_handler
stack_id, template_id = @args[2], @args[3]
r = inspect_parameters(@options_parser.delete_params, stack_id, template_id)
unless r.nil?
@options_parser.invalid_change_stack_template_command
abort(r)
end
@show = put("/stack/#{stack_id}/stack_template", {stack_template: template_id})
end
private
def provider_stacks(provider)

View File

@ -2,7 +2,7 @@ require "devops-client/options/common_options"
class StackOptions < CommonOptions
commands :create, :delete, :list, :show, :sync, :resources, :deploy, :reserve, :unreserve
commands :create, :delete, :list, :show, :sync, :resources, :deploy, :reserve, :unreserve, :change_stack_template
def initialize args, def_options
super(args, def_options)
@ -15,6 +15,7 @@ class StackOptions < CommonOptions
self.resources_params = ["STACK"]
self.deploy_params = ["STACK"]
self.reserve_params = ["STACK"]
self.change_stack_template_params = %w(STACK STACK_TEMPLATE)
end
def create_options

View File

@ -203,6 +203,13 @@ module Devops
end
end
def change_stack_template(stack_id)
stack_template_id = parser.change_stack_template
Devops::Db.connector.stack_template(stack_template_id)
stack = Devops::Db.connector.stack(stack_id)
stack.change_stack_template!(stack_template_id)
end
end
end
end

View File

@ -38,6 +38,12 @@ module Devops
@body
end
def change_stack_template
template_id = create_object_from_json_body['stack_template']
check_string(template_id, "Parameter 'stack_template' must be a not empty string")
template_id
end
end
end
end

View File

@ -187,6 +187,25 @@ module Devops
}
app.multi_routes "/stack/:id/tags", {:headers => [:content_type]}, hash
# Change stack stack_template
#
# * *Request*
# - method : PUT
# - headers :
# - Accept: application/json
# - Content-Type: application/json
# - body :
# {
# "stack_template": "template_id"
# }
#
# * *Returns* :
# 200 - OK
app.put_with_headers "/stack/:id/stack_template", :headers => [:accept, :content_type] do |id|
check_privileges("stack", "r")
json Devops::API2_0::Handler::Stack.new(request).change_stack_template(id)
end
puts "Stack routes initialized"
end

View File

@ -18,6 +18,23 @@ module Devops
result
end
def update_in_cloud!(params)
parameters = params.keep_if do |key, value|
%w(Parameters TemplateBody TemplateURL Capabilities)
end
provider_instance.update_stack(self, parameters)
end
# We should improve this functionality: stack will be rollbacked
# if there are errors during stack_template changing, so we should track
# that process and persist changes only in case of success.
def change_stack_template!(stack_template)
self.stack_template = stack_template
update_in_cloud!('TemplateBody' => template_body)
Devops::Db.connector.stack_update(self)
end
end
end
end

View File

@ -261,6 +261,10 @@ module Provider
end
end
def update_stack(stack, params)
cloud_formation.update_stack(stack.name, params)
end
def set_stack_tags stack, out=""
tags = {
# "cid:remoteUser" => s.remote_user