puppet-ghostbuster 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/puppet-ghostbuster/bin.rb +1 -1
- data/lib/puppet-ghostbuster/configuration.rb +2 -1
- data/lib/puppet-ghostbuster/optparser.rb +9 -4
- data/lib/puppet-ghostbuster/version.rb +1 -1
- data/lib/puppet-ghostbuster.rb +23 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e0e4553e6823762987d5f037c2f398496ba8e116
|
|
4
|
+
data.tar.gz: d45d5765efb485e178d0ac361a3caed3d14bc297
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 727bc5028c12732e1a9fcf542fe250b6c13a3a6d7f0bcbddbf0f098cd5d6d86a2b5ee7a09c0d090664093a5c756c504f138d02c5d2f6010170976343dd851162
|
|
7
|
+
data.tar.gz: dd7a8967c4651125dd743475fdaddd255c28bfe92eceff07401004cedf0b516023d68257d5a3b681857bf7983ec6ac70527b1a6ec07779c259da2a0ccd9c1e20
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [0.1.2](https://github.com/camptocamp/puppet-ghostbuster/releases/tag/0.1.3) (2015-04-23)
|
|
4
|
+
|
|
5
|
+
- Add --log-level option and debug
|
|
6
|
+
|
|
3
7
|
## [0.1.2](https://github.com/camptocamp/puppet-ghostbuster/releases/tag/0.1.2) (2015-04-23)
|
|
4
8
|
|
|
5
9
|
**Fixed bugs:**
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Classes used 0 time should be removed.
|
|
|
12
12
|
Usage
|
|
13
13
|
-----
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
If you want to read default options and private key from puppet configuration, this gem needs to have root (puppet) permissions.
|
|
16
16
|
```
|
|
17
17
|
sudo bundle exec puppet-ghostbuster
|
|
18
18
|
```
|
|
@@ -4,7 +4,7 @@ class PuppetGhostbuster
|
|
|
4
4
|
class Configuration
|
|
5
5
|
|
|
6
6
|
def initialize
|
|
7
|
-
Puppet.initialize_settings
|
|
7
|
+
Puppet.initialize_settings
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
# Public: Catch situations where options are being set for the first time
|
|
@@ -86,6 +86,7 @@ class PuppetGhostbuster
|
|
|
86
86
|
# Returns nothing.
|
|
87
87
|
def defaults
|
|
88
88
|
settings.clear
|
|
89
|
+
self.loglevel = Logger::INFO
|
|
89
90
|
self.puppetdbserverurl = "https://#{Puppet[:server]}:8081"
|
|
90
91
|
self.hostprivkey = Puppet[:hostprivkey]
|
|
91
92
|
self.hostcert = Puppet[:hostcert]
|
|
@@ -29,12 +29,17 @@ class PuppetGhostbuster::OptParser
|
|
|
29
29
|
opts.load(file)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
opts.on('--
|
|
33
|
-
'The level of
|
|
34
|
-
PuppetGhostbuster.configuration.
|
|
32
|
+
opts.on('--log-level LEVEL', [:debug, :info, :warn, :error],
|
|
33
|
+
'The level of verbosity (debug, info, warn or error)') do |loglevel|
|
|
34
|
+
PuppetGhostbuster.configuration.loglevel=Logger::DEBUG if loglevel==:debug
|
|
35
|
+
PuppetGhostbuster.configuration.loglevel=Logger::INFO if loglevel==:info
|
|
36
|
+
PuppetGhostbuster.configuration.loglevel=Logger::WARN if loglevel==:warn
|
|
37
|
+
PuppetGhostbuster.configuration.loglevel=Logger::ERROR if loglevel==:error
|
|
35
38
|
end
|
|
36
39
|
|
|
37
|
-
opts.on('-s', '--puppetdburl SERVER',
|
|
40
|
+
opts.on('-s', '--puppetdburl SERVER',
|
|
41
|
+
'puppet db server url to connect to.',
|
|
42
|
+
'Defaults to the puppet server found in puppet configuration') do |s|
|
|
38
43
|
PuppetGhostbuster.configuration.puppetdbserverurl = s
|
|
39
44
|
end
|
|
40
45
|
|
data/lib/puppet-ghostbuster.rb
CHANGED
|
@@ -31,7 +31,6 @@ class PuppetGhostbuster
|
|
|
31
31
|
self.class.configuration
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
|
|
35
34
|
def self.puppetdbserverfilename
|
|
36
35
|
return configuration.puppetdbserverurl.gsub(/[:\/]/,'_')
|
|
37
36
|
end
|
|
@@ -55,7 +54,8 @@ class PuppetGhostbuster
|
|
|
55
54
|
end
|
|
56
55
|
end
|
|
57
56
|
|
|
58
|
-
def self.client
|
|
57
|
+
def self.client
|
|
58
|
+
@@logger.debug "Connecting to puppet DB #{configuration.puppetdbserverurl}"
|
|
59
59
|
PuppetDB::Client.new({
|
|
60
60
|
:server => configuration.puppetdbserverurl,
|
|
61
61
|
:pem => {
|
|
@@ -78,8 +78,13 @@ class PuppetGhostbuster
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def find_unused_classes
|
|
81
|
+
@@logger.info 'Now trying to find unused classes'
|
|
81
82
|
manifests.each do |file|
|
|
82
|
-
|
|
83
|
+
@@logger.debug " file #{file}."
|
|
84
|
+
if File.symlink?(file)
|
|
85
|
+
@@logger.warn " Skipping symlink #{file}"
|
|
86
|
+
next
|
|
87
|
+
end
|
|
83
88
|
if c = File.readlines(file).grep(/^class\s+([^\s\(\{]+)/){$1}[0]
|
|
84
89
|
class_name = c.split('::').map(&:capitalize).join('::')
|
|
85
90
|
count = self.class.used_classes.select { |klass| klass == class_name }.size
|
|
@@ -89,8 +94,12 @@ class PuppetGhostbuster
|
|
|
89
94
|
end
|
|
90
95
|
|
|
91
96
|
def find_unused_defines
|
|
97
|
+
@@logger.info 'Now trying to find unused defines'
|
|
92
98
|
manifests.each do |file|
|
|
93
|
-
|
|
99
|
+
if File.symlink?(file)
|
|
100
|
+
@@logger.warn " Skipping symlink #{file}"
|
|
101
|
+
next
|
|
102
|
+
end
|
|
94
103
|
if d = File.readlines(file).grep(/^define\s+([^\s\(\{]+)/){$1}[0]
|
|
95
104
|
define_name = d.split('::').map(&:capitalize).join('::')
|
|
96
105
|
count = self.class.client.request('resources', [:'=', 'type', define_name]).data.size
|
|
@@ -100,12 +109,16 @@ class PuppetGhostbuster
|
|
|
100
109
|
end
|
|
101
110
|
|
|
102
111
|
def find_unused_templates
|
|
112
|
+
@@logger.info 'Now trying to find unused templates'
|
|
103
113
|
templates.each do |template|
|
|
104
114
|
next unless File.file?(template)
|
|
105
115
|
module_name, template_name = template.match(/.*\/([^\/]+)\/templates\/(.+)$/).captures
|
|
106
116
|
count = 0
|
|
107
117
|
manifests.each do |manifest|
|
|
108
|
-
|
|
118
|
+
if File.symlink?(manifest)
|
|
119
|
+
@@logger.warn " Skipping symlink #{manifest}"
|
|
120
|
+
next
|
|
121
|
+
end
|
|
109
122
|
if match = manifest.match(/.*\/([^\/]+)\/manifests\/.+$/)
|
|
110
123
|
manifest_module_name = match.captures[0]
|
|
111
124
|
count += File.readlines(manifest).grep(/["']\$\{module_name\}\/#{template_name}["']/).size if manifest_module_name == module_name
|
|
@@ -117,6 +130,7 @@ class PuppetGhostbuster
|
|
|
117
130
|
end
|
|
118
131
|
|
|
119
132
|
def find_unused_files
|
|
133
|
+
@@logger.info 'Now trying to find unused files'
|
|
120
134
|
files.each do |file|
|
|
121
135
|
next unless File.file?(file)
|
|
122
136
|
module_name, file_name = file.match(/.*\/([^\/]+)\/files\/(.+)$/).captures
|
|
@@ -142,6 +156,10 @@ class PuppetGhostbuster
|
|
|
142
156
|
|
|
143
157
|
def initialize(path = '.')
|
|
144
158
|
self.path = path
|
|
159
|
+
@@logger = Logger.new(STDERR).tap do |log|
|
|
160
|
+
log.progname = 'PuppetGhostbuster'
|
|
161
|
+
log.level=PuppetGhostbuster.configuration.loglevel
|
|
162
|
+
end
|
|
145
163
|
end
|
|
146
164
|
|
|
147
165
|
def run
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: puppet-ghostbuster
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Camptocamp
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-04-
|
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|