chef-provisioning-azure 0.1

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: 5dfbd9bf13dae981521da7d5457b5dada54c1699
4
+ data.tar.gz: 2ea395bf16f0f32a109683476a9dc758ef0ff7cb
5
+ SHA512:
6
+ metadata.gz: 3280d914c822f0841cd0e7003a007fdecfbbf5956269a669a2f85ccb7db6db15dbe942073362c31dc989e8113ef6bf67545fcbdc5fa3d8c1419bc23a6a322a15
7
+ data.tar.gz: e6e4a3b21a1c194573f486ffc4c4a804c66e537b4bd395ac77fc126cf4884aa518c39ac520e4f970ca30a81252f582e99ca939a5b9270d75c3bee6b995df7387
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,66 @@
1
+ [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/opscode/chef-provisioning?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
+
3
+ # chef-provisioning-azure
4
+
5
+ Implementation of an Azure driver that relies on the Azure SDK.
6
+
7
+ This is not quite ready for public consumption and is under active
8
+ development.
9
+
10
+
11
+ ## DO NOT USE THIS FOR ANYTHING IMPORTANT
12
+
13
+ At least not yet, you have been warned :grin:
14
+
15
+
16
+ ## What does it do?
17
+
18
+ It can provision and converge a host on Azure with a recipe like the following:
19
+
20
+ ```ruby
21
+ require 'chef/provisioning/azure_driver'
22
+ with_driver 'azure'
23
+
24
+ machine_options = {
25
+ :bootstrap_options => {
26
+ :cloud_service_name => 'chefprovisioning',
27
+ :storage_account_name => 'chefprovisioning',
28
+ #:vm_size => "A7"
29
+ :location => 'West US'
30
+ },
31
+ #:image_id => 'foobar'
32
+ # Until SSH keys are supported (soon)
33
+ :password => "chefm3t4l\\m/"
34
+ }
35
+
36
+ machine 'toad' do
37
+ machine_options machine_options
38
+ end
39
+ ```
40
+
41
+ That's it. No images, nothing else. Do not expect much just yet. Currently you have to specify the
42
+ password you want the initial user to have in your recipe. No, this will not be for very long.
43
+
44
+ ### Setting your credentials
45
+
46
+ Put the right values in ~/.azure/config so that it looks like the following:
47
+
48
+ ```
49
+ [default]
50
+ management_certificate = "/Users/YOU/.azure/azure.pem"
51
+ subscription_id = "YOUR_SUBSCRIPTION_ID"
52
+ ```
53
+
54
+ If you need to generate a certificate for Azure on OSX / Linux you can do it with the following:
55
+
56
+ ```shell
57
+ openssl req \
58
+ -x509 -nodes -days 365 \
59
+ -newkey rsa:1024 -keyout azure.pem -out azure.pem
60
+ ```
61
+
62
+ followed by conversion to the DER format for Azure:
63
+
64
+ ```shell
65
+ openssl x509 -inform pem -in azure.pem -outform der -out azure.cer
66
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+
4
+ task :spec do
5
+ require File.expand_path('spec/run')
6
+ end
@@ -0,0 +1,3 @@
1
+ require 'chef/provisioning'
2
+ require 'chef/provisioning/azure_driver/driver'
3
+ require 'chef/provisioning/azure_driver/resources'
@@ -0,0 +1,291 @@
1
+ require 'chef/mixin/shell_out'
2
+ require 'chef/provisioning/driver'
3
+ require 'chef/provisioning/convergence_strategy/install_cached'
4
+ require 'chef/provisioning/convergence_strategy/install_sh'
5
+ require 'chef/provisioning/convergence_strategy/no_converge'
6
+ require 'chef/provisioning/transport/ssh'
7
+ require 'chef/provisioning/machine/windows_machine'
8
+ require 'chef/provisioning/machine/unix_machine'
9
+ require 'chef/provisioning/machine_spec'
10
+
11
+ require 'chef/provisioning/azure_driver/version'
12
+ require 'chef/provisioning/azure_driver/credentials'
13
+
14
+ require 'yaml'
15
+ require 'azure'
16
+
17
+ class Chef
18
+ module Provisioning
19
+ module AzureDriver
20
+ # Provisions machines using the Azure SDK
21
+ class Driver < Chef::Provisioning::Driver
22
+ attr_reader :region
23
+
24
+ # Construct an AzureDriver object from a URL - used to parse existing URL
25
+ # data to hydrate a driver object.
26
+ # URL scheme:
27
+ # azure:account_id:region
28
+ # @return [AzureDriver] A chef-provisioning Azure driver object for the given URL
29
+ def self.from_url(driver_url, config)
30
+ Driver.new(driver_url, config)
31
+ end
32
+
33
+ def initialize(driver_url, config)
34
+ super
35
+ # TODO: load a specific one if requested by driver config
36
+ credentials = azure_credentials.default
37
+ default_endpoint = 'https://management.core.windows.net'
38
+ Azure.configure do |azure|
39
+ # Configure these 3 properties to use Storage
40
+ azure.management_certificate = credentials[:management_certificate]
41
+ azure.subscription_id = credentials[:subscription_id]
42
+ azure.management_endpoint = credentials[:management_endpoint] || default_endpoint
43
+ end
44
+ end
45
+
46
+ # Take a URL and split it into the appropriate parts of [URL, config]
47
+ # @return [String, Hash] A 2-element array of [URL, config]
48
+ def self.canonicalize_url(driver_url, config)
49
+ url = driver_url.split(':')[0]
50
+ ["azure:#{url}", config]
51
+ end
52
+
53
+ # -- Machine methods --
54
+
55
+ # Allocate a new machine with the Azure API and start it up, without
56
+ # blocking to wait for it. Creates any needed resources to get a machine
57
+ # up and running.
58
+ # @param (see Chef::Provisioning::Driver#allocate_machine)
59
+ def allocate_machine(action_handler, machine_spec, machine_options)
60
+ existing_vm = vm_for(machine_spec)
61
+
62
+ # We don't need to do anything if the existing VM is found
63
+ return if existing_vm
64
+
65
+ bootstrap_options = machine_options[:bootstrap_options] || {}
66
+ bootstrap_options[:vm_size] ||= 'Small'
67
+ bootstrap_options[:cloud_service_name] ||= 'chefprovisioning'
68
+ bootstrap_options[:storage_account_name] ||= 'chefprovisioning'
69
+ bootstrap_options[:location] ||= 'West US'
70
+
71
+ location = bootstrap_options[:location]
72
+
73
+ machine_spec.location = {
74
+ 'driver_url' => driver_url,
75
+ 'driver_version' => Chef::Provisioning::AzureDriver::VERSION,
76
+ 'allocated_at' => Time.now.utc.to_s,
77
+ 'host_node' => action_handler.host_node,
78
+ 'image_id' => machine_options[:image_id],
79
+ 'location' => location,
80
+ 'cloud_service' => bootstrap_options[:cloud_service_name]
81
+ }
82
+
83
+ image_id = machine_options[:image_id] || default_image_for_location(location)
84
+
85
+ params = {
86
+ vm_name: machine_spec.name,
87
+ vm_user: default_ssh_username,
88
+ image: image_id,
89
+ # This is only until SSH keys are added
90
+ password: machine_options[:password],
91
+ location: location
92
+ }
93
+
94
+ Chef::Log.debug "Azure bootstrap options: #{bootstrap_options.inspect}"
95
+
96
+ action_handler.report_progress "Creating #{machine_spec.name} with image #{image_id} in #{location}..."
97
+ vm = azure_vm_service.create_virtual_machine(params, bootstrap_options)
98
+ machine_spec.location['vm_name'] = vm.vm_name
99
+ action_handler.report_progress "Created #{vm.vm_name} in #{location}..."
100
+
101
+ end
102
+
103
+ # (see Chef::Provisioning::Driver#ready_machine)
104
+ def ready_machine(action_handler, machine_spec, machine_options)
105
+ vm = vm_for(machine_spec)
106
+ location = machine_spec.location['location']
107
+
108
+ if vm.nil?
109
+ fail "Machine #{machine_spec.name} does not have a VM associated with it, or the VM does not exist."
110
+ end
111
+
112
+ # TODO: Not sure if this is the right thing to check
113
+ if vm.status != 'ReadyRole'
114
+ action_handler.report_progress "Readying #{machine_spec.name} in #{location}..."
115
+ wait_until_ready(action_handler, machine_spec)
116
+ wait_for_transport(action_handler, machine_spec, machine_options)
117
+ else
118
+ action_handler.report_progress "#{machine_spec.name} already ready in #{location}!"
119
+ end
120
+
121
+ machine_for(machine_spec, machine_options, vm)
122
+ end
123
+
124
+ # (see Chef::Provisioning::Driver#destroy_machine)
125
+ def destroy_machine(action_handler, machine_spec, machine_options)
126
+ vm = vm_for(machine_spec)
127
+ vm_name = machine_spec.name
128
+ cloud_service = machine_spec.location['cloud_service']
129
+
130
+ # Check if we need to proceed
131
+ return if vm.nil? || vm_name.nil? || cloud_service.nil?
132
+
133
+ # Skip if we don't actually need to do anything
134
+ return unless action_handler.should_perform_actions
135
+
136
+ # TODO: action_handler.do |block| ?
137
+ action_handler.report_progress "Destroying VM #{machine_spec.name}!"
138
+ azure_vm_service.delete_virtual_machine(vm_name, cloud_service)
139
+ action_handler.report_progress "Destroyed VM #{machine_spec.name}!"
140
+ end
141
+
142
+ private
143
+
144
+ def machine_for(machine_spec, machine_options, vm = nil)
145
+ vm ||= vm_for(machine_spec)
146
+
147
+ fail "VM for node #{machine_spec.name} has not been created!" unless vm
148
+
149
+ transport = transport_for(machine_spec, machine_options, vm)
150
+ convergence_strategy = convergence_strategy_for(machine_spec, machine_options)
151
+
152
+ if machine_spec.location['is_windows']
153
+ Chef::Provisioning::Machine::WindowsMachine.new(machine_spec, transport, convergence_strategy)
154
+ else
155
+ Chef::Provisioning::Machine::UnixMachine.new(machine_spec, transport, convergence_strategy)
156
+ end
157
+ end
158
+
159
+ def azure_vm_service
160
+ @vm_service ||= Azure::VirtualMachineManagementService.new
161
+ end
162
+
163
+ def default_ssh_username
164
+ 'ubuntu'
165
+ end
166
+
167
+ def vm_for(machine_spec)
168
+ if machine_spec.location && machine_spec.name
169
+ existing_vms = azure_vm_service.list_virtual_machines
170
+ existing_vms.select { |vm| vm.vm_name == machine_spec.name }.first
171
+ else
172
+ nil
173
+ end
174
+ end
175
+
176
+ def transport_for(machine_spec, machine_options, vm)
177
+ # TODO winrm
178
+ create_ssh_transport(machine_spec, machine_options, vm)
179
+ end
180
+
181
+ def azure_credentials
182
+ # Grab the list of possible credentials
183
+ @azure_credentials ||= if driver_options[:azure_credentials]
184
+ driver_options[:azure_credentials]
185
+ else
186
+ credentials = Credentials.new
187
+ if driver_options[:azure_config_file]
188
+ credentials.load_ini(driver_options.delete(:azure_config_file))
189
+ else
190
+ credentials.load_default
191
+ end
192
+ credentials
193
+ end
194
+ end
195
+
196
+ def default_image_for_location(location)
197
+ Chef::Log.debug("Choosing default image for region '#{location}'")
198
+
199
+ case location
200
+ when 'East US'
201
+ when 'Southeast Asia'
202
+ when 'West US'
203
+ 'b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_1-LTS-amd64-server-20140927-en-us-30GB'
204
+ else
205
+ raise 'Unsupported location!'
206
+ end
207
+ end
208
+
209
+ def create_ssh_transport(machine_spec, machine_options, vm)
210
+ username = machine_spec.location['ssh_username'] || default_ssh_username
211
+ tcp_endpoint = vm.tcp_endpoints.select { |tcp| tcp[:name] == 'SSH' }.first
212
+ remote_host = tcp_endpoint[:vip]
213
+
214
+ # TODO: not this... replace with SSH key ASAP, only for getting this thing going...
215
+ ssh_options = { password: machine_options[:password] }
216
+
217
+ options = {}
218
+ options[:prefix] = 'sudo ' if machine_spec.location[:sudo] || username != 'root'
219
+
220
+ # Enable pty by default
221
+ # TODO: why?
222
+ options[:ssh_pty_enable] = true
223
+ options[:ssh_gateway] ||= machine_spec.location['ssh_gateway']
224
+
225
+ Chef::Provisioning::Transport::SSH.new(remote_host, username, ssh_options, options, config)
226
+ end
227
+
228
+ def convergence_strategy_for(machine_spec, machine_options)
229
+ convergence_options = machine_options[:convergence_options]
230
+ # Defaults
231
+ unless machine_spec.location
232
+ return Chef::Provisioning::ConvergenceStrategy::NoConverge.new(convergence_options, config)
233
+ end
234
+
235
+ if machine_spec.location['is_windows']
236
+ Chef::Provisioning::ConvergenceStrategy::InstallMsi.new(convergence_options, config)
237
+ elsif machine_options[:cached_installer]
238
+ Chef::Provisioning::ConvergenceStrategy::InstallCached.new(convergence_options, config)
239
+ else
240
+ Chef::Provisioning::ConvergenceStrategy::InstallSh.new(convergence_options, config)
241
+ end
242
+ end
243
+
244
+ def wait_until_ready(action_handler, machine_spec)
245
+ vm = vm_for(machine_spec)
246
+
247
+ # If the machine is ready, nothing to do
248
+ return if vm.status == 'ReadyRole'
249
+
250
+ # Skip if we don't actually need to do anything
251
+ return unless action_handler.should_perform_actions
252
+
253
+ time_elapsed = 0
254
+ sleep_time = 10
255
+ max_wait_time = 120
256
+
257
+ action_handler.report_progress "waiting for #{machine_spec.name} to be ready ..."
258
+ while time_elapsed < 120 && vm.status != 'ReadyRole'
259
+ action_handler.report_progress "#{time_elapsed}/#{max_wait_time}s..."
260
+ sleep(sleep_time)
261
+ time_elapsed += sleep_time
262
+ # Azure caches results
263
+ vm = vm_for(machine_spec)
264
+ end
265
+ action_handler.report_progress "#{machine_spec.name} is now ready"
266
+ end
267
+
268
+ def wait_for_transport(action_handler, machine_spec, machine_options)
269
+ vm = vm_for(machine_spec)
270
+ transport = transport_for(machine_spec, machine_options, vm)
271
+
272
+ return if transport.available?
273
+ return unless action_handler.should_perform_actions
274
+
275
+ time_elapsed = 0
276
+ sleep_time = 10
277
+ max_wait_time = 120
278
+
279
+ action_handler.report_progress "Waiting for transport on #{machine_spec.name} ..."
280
+ while time_elapsed < 120 && !transport.available?
281
+ action_handler.report_progress "#{time_elapsed}/#{max_wait_time}s..."
282
+ sleep(sleep_time)
283
+ time_elapsed += sleep_time
284
+ end
285
+ action_handler.report_progress "Transport to #{machine_spec.name} is now up!"
286
+ end
287
+
288
+ end
289
+ end
290
+ end
291
+ end
@@ -0,0 +1,25 @@
1
+ class Chef
2
+ module Provisioning
3
+ module AzureDriver
4
+ # Represents available options when bootstrapping a host on Azure
5
+ # These are used to tell Azure some initial pieces of information
6
+ # for building a new VM.
7
+ class BootstrapOptions < Chef::Provisioning::BootstrapOptions
8
+ # @return [String] The name of the VM
9
+ attr_accessor :vm_name
10
+
11
+ # @return [String] The VM user
12
+ attr_accessor :vm_user
13
+
14
+ # @return [String] The identifier for the VM image to use
15
+ attr_accessor :image
16
+
17
+ # @return [String] the password to use
18
+ attr_accessor :password
19
+
20
+ # @return [String] The Azure location to store this in
21
+ attr_accessor :location
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ class Chef
2
+ module Provisioning
3
+ module AzureDriver
4
+ # A collection of useful Azure-specific constants
5
+ class Constants
6
+ # Constants around transport mechanisms available
7
+ class Transport
8
+ HTTP = 'http'
9
+ HTTPS = 'https'
10
+ end
11
+
12
+ # Constants for describing VM sizes in Azure
13
+ class MachineSize
14
+ # Put in machine specs here...
15
+ EXTRASMALL = 'ExtraSmall'
16
+ # What is this?
17
+ SMALL = 'Small'
18
+ # Are these now A2?
19
+ MEDIUM = 'Medium'
20
+ LARGE = 'Large'
21
+ XLARGE = 'ExtraLarge'
22
+ A5 = 'A5'
23
+ A6 = 'A6'
24
+ A7 = 'A7'
25
+ BASIC_A0 = 'Basic_A0'
26
+ BASIC_A1 = 'Basic_A1'
27
+ BASIC_A2 = 'Basic_A2'
28
+ BASIC_A3 = 'Basic_A3'
29
+ BASIC_A4 = 'Basic_A4'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,73 @@
1
+ require 'inifile'
2
+
3
+ class Chef
4
+ module Provisioning
5
+ module AzureDriver
6
+ # Reads in a credentials file from a config file and presents them
7
+ class Credentials
8
+ CONFIG_PATH = "#{ENV['HOME']}/.azure/config"
9
+
10
+ def initialize
11
+ @credentials = {}
12
+ load_default
13
+ end
14
+
15
+ include Enumerable
16
+
17
+ def default
18
+ if @credentials.size == 0
19
+ fail "No credentials loaded! Do you have a #{CONFIG_PATH}?"
20
+ end
21
+ default_key = ENV['AZURE_DEFAULT_PROFILE'] || 'default'
22
+ @credentials[default_key] || @credentials.first[1]
23
+ end
24
+
25
+ def keys
26
+ @credentials.keys
27
+ end
28
+
29
+ def [](name)
30
+ @credentials[name]
31
+ end
32
+
33
+ def each(&block)
34
+ @credentials.each(&block)
35
+ end
36
+
37
+ def load_ini(credentials_ini_file)
38
+ inifile = IniFile.load(File.expand_path(credentials_ini_file))
39
+ if inifile
40
+ inifile.each_section do |section|
41
+ if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/
42
+ profile_name = $1.strip
43
+ profile = inifile[section].inject({}) do |result, pair|
44
+ result[pair[0].to_sym] = pair[1]
45
+ result
46
+ end
47
+ profile[:name] = profile_name
48
+ @credentials[profile_name] = profile
49
+ end
50
+ end
51
+ else
52
+ # Get it to throw an error
53
+ File.open(File.expand_path(credentials_ini_file)) do
54
+ end
55
+ end
56
+ end
57
+
58
+ def load_default
59
+ config_file = ENV['AZURE_CONFIG_FILE'] || File.expand_path(CONFIG_PATH)
60
+ load_ini(config_file) if File.file?(config_file)
61
+ end
62
+
63
+ def self.method_missing(name, *args, &block)
64
+ singleton.send(name, *args, &block)
65
+ end
66
+
67
+ def self.singleton
68
+ @azure_credentials ||= Credentials.new
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,62 @@
1
+ require 'chef/provisioning/machine_options'
2
+ require 'chef/provisioning/azure_driver/constants'
3
+
4
+ # Chef Provisioning Azure driver
5
+ class Chef
6
+ module Provisioning
7
+ module AzureDriver
8
+ # Represents available machine provisioning options for Azure
9
+ # These are used to tell Azure how to construct a new VM
10
+ class MachineOptions < Chef::Provisioning::MachineOptions
11
+ # @return [String] Storage account name.
12
+ attr_accessor :storage_account_name
13
+
14
+ # @return [String] WinRM transport mechanism ("http", or "https").
15
+ # Defaults to "http".
16
+ attr_accessor :winrm_transport
17
+
18
+ # @return [String] Cloud service name.
19
+ attr_accessor :cloud_service_name
20
+
21
+ # @return [String] Deployment name.
22
+ attr_accessor :deployment_name
23
+
24
+ # @return [Array] Array of ports to enable.
25
+ # Can be in +port+ or +src:dest+ format.
26
+ attr_accessor :tcp_endpoints
27
+
28
+ # @return [Pathname] Path to the private key.
29
+ attr_accessor :private_key_file
30
+
31
+ # @return [Pathname] Path to the certificate file.
32
+ attr_accessor :certificate_file
33
+
34
+ # @return [Integer] The SSH port to listen on.
35
+ # Defaults to 22
36
+ attr_accessor :ssh_port
37
+
38
+ # @return [Chef::Provisioning::AzureDriver::Constants::MachineSize] The Azure machine size.
39
+ attr_accessor :vm_size
40
+
41
+ # @return [String] Name of the affinity group being used.
42
+ attr_accessor :affinity_group_name
43
+
44
+ # @return [String] Virtual network name.
45
+ attr_accessor :virtual_network_name
46
+
47
+ # @return [String] Subnet name.
48
+ attr_accessor :subnet_name
49
+
50
+ # @return [String] Availability set name.
51
+ attr_accessor :availability_set_name
52
+
53
+ def initialize
54
+ # Set defaults
55
+ self.winrm_transport = 'http'
56
+ self.ssh_port = 22
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ resources = %w()
2
+
3
+ resources.each do |r|
4
+ Chef::Log.debug "Loading #{r}"
5
+ require "chef/resource/azure_#{r}"
6
+ require "chef/provider/azure_#{r}"
7
+ end
@@ -0,0 +1,8 @@
1
+ # Chef Provisioning Azure driver
2
+ class Chef
3
+ module Provisioning
4
+ module AzureDriver
5
+ VERSION = '0.1'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'chef/provisioning/azure_driver/driver'
2
+
3
+ Chef::Provisioning.register_driver_class('azure', Chef::Provisioning::AzureDriver::Driver)
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-provisioning-azure
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - John Ewart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-05 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: chef-provisioning
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: azure
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
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
+ description: Provisioner for creating Azure things in Chef Provisioning.
98
+ email: jewart@getchef.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.md
103
+ - LICENSE
104
+ files:
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - lib/chef/provisioning/azure_driver.rb
109
+ - lib/chef/provisioning/azure_driver/azure_driver.rb
110
+ - lib/chef/provisioning/azure_driver/bootstrap_options.rb
111
+ - lib/chef/provisioning/azure_driver/constants.rb
112
+ - lib/chef/provisioning/azure_driver/credentials.rb
113
+ - lib/chef/provisioning/azure_driver/machine_options.rb
114
+ - lib/chef/provisioning/azure_driver/resources.rb
115
+ - lib/chef/provisioning/azure_driver/version.rb
116
+ - lib/chef/provisioning/driver_init/driver_init/azure.rb
117
+ homepage: https://github.com/opscode/chef-provisioning-azure
118
+ licenses: []
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Provisioner for creating Azure things in Chef Provisioning.
140
+ test_files: []
141
+ has_rdoc: