knife-advisor 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40942ef6adf162cf086ffc2bdb1e5213b1a6f6ec
4
+ data.tar.gz: ed7033b55c293043873c22a647006180364c74b6
5
+ SHA512:
6
+ metadata.gz: a0ce6648b5ee09a7aa31dd66376d4f2c1e16dcbd3658835aa246a2e4ed5e83b08bf031be26d9ba969fc2b21de7d608b7be148d1ac491f7da7b665462cf0366aa
7
+ data.tar.gz: 6a47276a298891a5370c2eb1bf9267eed83ca77e84a903bdbb4c16158c13693b50fb379f9bd41d78ea7e6110edb36c37556fc4cebeb377947d0af1532c23348f
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ source 'https://rubygems.org/'
18
+
19
+ gemspec
@@ -0,0 +1,33 @@
1
+ # Knife-Advisor Plugin
2
+
3
+ A knife plugin to get real-time help from an expert Chef advisor.
4
+
5
+ ## Getting Started
6
+
7
+ If you have ChefDK installed locally you can install via:
8
+
9
+ ```
10
+ chef gem install knife-advisor
11
+ ```
12
+
13
+ Then you can run the plugin:
14
+
15
+ ```
16
+ knife advisor
17
+ ```
18
+
19
+ ## License
20
+
21
+ Copyright 2015, Noah Kantrowitz
22
+
23
+ Licensed under the Apache License, Version 2.0 (the "License");
24
+ you may not use this file except in compliance with the License.
25
+ You may obtain a copy of the License at
26
+
27
+ http://www.apache.org/licenses/LICENSE-2.0
28
+
29
+ Unless required by applicable law or agreed to in writing, software
30
+ distributed under the License is distributed on an "AS IS" BASIS,
31
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ See the License for the specific language governing permissions and
33
+ limitations under the License.
@@ -0,0 +1,17 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'bundler/gem_tasks'
@@ -0,0 +1,37 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ lib = File.expand_path('../lib', __FILE__)
18
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
19
+ require 'knife_advisor/version'
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = 'knife-advisor'
23
+ spec.version = KnifeAdvisor::VERSION
24
+ spec.authors = ['Noah Kantrowitz']
25
+ spec.email = %w{noah@coderanger.net}
26
+ spec.description = 'A knife plugin to get some help!'
27
+ spec.summary = spec.description
28
+ spec.homepage = 'https://github.com/coderanger/knife-advisor'
29
+ spec.license = 'Apache 2.0'
30
+
31
+ spec.files = `git ls-files`.split($/)
32
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
33
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
+ spec.require_paths = %w{lib}
35
+
36
+ spec.add_dependency 'chef'
37
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/knife'
18
+
19
+
20
+ module KnifeAdvisor
21
+ class Advisor < Chef::Knife
22
+
23
+ deps do
24
+ require 'knife_advisor'
25
+ end
26
+
27
+ banner "knife advisor"
28
+
29
+ def run
30
+ KnifeAdvisor::UI.new(ui).run
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ module KnifeAdvisor
19
+ autoload :VERSION, 'knife_advisor/version'
20
+ autoload :UI, 'knife_advisor/ui'
21
+ autoload :RingBuffer, 'knife_advisor/ring_buffer'
22
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ module KnifeAdvisor
19
+ class RingBuffer
20
+ def initialize(values=[])
21
+ @values = values.shuffle
22
+ @i = 0
23
+ end
24
+
25
+ def advance!
26
+ @i += 1
27
+ if @i >= @values.length
28
+ @i = 0
29
+ @values.shuffle!
30
+ end
31
+ end
32
+
33
+ def next
34
+ @values[@i].tap { advance! }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'tk'
18
+
19
+
20
+ module KnifeAdvisor
21
+ class UI
22
+ autoload :Window, 'knife_advisor/ui/window'
23
+
24
+ def initialize(ui)
25
+ @ui = ui
26
+ @responses = RingBuffer.new([
27
+ 'Do you care about networking performance?',
28
+ 'Do you need high availability?',
29
+ 'Do you want auto-scaling?',
30
+ 'Do you need to improve your IT velocity?',
31
+ 'Do you need network security?',
32
+ 'Is your business web scale?',
33
+ 'Are you using MongoDB to power your web applications?',
34
+ 'Is your current hosting too expensive?',
35
+ ])
36
+ end
37
+
38
+ def run
39
+ $stdout.write('Just a moment. We are connecting you to one of our expert advisors.')
40
+ 10.times do
41
+ sleep(1)
42
+ $stdout.write('.')
43
+ end
44
+ $stdout.write("\n")
45
+ # Show the window.
46
+ window
47
+ after(4000) do
48
+ window.say('Hi there!')
49
+ end
50
+ after(6000) do
51
+ window.append('It looks like you are trying to use the cloud.')
52
+ end
53
+ after(8000) do
54
+ window.append('Would you like help?')
55
+ window.draw_buttons!
56
+ window.on_yes do
57
+ window.say(@responses.next)
58
+ end
59
+ window.on_no do
60
+ window.clear_buttons!
61
+ window.say("I'm sorry to hear that.")
62
+ after(2000) { window.append('Goodbye!') }
63
+ after(4000) { puts('Thank you for using the cloud!'); exit(0) }
64
+ end
65
+ end
66
+ Tk.mainloop
67
+ end
68
+
69
+ private
70
+
71
+ def image
72
+ @image ||= TkPhotoImage.new(file: File.expand_path('../advisor.gif', __FILE__))
73
+ end
74
+
75
+ def window
76
+ @window ||= Window.new(image)
77
+ end
78
+
79
+ def after(n, &block)
80
+ window.root.after(n, &block)
81
+ end
82
+
83
+
84
+
85
+ end
86
+ end
@@ -0,0 +1,140 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'tk'
18
+
19
+
20
+ module KnifeAdvisor
21
+ class UI
22
+ class Window
23
+ def initialize(image)
24
+ @image = image
25
+ center!
26
+
27
+ # Create a widget to show the image.
28
+ TkLabel.new(root, background: 'systemTransparent', image: image) do
29
+ place(x: 150, y: 200-(image.height/2))
30
+ end
31
+ end
32
+
33
+ def root
34
+ @root ||= TkRoot.new(background: 'systemTransparent', width: @image.width+150, height: (@image.height/2)+200).tap do |window|
35
+ # Disable the WM decoration (title bar).
36
+ Tk::Wm.overrideredirect(window, 1)
37
+ # Start in front of other windows.
38
+ Tk::Wm.attributes(window, 'topmost', true)
39
+ # Activate transparency mode.
40
+ Tk::Wm.attributes(window, 'transparent', true)
41
+ end
42
+ end
43
+
44
+ def center!
45
+ # Center the window.
46
+ screen_width = TkWinfo.screenwidth(root)
47
+ screen_height = TkWinfo.screenheight(root)
48
+ x = (screen_width/2) - (@image.width/2) - 150
49
+ y = (screen_height/2) - 200
50
+ root.geometry("#{root.width}x#{root.height}+#{x}+#{y}")
51
+ end
52
+
53
+ def say(msg)
54
+ msg = msg.strip
55
+ @msg = msg
56
+ unless @message_canvas
57
+ @message_canvas = TkCanvas.new(root, background: 'systemTransparent', highlightthickness: 0) do
58
+ place(x: 0, y: 0, width: 200, height: 200)
59
+ end
60
+ rounded_rect(@message_canvas, 0, 0, 200, 200, 10, '#FFFFC7')
61
+ end
62
+ if @text
63
+ @text.text = msg
64
+ else
65
+ @text = TkcText.new(@message_canvas, 10, 10, anchor: 'nw', width: 180, text: msg)
66
+ end
67
+ end
68
+
69
+ def append(msg)
70
+ say("#{@msg} #{msg}")
71
+ end
72
+
73
+ def unsay!
74
+ if @message_canvas && @text
75
+ @text.destroy
76
+ @text = nil
77
+ end
78
+ end
79
+
80
+ def clear!
81
+ if @message_canvas
82
+ @message_canvas.destroy
83
+ @message_canvas = nil
84
+ @text = nil
85
+ end
86
+ end
87
+
88
+ def draw_buttons!
89
+ @yes_button = rounded_rect(@message_canvas, 10, 170, 16, 85, 2, '#FFFFC7', 1)
90
+ @yes_button << TkcText.new(@message_canvas, 48, 178, text: 'Yes')
91
+ @no_button = rounded_rect(@message_canvas, 105, 170, 16, 85, 2, '#FFFFC7', 1)
92
+ @no_button << TkcText.new(@message_canvas, 147, 178, text: 'No')
93
+ end
94
+
95
+ def on_yes(&block)
96
+ @yes_button.each do |obj|
97
+ obj.bind('1', &block)
98
+ end
99
+ end
100
+
101
+ def on_no(&block)
102
+ @no_button.each do |obj|
103
+ obj.bind('1', &block)
104
+ end
105
+ end
106
+
107
+ def clear_buttons!
108
+ (@yes_button + @no_button).each(&:destroy)
109
+ @yes_button = @no_button = nil
110
+ end
111
+
112
+ def rounded_rect(canvas, x, y, height, width, radius, color, border=0, border_color='black')
113
+ [].tap do |objs|
114
+ diameter = radius * 2
115
+ # Top left corner.
116
+ objs << TkcOval.new(canvas, x, y, x+diameter, y+diameter, fill: color, width: border, outline: border_color)
117
+ # Top right corner.
118
+ objs << TkcOval.new(canvas, x+width-diameter, y, x+width, y+diameter, fill: color, width: border, outline: border_color)
119
+ # Bottom left corner.
120
+ objs << TkcOval.new(canvas, x, y+height-diameter, x+diameter, y+height, fill: color, width: border, outline: border_color)
121
+ # Bottom right corner.
122
+ objs << TkcOval.new(canvas, x+width-diameter, y+height-diameter, x+width, y+height, fill: color, width: border, outline: border_color)
123
+ objs << TkcRectangle.new(canvas, x+radius, y, x+width-radius, y+height, fill: color, width: 0)
124
+ objs << TkcRectangle.new(canvas, x, y+radius, x+width, y+height-radius, fill: color, width: 0)
125
+ if border > 0
126
+ # Top border.
127
+ objs << TkcLine.new(canvas, x+radius, y, x+width-radius, y, fill: border_color, width: border)
128
+ # Bottom border.
129
+ objs << TkcLine.new(canvas, x+radius, y+height, x+width-radius, y+height, fill: border_color, width: border)
130
+ # Left border.
131
+ objs << TkcLine.new(canvas, x, y+radius, x, y+height-radius, fill: border_color, width: border)
132
+ # Right border
133
+ objs << TkcLine.new(canvas, x+width, y+radius, x+width, y+height-radius, fill: border_color, width: border)
134
+ end
135
+ end
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ module KnifeAdvisor
19
+ VERSION = '1.0.0'
20
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-advisor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Kantrowitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chef
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A knife plugin to get some help!
28
+ email:
29
+ - noah@coderanger.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - README.md
36
+ - Rakefile
37
+ - knife-advisor.gemspec
38
+ - lib/chef/knife/advisor.rb
39
+ - lib/knife_advisor.rb
40
+ - lib/knife_advisor/advisor.gif
41
+ - lib/knife_advisor/ring_buffer.rb
42
+ - lib/knife_advisor/ui.rb
43
+ - lib/knife_advisor/ui/window.rb
44
+ - lib/knife_advisor/version.rb
45
+ homepage: https://github.com/coderanger/knife-advisor
46
+ licenses:
47
+ - Apache 2.0
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.2.2
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: A knife plugin to get some help!
69
+ test_files: []