knife-cfn 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,40 +18,47 @@ require 'chef/knife/cfn_base'
18
18
  class Chef
19
19
  class Knife
20
20
  class CfnDescribe < Chef::Knife::CfnBase
21
-
21
+
22
22
  deps do
23
23
  require 'fog'
24
24
  require 'readline'
25
25
  require 'chef/json_compat'
26
26
  require 'chef/knife/bootstrap'
27
27
  Chef::Knife::Bootstrap.load_deps
28
- end
28
+ end
29
29
 
30
30
  banner "knife cfn describe [stack name] - lists all stacks if [stack name] is omitted."
31
31
 
32
+ option :long_names,
33
+ :short => "-l",
34
+ :long => "--long",
35
+ :description => "Use long stack names (ARN) instead of friendly names"
36
+
32
37
  def run
33
38
  $stdout.sync = true
34
39
 
35
40
  validate!
36
-
41
+
37
42
  stack_name = @name_args[0]
38
- output_mode = "StackId"
39
- output_header = "Stack ID"
43
+ if stack_name.nil?
44
+ @name_args[0] = "__ALL__"
45
+ end
40
46
 
41
-
42
- if stack_name.nil?
43
- @name_args[0] = "__ALL__"
44
- output_mode = "StackName"
45
- output_header = "Stack Name"
46
- end
47
+ output_mode = "StackName"
48
+ output_header = "Stack Name"
49
+
50
+ if !config[:long_names].nil?
51
+ output_mode = "StackId"
52
+ output_header = "Stack ID"
53
+ end
47
54
 
48
55
  stack_list = [
49
- ui.color(output_header, :bold),
50
- ui.color('Status', :bold),
51
- ui.color('Creation Time', :bold),
52
- ui.color('Disable Rollback', :bold)
56
+ ui.color(output_header, :bold),
57
+ ui.color('Status', :bold),
58
+ ui.color('Creation Time', :bold),
59
+ ui.color('Disable Rollback', :bold)
53
60
  ]
54
-
61
+
55
62
  @name_args.each do |stack_name|
56
63
  options = {}
57
64
  data = Array.new
@@ -65,26 +72,27 @@ class Chef
65
72
  end
66
73
 
67
74
  data = response.body['Stacks']
68
- rescue Excon::Errors::BadRequest => e
69
- i= e.response.body.index("<Message>")
70
- j = e.response.body.index("</Message>")
71
- if !i.nil? and !j.nil?
72
- ui.error(e.response.body[i+9,j-i-9])
73
- else
74
- print "\n#{e.response.body}"
75
- end
76
- exit 1
75
+ rescue Excon::Errors::BadRequest => e
76
+ i= e.response.body.index("<Message>")
77
+ j = e.response.body.index("</Message>")
78
+ if !i.nil? and !j.nil?
79
+ ui.error(e.response.body[i+9,j-i-9])
77
80
  else
78
- data.each do |stack|
79
- stack_list << stack[output_mode]
80
- stack_list << stack['StackStatus']
81
- stack_list << stack['CreationTime'].to_s
82
- stack_list << stack['DisableRollback'].to_s
83
- end
84
- puts ui.list(stack_list, :uneven_columns_across, 4)
85
- end
81
+ print "\n#{e.response.body}"
82
+ end
83
+ exit 1
84
+ else
85
+ data.each do |stack|
86
+ stack_list << stack[output_mode]
87
+ stack_list << stack['StackStatus']
88
+ stack_list << stack['CreationTime'].to_s
89
+ stack_list << stack['DisableRollback'].to_s
90
+ end
91
+
92
+ puts ui.list(stack_list, :uneven_columns_across, 4)
86
93
  end
87
94
  end
88
95
  end
89
96
  end
97
+ end
90
98
  end
@@ -0,0 +1,90 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ require 'chef/knife'
16
+ require 'chef/knife/cfn_base'
17
+
18
+ class Chef
19
+ class Knife
20
+ class CfnOutputs < Chef::Knife::CfnBase
21
+
22
+ deps do
23
+ require 'fog'
24
+ require 'readline'
25
+ require 'chef/json_compat'
26
+ require 'chef/knife/bootstrap'
27
+ Chef::Knife::Bootstrap.load_deps
28
+ end
29
+
30
+ banner "knife cfn outputs <stack name>"
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ stack_name = @name_args[0]
38
+ if stack_name.nil?
39
+ show_usage
40
+ ui.error("You must specify a stack name")
41
+ exit 1
42
+ end
43
+
44
+ events_list = [
45
+ ui.color("Stack", :bold),
46
+ ui.color('Output Key', :bold),
47
+ ui.color('Output Value', :bold),
48
+ ui.color('Description', :bold)
49
+ ]
50
+
51
+ @name_args.each do |stack_name|
52
+ options = {}
53
+ options["StackName"] = stack_name
54
+ data = Array.new
55
+ begin
56
+ response = connection.describe_stacks(options)
57
+ data = response.body["Stacks"]
58
+
59
+ rescue Excon::Errors::BadRequest => e
60
+ i= e.response.body.index("<Message>")
61
+ j = e.response.body.index("</Message>")
62
+ if !i.nil? and !j.nil?
63
+ ui.error(e.response.body[i+9,j-i-9])
64
+ else
65
+ print "\n#{e.response.body}"
66
+ end
67
+ exit 1
68
+ else
69
+ data.each do |stack|
70
+ row1 = true
71
+ events_list << stack["StackName"]
72
+ stack["Outputs"].each do |output|
73
+ if !row1
74
+ events_list << ""
75
+ end
76
+ events_list << output["OutputKey"]
77
+ events_list << output["OutputValue"]
78
+ events_list << output["Description"]
79
+ row1 = false
80
+ end
81
+ end
82
+ puts ui.list(events_list, :uneven_columns_across, 4)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-cfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-26 00:00:00.000000000 Z
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -54,6 +54,7 @@ files:
54
54
  - lib/chef/knife/cfn_delete.rb
55
55
  - lib/chef/knife/cfn_describe.rb
56
56
  - lib/chef/knife/cfn_events.rb
57
+ - lib/chef/knife/cfn_outputs.rb
57
58
  - lib/chef/knife/cfn_update.rb
58
59
  - lib/chef/knife/cfn_validate.rb
59
60
  - lib/knife-cnf/version.rb