add ability to watch stack resources

This commit is contained in:
Anton Chuchkalov 2015-07-15 19:37:27 +04:00
parent fb5cdea4b2
commit 9aad1253fe
9 changed files with 49 additions and 14 deletions

View File

@ -13,8 +13,8 @@ module Outputtable
@outputter ||= outputter_class.new(data_to_output, options, additional_output_options) @outputter ||= outputter_class.new(data_to_output, options, additional_output_options)
end end
def output def output(preferred_format=nil)
outputter.output outputter.output(preferred_format)
end end

View File

@ -25,9 +25,12 @@ class Stack < Handler
create_handler create_handler
when :delete when :delete
delete_handler delete_handler
when :sync_details when :sync
sync_handler sync_handler
output output
when :resources
resources_handler
output('json')
end end
end end
@ -67,7 +70,7 @@ class Stack < Handler
def sync_handler def sync_handler
stack_id = @args[2] stack_id = @args[2]
r = inspect_parameters(@options_parser.sync_details_params, stack_id) r = inspect_parameters(@options_parser.sync_params, stack_id)
unless r.nil? unless r.nil?
@options_parser.invalid_sync_command @options_parser.invalid_sync_command
abort(r) abort(r)
@ -75,6 +78,16 @@ class Stack < Handler
@show = post "/stack/#{stack_id}/sync_details" @show = post "/stack/#{stack_id}/sync_details"
end end
def resources_handler
stack_id = @args[2]
r = inspect_parameters(@options_parser.sync_params, stack_id)
unless r.nil?
@options_parser.invalid_sync_command
abort(r)
end
@list = get "/stack/#{stack_id}/resources"
end
def delete_handler def delete_handler
stack_id = @args[2] stack_id = @args[2]
r = inspect_parameters(@options_parser.delete_params, stack_id) r = inspect_parameters(@options_parser.delete_params, stack_id)

View File

@ -2,7 +2,7 @@ require "devops-client/options/common_options"
class StackOptions < CommonOptions class StackOptions < CommonOptions
commands :create, :delete, :list, :show, :sync_details commands :create, :delete, :list, :show, :sync, :resources
def initialize args, def_options def initialize args, def_options
super(args, def_options) super(args, def_options)
@ -11,7 +11,8 @@ class StackOptions < CommonOptions
self.list_params = ["[provider]", "[ec2|openstack]"] self.list_params = ["[provider]", "[ec2|openstack]"]
self.show_params = ["STACK"] self.show_params = ["STACK"]
self.delete_params = ["STACK"] self.delete_params = ["STACK"]
self.sync_details_params = ["STACK"] self.sync_params = ["STACK"]
self.resources_params = ["STACK"]
end end
def create_options def create_options

View File

@ -18,8 +18,9 @@ module Output
@data, @options, @additional_options = data_to_output, command_line_options, additional_options @data, @options, @additional_options = data_to_output, command_line_options, additional_options
end end
def output def output(format = nil)
case options[:format] format ||= options[:format]
case format
when CommonOptions::TABLE_FORMAT when CommonOptions::TABLE_FORMAT
table table
when CommonOptions::JSON_FORMAT when CommonOptions::JSON_FORMAT

View File

@ -52,8 +52,11 @@ module Devops
end end
def sync_details! def sync_details!
details = provider_class.stack_details(self) self.details = provider_class.stack_details(self)
self.details = details#.to_json end
def resources
provider_class.stack_resources(self)
end end
def template_body def template_body

View File

@ -4,7 +4,7 @@ module Devops
self.provider = 'openstack' self.provider = 'openstack'
def stack_status def stack_status
details[:body]['stack']['stack_status'] if details details[:stack_status] if details
end end
end end
end end

View File

@ -206,12 +206,15 @@ module Provider
end end
def delete_stack(stack) def delete_stack(stack)
orchestration.delete_stack(stack.id, stack.cloud_stack_id) fog_stack(stack).destroy
end end
def stack_details(stack) def stack_details(stack)
puts "Fetching information about stack #{stack.id}/#{stack.cloud_stack_id}" fog_stack(stack).details.attributes
orchestration.show_stack_details(stack.id, stack.cloud_stack_id).data end
def stack_resources(stack)
fog_stack(stack).resources
end end
private private
@ -239,5 +242,9 @@ module Provider
@connection ||= Fog::Orchestration.new(connection_options) @connection ||= Fog::Orchestration.new(connection_options)
end end
def fog_stack(stack)
orchestration.stacks.get(stack.id, stack.cloud_stack_id)
end
end end
end end

View File

@ -66,6 +66,14 @@ module Devops
} }
end end
def self.resources
lambda {
check_privileges("stack", "r")
stack = settings.mongo.stack(params[:stack_id])
json stack.resources
}
end
end end
end end
end end

View File

@ -16,6 +16,8 @@ module Devops
app.post_with_headers "/stack/:stack_id/sync_details", :headers => [:accept], &Devops::Version2_0::Handler::Stack.sync_details app.post_with_headers "/stack/:stack_id/sync_details", :headers => [:accept], &Devops::Version2_0::Handler::Stack.sync_details
app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept], &Devops::Version2_0::Handler::Stack.resources
hash = {} hash = {}
hash['GET'] = Devops::Version2_0::Handler::Stack.get_stack hash['GET'] = Devops::Version2_0::Handler::Stack.get_stack