chef-metal 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +160 -0
  4. data/Rakefile +6 -0
  5. data/lib/chef/provider/fog_key_pair.rb +106 -0
  6. data/lib/chef/provider/machine.rb +60 -0
  7. data/lib/chef/provider/machine_file.rb +39 -0
  8. data/lib/chef/provider/vagrant_box.rb +44 -0
  9. data/lib/chef/provider/vagrant_cluster.rb +39 -0
  10. data/lib/chef/resource/fog_key_pair.rb +34 -0
  11. data/lib/chef/resource/machine.rb +56 -0
  12. data/lib/chef/resource/machine_file.rb +25 -0
  13. data/lib/chef/resource/vagrant_box.rb +18 -0
  14. data/lib/chef/resource/vagrant_cluster.rb +16 -0
  15. data/lib/chef_metal.rb +84 -0
  16. data/lib/chef_metal/aws_credentials.rb +55 -0
  17. data/lib/chef_metal/convergence_strategy.rb +15 -0
  18. data/lib/chef_metal/convergence_strategy/install_msi.rb +41 -0
  19. data/lib/chef_metal/convergence_strategy/install_sh.rb +36 -0
  20. data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +140 -0
  21. data/lib/chef_metal/inline_resource.rb +88 -0
  22. data/lib/chef_metal/machine.rb +79 -0
  23. data/lib/chef_metal/machine/basic_machine.rb +79 -0
  24. data/lib/chef_metal/machine/unix_machine.rb +108 -0
  25. data/lib/chef_metal/machine/windows_machine.rb +94 -0
  26. data/lib/chef_metal/provisioner.rb +71 -0
  27. data/lib/chef_metal/provisioner/fog_provisioner.rb +378 -0
  28. data/lib/chef_metal/provisioner/vagrant_provisioner.rb +327 -0
  29. data/lib/chef_metal/recipe_dsl.rb +26 -0
  30. data/lib/chef_metal/transport.rb +36 -0
  31. data/lib/chef_metal/transport/ssh.rb +157 -0
  32. data/lib/chef_metal/transport/winrm.rb +91 -0
  33. data/lib/chef_metal/version.rb +3 -0
  34. metadata +175 -0
@@ -0,0 +1,91 @@
1
+ require 'base64'
2
+
3
+ module ChefMetal
4
+ class Transport
5
+ class WinRM
6
+ def initialize(endpoint, type, options = {})
7
+ @endpoint = endpoint
8
+ @type = type
9
+ @options = options
10
+ end
11
+
12
+ attr_reader :endpoint
13
+ attr_reader :type
14
+ attr_reader :options
15
+
16
+ def execute(command)
17
+ output = session.run_powershell_script(command)
18
+ WinRMResult.new(output)
19
+ end
20
+
21
+ def read_file(path)
22
+ result = execute("[Convert]::ToBase64String((Get-Content #{escape(path)} -Encoding byte -ReadCount 0))")
23
+ if result.exitstatus == 0
24
+ Base64.decode64(result.stdout)
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def write_file(path, content)
31
+ chunk_size = options[:chunk_size] || 1024
32
+ # TODO if we could marshal this data directly, we wouldn't have to base64 or do this godawful slow stuff :(
33
+ index = 0
34
+ execute("
35
+ $ByteArray = [System.Convert]::FromBase64String(#{escape(Base64.encode64(content[index..index+chunk_size-1]))})
36
+ $file = [System.IO.File]::Open(#{escape(path)}, 'Create', 'Write')
37
+ $file.Write($ByteArray, 0, $ByteArray.Length)
38
+ $file.Close
39
+ ").error!
40
+ index += chunk_size
41
+ while index < content.length
42
+ execute("
43
+ $ByteArray = [System.Convert]::FromBase64String(#{escape(Base64.encode64(content[index..index+chunk_size-1]))})
44
+ $file = [System.IO.File]::Open(#{escape(path)}, 'Append', 'Write')
45
+ $file.Write($ByteArray, 0, $ByteArray.Length)
46
+ $file.Close
47
+ ").error!
48
+ index += chunk_size
49
+ end
50
+ end
51
+
52
+ def disconnect
53
+ #
54
+ end
55
+
56
+ def escape(string)
57
+ "'#{string.gsub("'", "''")}'"
58
+ end
59
+
60
+ protected
61
+
62
+ def session
63
+ @session ||= begin
64
+ require 'kconv' # Really, people? *sigh*
65
+ require 'winrm'
66
+ ::WinRM::WinRMWebService.new(endpoint, type, options)
67
+ end
68
+ end
69
+
70
+ class WinRMResult
71
+ def initialize(output)
72
+ @exitstatus = output[:exitcode]
73
+ @stdout = ''
74
+ @stderr = ''
75
+ output[:data].each do |data|
76
+ @stdout << data[:stdout] if data[:stdout]
77
+ @stderr << data[:stderr] if data[:stderr]
78
+ end
79
+ end
80
+
81
+ attr_reader :stdout
82
+ attr_reader :stderr
83
+ attr_reader :exitstatus
84
+
85
+ def error!
86
+ raise "Error: code #{exitstatus}.\nSTDOUT:#{stdout}\nSTDERR:#{stderr}" if exitstatus != 0
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ module ChefMetal
2
+ VERSION = '0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-metal
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - John Keiser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-21 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: cheffish
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ssh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-scp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.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.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: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A library for creating machines and infrastructures idempotently in Chef.
112
+ email: jkeiser@opscode.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - README.md
117
+ - LICENSE
118
+ files:
119
+ - Rakefile
120
+ - LICENSE
121
+ - README.md
122
+ - lib/chef/provider/fog_key_pair.rb
123
+ - lib/chef/provider/machine.rb
124
+ - lib/chef/provider/machine_file.rb
125
+ - lib/chef/provider/vagrant_box.rb
126
+ - lib/chef/provider/vagrant_cluster.rb
127
+ - lib/chef/resource/fog_key_pair.rb
128
+ - lib/chef/resource/machine.rb
129
+ - lib/chef/resource/machine_file.rb
130
+ - lib/chef/resource/vagrant_box.rb
131
+ - lib/chef/resource/vagrant_cluster.rb
132
+ - lib/chef_metal/aws_credentials.rb
133
+ - lib/chef_metal/convergence_strategy/install_msi.rb
134
+ - lib/chef_metal/convergence_strategy/install_sh.rb
135
+ - lib/chef_metal/convergence_strategy/precreate_chef_objects.rb
136
+ - lib/chef_metal/convergence_strategy.rb
137
+ - lib/chef_metal/inline_resource.rb
138
+ - lib/chef_metal/machine/basic_machine.rb
139
+ - lib/chef_metal/machine/unix_machine.rb
140
+ - lib/chef_metal/machine/windows_machine.rb
141
+ - lib/chef_metal/machine.rb
142
+ - lib/chef_metal/provisioner/fog_provisioner.rb
143
+ - lib/chef_metal/provisioner/vagrant_provisioner.rb
144
+ - lib/chef_metal/provisioner.rb
145
+ - lib/chef_metal/recipe_dsl.rb
146
+ - lib/chef_metal/transport/ssh.rb
147
+ - lib/chef_metal/transport/winrm.rb
148
+ - lib/chef_metal/transport.rb
149
+ - lib/chef_metal/version.rb
150
+ - lib/chef_metal.rb
151
+ homepage: http://wiki.opscode.com/display/chef
152
+ licenses: []
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.0.3
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: A library for creating machines and infrastructures idempotently in Chef.
174
+ test_files: []
175
+ has_rdoc: