clc-fork-chef-metal 0.11.beta.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +106 -0
  3. data/LICENSE +201 -0
  4. data/README.md +201 -0
  5. data/Rakefile +6 -0
  6. data/bin/metal +276 -0
  7. data/lib/chef/provider/machine.rb +147 -0
  8. data/lib/chef/provider/machine_batch.rb +130 -0
  9. data/lib/chef/provider/machine_execute.rb +30 -0
  10. data/lib/chef/provider/machine_file.rb +49 -0
  11. data/lib/chef/resource/machine.rb +95 -0
  12. data/lib/chef/resource/machine_batch.rb +20 -0
  13. data/lib/chef/resource/machine_execute.rb +22 -0
  14. data/lib/chef/resource/machine_file.rb +28 -0
  15. data/lib/chef_metal.rb +62 -0
  16. data/lib/chef_metal/action_handler.rb +63 -0
  17. data/lib/chef_metal/add_prefix_action_handler.rb +29 -0
  18. data/lib/chef_metal/chef_machine_spec.rb +64 -0
  19. data/lib/chef_metal/chef_provider_action_handler.rb +72 -0
  20. data/lib/chef_metal/chef_run_data.rb +80 -0
  21. data/lib/chef_metal/convergence_strategy.rb +26 -0
  22. data/lib/chef_metal/convergence_strategy/install_cached.rb +157 -0
  23. data/lib/chef_metal/convergence_strategy/install_msi.rb +56 -0
  24. data/lib/chef_metal/convergence_strategy/install_sh.rb +51 -0
  25. data/lib/chef_metal/convergence_strategy/no_converge.rb +38 -0
  26. data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +180 -0
  27. data/lib/chef_metal/driver.rb +267 -0
  28. data/lib/chef_metal/machine.rb +110 -0
  29. data/lib/chef_metal/machine/basic_machine.rb +82 -0
  30. data/lib/chef_metal/machine/unix_machine.rb +276 -0
  31. data/lib/chef_metal/machine/windows_machine.rb +102 -0
  32. data/lib/chef_metal/machine_spec.rb +78 -0
  33. data/lib/chef_metal/recipe_dsl.rb +84 -0
  34. data/lib/chef_metal/transport.rb +87 -0
  35. data/lib/chef_metal/transport/ssh.rb +235 -0
  36. data/lib/chef_metal/transport/winrm.rb +109 -0
  37. data/lib/chef_metal/version.rb +3 -0
  38. metadata +223 -0
