Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from brettcave/cloudformation-resources
Browse files Browse the repository at this point in the history
Cloudformation resource listing
  • Loading branch information
neillturner committed Nov 12, 2014
2 parents 34f9959 + 8f194c8 commit bd882cf
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gem
6 changes: 6 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ The <tt>--long</tt> (<tt>-l</tt>) parameter shows stack IDs (ARN) instead of fri

Outputs a list of events for a stack name.

== knife cfn resources [ stack name ] [ logical resource id ]

Outputs the logical resource ID, physical resource ID, resource type and status for all resources of a stack. If <tt>logical resource
id</tt> is specified, then only the details of that resource is shown. A logical resource ID is reference given to a resource in the cloudformation
template, under the "Resources" section.

== knife cfn outputs [ -o ] [ stack name ]

Outputs a list of outputs for a stack name. If <tt>-o</tt> option is specified, then output will be formatted in the same syntax as parameters for cfn create / update
Expand Down
2 changes: 1 addition & 1 deletion knife-cfn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = "knife-cfn"
s.version = "0.1.9"
s.version = "0.1.10"
s.summary = "CloudFormation Support for Knife"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.author = "Neill Turner"
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/cfn_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CfnCreate < Chef::Knife::CfnBase
banner "knife cfn create <stack name> (options)"

option :capabilities,
:short => "-c CAPABILITY..",
:short => "-C CAPABILITY..",
:long => "--capabilities CAPABILITY1,CAPABILITY2,CAPABILITY3..",
:description => "The explicitly approved capabilities that may be used during this stack creation",
:proc => Proc.new { |capabilities| capabilities.split(',') }
Expand Down
14 changes: 7 additions & 7 deletions lib/chef/knife/cfn_outputs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run
exit 1
end

events_list = [
outputs_list = [
ui.color("Stack", :bold),
ui.color('Output Key', :bold),
ui.color('Output Value', :bold),
Expand Down Expand Up @@ -79,23 +79,23 @@ def run
parameter_output += delim
delim="\n"
parameter_output+=stack["StackName"] + ": "
events_list << stack["StackName"]
outputs_list << stack["StackName"]
stack["Outputs"].each do |output|
if !row1
events_list << ""
outputs_list << ""
parameter_output += ";"
end
events_list << output["OutputKey"]
events_list << output["OutputValue"]
events_list << output["Description"]
outputs_list << output["OutputKey"]
outputs_list << output["OutputValue"]
outputs_list << output["Description"]
parameter_output += output["OutputKey"] + "=" + output["OutputValue"]
row1 = false
end
end
if locate_config_value(:output_format) == "parameter"
puts parameter_output
else
puts ui.list(events_list, :uneven_columns_across, 4)
puts ui.list(outputs_list, :uneven_columns_across, 4)
end

end
Expand Down
86 changes: 86 additions & 0 deletions lib/chef/knife/cfn_resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/knife'
require 'chef/knife/cfn_base'

class Chef
class Knife
class CfnResources < Chef::Knife::CfnBase

deps do
require 'fog'
require 'readline'
require 'chef/json_compat'
require 'chef/knife/bootstrap'
Chef::Knife::Bootstrap.load_deps
end

banner "knife cfn resources <stack name> [logical resource id]"

def run
$stdout.sync = true

validate!

stack_name = @name_args[0]
logical_resource_id = @name_args[1]

if stack_name.nil?
show_usage
ui.error("You must specify a stack name")
exit 1
end

resources_list = [
ui.color('Logical Resource Id', :bold),
ui.color('Physical Resource Id', :bold),
ui.color('Resource Type', :bold),
ui.color('Resource Status', :bold)
]

connection_params = { "StackName" => stack_name }
if !logical_resource_id.nil?
connection_params["LogicalResourceId"] = logical_resource_id
end

data = Array.new
begin
response = connection.describe_stack_resources(connection_params)
data = response.body['StackResources']
rescue Excon::Errors::BadRequest => e
i= e.response.body.index("<Message>")
j = e.response.body.index("</Message>")
if !i.nil? and !j.nil?
ui.error(e.response.body[i+9,j-i-9])
else
print "\n#{e.response.body}"
end
exit 1
else
data.each do |resource|
resources_list << resource['LogicalResourceId']
resources_list << resource['PhysicalResourceId']
resources_list << resource['ResourceType']
resources_list << resource['ResourceStatus']
end
puts ui.list(resources_list, :uneven_columns_across, 4)
end

end
end
end
end


3 changes: 3 additions & 0 deletions lib/knife-cfn/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module KnifeCfn
VERSION = "0.1.10"
end
3 changes: 0 additions & 3 deletions lib/knife-cnf/version.rb

This file was deleted.

15 changes: 8 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
$:.unshift File.expand_path('../../lib', __FILE__)
require 'chef'
require 'knife-cnf/cfn_base'
require 'knife-cnf/cfn_create'
require 'knife-cnf/cfn_delete'
require 'knife-cnf/cfn_describe'
require 'knife-cnf/cfn_events'
require 'knife-cnf/cfn_outputs'
require 'knife-cnf/cfn_validate'
require 'knife-cfn/cfn_base'
require 'knife-cfn/cfn_create'
require 'knife-cfn/cfn_delete'
require 'knife-cfn/cfn_describe'
require 'knife-cfn/cfn_events'
require 'knife-cfn/cfn_resources'
require 'knife-cfn/cfn_outputs'
require 'knife-cfn/cfn_validate'

0 comments on commit bd882cf

Please sign in to comment.