knife-dependency-tree 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGRmOWI0NzIxZjhhYzFiZmMyMzI5ZTVhZThlY2RkYzUyNTAwM2U1Zg==
5
+ data.tar.gz: !binary |-
6
+ MThhYzNlZDJiNjA1ODJkMTMyY2NhNGMxNmU1OWY0MmU0Yjk1OTc0MQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGExMGEwYzUwODNjZGMxODM4MjIyYzIxYWFmNjkyYzNhOTg5ODQ1YzNlMTYw
10
+ YTA2MDc5YzQxYzY5ZmEwMDY3YzcxMTUyNjcyNTE2OWFmM2RhNDczZmRmMWU5
11
+ NTRlY2NjMWYyZmI4NDAzMWNhNjU1MTFjYWQ1NGM4YmViOTBkYjQ=
12
+ data.tar.gz: !binary |-
13
+ NWIxMmFkMjVhZmFlMjFlYTI3M2YyYmY0MzAwZjllNGZhYTU4MzI1NTc5NGNm
14
+ OTA1MDE5ZDg3NTI2YzNiOWM5NGNlNTY4YTdlYTI2ZjgxM2Y3YWZiODcxYmFi
15
+ MzZjMjAyZWQxOWM3ZGFjZDY5NTkzYjUxNTNhMjg3ZmM5Mjk1NzM=
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2013, Aaron Peschel
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ Redistributions in binary form must reproduce the above copyright notice, this
11
+ list of conditions and the following disclaimer in the documentation and/or
12
+ other materials provided with the distribution.
13
+
14
+ Neither the name of the {organization} nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,4 @@
1
+ knife_dependency_tree
2
+ =====================
3
+
4
+ Generates a dependency tree of roles and cookbooks.
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'knife-dependency-tree/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'knife-dependency-tree'
7
+ s.version = Knife::DependencyTree::VERSION
8
+ s.authors = ['Aaron Peschel']
9
+ s.email = ['aaron.peschel@gmail.com']
10
+ s.homepage = 'https://github.com/apeschel/knife-dependency-tree'
11
+ s.summary = %q{Generates a dependency tree of roles and cookbooks.}
12
+ s.description = s.summary
13
+ s.license = 'BSD'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+
19
+ s.require_paths = ['lib']
20
+ end
21
+
@@ -0,0 +1,105 @@
1
+ class NodeDependencyTree < ::Chef::Knife
2
+ deps do
3
+ require 'chef/json_compat'
4
+ require 'uri'
5
+ require 'chef/cookbook_version'
6
+ require 'set'
7
+ end
8
+
9
+ banner "knife node dependency tree NODE"
10
+
11
+ class TreeNode < NodeDependencyTree
12
+ @@cookbook_versions = {}
13
+ @@seen_cookbooks = Set.new
14
+
15
+ def initialize(name, children=[])
16
+ @name = name
17
+ @children = children
18
+ @color = :red
19
+ end
20
+
21
+ def to_s
22
+ pretty_print(0)
23
+ end
24
+
25
+ def pretty_print(indent_level)
26
+ output = []
27
+ indent_symbol = " "
28
+ indent = indent_symbol * indent_level
29
+
30
+ output << indent + ::Chef::Knife::ui.color(@name, @color)
31
+
32
+ @children.each do |child|
33
+ output << child.pretty_print(indent_level + 1)
34
+ end
35
+
36
+ output.join("\n")
37
+ end
38
+
39
+ def roles_to_cookbooks(roles)
40
+ roles.map { |role_name| RoleNode.new(role_name) }
41
+ end
42
+
43
+ def recipes_to_cookbooks(recipes)
44
+ recipes.map do |recipe|
45
+ recipe.partition("::").first
46
+ end.uniq.map do |cookbook_name|
47
+ CookbookNode.new(cookbook_name)
48
+ end
49
+ end
50
+ end
51
+
52
+ class NodeNode < TreeNode
53
+ def initialize(name)
54
+ node = ::Chef::Node.load(name)
55
+
56
+ environment = ::Chef::Environment.load(node.chef_environment)
57
+ @@cookbook_versions = environment.cookbook_versions
58
+
59
+ cookbooks = recipes_to_cookbooks(node[:recipes])
60
+ roles = roles_to_cookbooks(node[:roles])
61
+ super(name, cookbooks + roles)
62
+
63
+ @color = :green
64
+ end
65
+ end
66
+
67
+ class RoleNode < TreeNode
68
+ def initialize(name)
69
+ role = ::Chef::Role.load(name)
70
+ cookbooks = recipes_to_cookbooks(role.run_list.recipes)
71
+ roles = roles_to_cookbooks(role.run_list.roles)
72
+ super(name, cookbooks + roles)
73
+
74
+ @color = :cyan
75
+ end
76
+ end
77
+
78
+ class CookbookNode < TreeNode
79
+ def initialize(name)
80
+ @@seen_cookbooks.add(name)
81
+ # XXX: Clean this up.
82
+ cookbook_version = @@cookbook_versions[name]
83
+ cookbooks = []
84
+ if cookbook_version
85
+ cookbook_version = cookbook_version.split.last
86
+ cookbook = rest.get_rest("cookbooks/#{name}/#{cookbook_version}")
87
+ dependencies = cookbook.manifest["metadata"]["dependencies"]
88
+ cookbooks = dependencies.keys.uniq.reject do |cookbook_name|
89
+ @@seen_cookbooks.include? cookbook_name
90
+ end.map do |cookbook_name|
91
+ CookbookNode.new(cookbook_name)
92
+ end
93
+ end
94
+ super(name, cookbooks)
95
+
96
+ @color = :yellow
97
+ end
98
+ end
99
+
100
+ def run
101
+ node_name = @name_args[0]
102
+ root = NodeNode.new(node_name)
103
+ puts root
104
+ end
105
+ end
@@ -0,0 +1,6 @@
1
+ module Knife
2
+ module DependencyTree
3
+ VERSION = "0.0.1"
4
+ MAJOR, MINOR, TINY = VERSION.split('.')
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-dependency-tree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Peschel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Generates a dependency tree of roles and cookbooks.
14
+ email:
15
+ - aaron.peschel@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - LICENSE
22
+ - README.md
23
+ - knife-dependency-tree.gemspec
24
+ - lib/chef/knife/node_dependency_tree.rb
25
+ - lib/knife-dependency-tree/version.rb
26
+ homepage: https://github.com/apeschel/knife-dependency-tree
27
+ licenses:
28
+ - BSD
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.6
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Generates a dependency tree of roles and cookbooks.
50
+ test_files: []