@@ -0,0 +1,109 @@
1
+ require 'chef_metal/transport'
2
+ require 'base64'
3
+ require 'timeout'
4
+
5
+ module ChefMetal
6
+ class Transport
7
+ class WinRM < ChefMetal::Transport
8
+ def initialize(endpoint, type, options, global_config)
9
+ @endpoint = endpoint
10
+ @type = type
11
+ @options = options
12
+ @config = global_config
13
+ end
14
+
15
+ attr_reader :endpoint
16
+ attr_reader :type
17
+ attr_reader :options
18
+ attr_reader :config
19
+
20
+ def execute(command, execute_options = {})
21
+ output = with_execute_timeout(execute_options) do
22
+ session.run_powershell_script(command) do |stdout, stderr|
23
+ stream_chunk(execute_options, stdout, stderr)
24
+ end
25
+ end
26
+ WinRMResult.new(command, execute_options, config, output)
27
+ end
28
+
29
+ def read_file(path)
30
+ result = execute("[Convert]::ToBase64String((Get-Content #{escape(path)} -Encoding byte -ReadCount 0))")
31
+ if result.exitstatus == 0
32
+ Base64.decode64(result.stdout)
33
+ else
34
+ nil
35
+ end
36
+ end
37
+
38
+ def write_file(path, content)
39
+ chunk_size = options[:chunk_size] || 1024
40
+ # TODO if we could marshal this data directly, we wouldn't have to base64 or do this godawful slow stuff :(
41
+ index = 0
42
+ execute("
43
+ $ByteArray = [System.Convert]::FromBase64String(#{escape(Base64.encode64(content[index..index+chunk_size-1]))})
44
+ $file = [System.IO.File]::Open(#{escape(path)}, 'Create', 'Write')
45
+ $file.Write($ByteArray, 0, $ByteArray.Length)
46
+ $file.Close
47
+ ").error!
48
+ index += chunk_size
49
+ while index < content.length
50
+ execute("
51
+ $ByteArray = [System.Convert]::FromBase64String(#{escape(Base64.encode64(content[index..index+chunk_size-1]))})
52
+ $file = [System.IO.File]::Open(#{escape(path)}, 'Append', 'Write')
53
+ $file.Write($ByteArray, 0, $ByteArray.Length)
54
+ $file.Close
55
+ ").error!
56
+ index += chunk_size
57
+ end
58
+ end
59
+
60
+ def disconnect
61
+ #
62
+ end
63
+
64
+ def escape(string)
65
+ "'#{string.gsub("'", "''")}'"
66
+ end
67
+
68
+ protected
69
+
70
+ def session
71
+ @session ||= begin
72
+ require 'kconv' # Really, people? *sigh*
73
+ require 'winrm'
74
+ ::WinRM::WinRMWebService.new(endpoint, type, options)
75
+ end
76
+ end
77
+
78
+ class WinRMResult
79
+ def initialize(command, options, config, output)
80
+ @command = command
81
+ @options = options
82
+ @config = config
83
+ @exitstatus = output[:exitcode]
84
+ @stdout = ''
85
+ @stderr = ''
86
+ output[:data].each do |data|
87
+ @stdout << data[:stdout] if data[:stdout]
88
+ @stderr << data[:stderr] if data[:stderr]
89
+ end
90
+ end
91
+
92
+ attr_reader :stdout
93
+ attr_reader :stderr
94
+ attr_reader :exitstatus
95
+ attr_reader :command
96
+ attr_reader :options
97
+
98
+ def error!
99
+ if exitstatus != 0
100
+ msg = "Error: command '#{command}' exited with code #{exitstatus}.\n"
101
+ msg << "STDOUT: #{stdout}" if !options[:stream] && !options[:stream_stdout] && config[:log_level] != :debug
102
+ msg << "STDERR: #{stderr}" if !options[:stream] && !options[:stream_stderr] && config[:log_level] != :debug
103
+ raise msg
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ module ChefMetal
2
+ VERSION = '0.11.beta.5'
3
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clc-fork-chef-metal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.beta.5
5
+ platform: ruby
6
+ authors:
7
+ - Matt Wrock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-28 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
+ - !ruby/object:Gem::Dependency
28
+ name: net-ssh
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-scp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-ssh-gateway
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: inifile
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cheffish
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.5.beta.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.5.beta.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: chef-metal-fog
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.5.beta.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.beta.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: chef-metal-vagrant
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.4.beta
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.4.beta
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A library for creating machines and infrastructures idempotently in Chef.
154
+ email: matt.wrock@CenturyLinkCloud.com
155
+ executables:
156
+ - metal
157
+ extensions: []
158
+ extra_rdoc_files:
159
+ - README.md
160
+ - CHANGELOG.md
161
+ - LICENSE
162
+ files:
163
+ - CHANGELOG.md
164
+ - LICENSE
165
+ - README.md
166
+ - Rakefile
167
+ - bin/metal
168
+ - lib/chef/provider/machine.rb
169
+ - lib/chef/provider/machine_batch.rb
170
+ - lib/chef/provider/machine_execute.rb
171
+ - lib/chef/provider/machine_file.rb
172
+ - lib/chef/resource/machine.rb
173
+ - lib/chef/resource/machine_batch.rb
174
+ - lib/chef/resource/machine_execute.rb
175
+ - lib/chef/resource/machine_file.rb
176
+ - lib/chef_metal.rb
177
+ - lib/chef_metal/action_handler.rb
178
+ - lib/chef_metal/add_prefix_action_handler.rb
179
+ - lib/chef_metal/chef_machine_spec.rb
180
+ - lib/chef_metal/chef_provider_action_handler.rb
181
+ - lib/chef_metal/chef_run_data.rb
182
+ - lib/chef_metal/convergence_strategy.rb
183
+ - lib/chef_metal/convergence_strategy/install_cached.rb
184
+ - lib/chef_metal/convergence_strategy/install_msi.rb
185
+ - lib/chef_metal/convergence_strategy/install_sh.rb
186
+ - lib/chef_metal/convergence_strategy/no_converge.rb
187
+ - lib/chef_metal/convergence_strategy/precreate_chef_objects.rb
188
+ - lib/chef_metal/driver.rb
189
+ - lib/chef_metal/machine.rb
190
+ - lib/chef_metal/machine/basic_machine.rb
191
+ - lib/chef_metal/machine/unix_machine.rb
192
+ - lib/chef_metal/machine/windows_machine.rb
193
+ - lib/chef_metal/machine_spec.rb
194
+ - lib/chef_metal/recipe_dsl.rb
195
+ - lib/chef_metal/transport.rb
196
+ - lib/chef_metal/transport/ssh.rb
197
+ - lib/chef_metal/transport/winrm.rb
198
+ - lib/chef_metal/version.rb
199
+ homepage: http://wiki.opscode.com/display/chef
200
+ licenses: []
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">"
214
+ - !ruby/object:Gem::Version
215
+ version: 1.3.1
216
+ requirements: []
217
+ rubyforge_project:
218
+ rubygems_version: 2.2.1
219
+ signing_key:
220
+ specification_version: 4
221
+ summary: A library for creating machines and infrastructures idempotently in Chef.
222
+ test_files: []
223
+ has_rdoc: