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)
end
def output
outputter.output
def output(preferred_format=nil)
outputter.output(preferred_format)
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -66,6 +66,14 @@ module Devops
}
end
def self.resources
lambda {
check_privileges("stack", "r")
stack = settings.mongo.stack(params[:stack_id])
json stack.resources
}
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.get_with_headers "/stack/:stack_id/resources", :headers => [:accept], &Devops::Version2_0::Handler::Stack.resources
hash = {}
hash['GET'] = Devops::Version2_0::Handler::Stack.get_stack