vagrant-azure 1.0.1

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/.gitignore +12 -0
  3. data/Gemfile +19 -0
  4. data/LICENSE +4 -0
  5. data/README.md +9 -0
  6. data/Rakefile +14 -0
  7. data/lib/vagrant-azure.rb +24 -0
  8. data/lib/vagrant-azure/action.rb +249 -0
  9. data/lib/vagrant-azure/action/connect_azure.rb +41 -0
  10. data/lib/vagrant-azure/action/provision.rb +40 -0
  11. data/lib/vagrant-azure/action/rdp.rb +62 -0
  12. data/lib/vagrant-azure/action/read_ssh_info.rb +51 -0
  13. data/lib/vagrant-azure/action/read_state.rb +46 -0
  14. data/lib/vagrant-azure/action/restart_vm.rb +27 -0
  15. data/lib/vagrant-azure/action/run_instance.rb +111 -0
  16. data/lib/vagrant-azure/action/start_instance.rb +35 -0
  17. data/lib/vagrant-azure/action/stop_instance.rb +38 -0
  18. data/lib/vagrant-azure/action/terminate_instance.rb +34 -0
  19. data/lib/vagrant-azure/action/wait_for_state.rb +49 -0
  20. data/lib/vagrant-azure/command/rdp/command.rb +21 -0
  21. data/lib/vagrant-azure/config.rb +147 -0
  22. data/lib/vagrant-azure/driver.rb +79 -0
  23. data/lib/vagrant-azure/plugin.rb +87 -0
  24. data/lib/vagrant-azure/provider.rb +70 -0
  25. data/lib/vagrant-azure/provisioner/puppet.rb +109 -0
  26. data/lib/vagrant-azure/scripts/check_winrm.ps1 +41 -0
  27. data/lib/vagrant-azure/scripts/export_vm.ps1 +31 -0
  28. data/lib/vagrant-azure/scripts/file_sync.ps1 +145 -0
  29. data/lib/vagrant-azure/scripts/host_info.ps1 +25 -0
  30. data/lib/vagrant-azure/scripts/hyperv_manager.ps1 +36 -0
  31. data/lib/vagrant-azure/scripts/run_in_remote.ps1 +32 -0
  32. data/lib/vagrant-azure/scripts/upload_file.ps1 +95 -0
  33. data/lib/vagrant-azure/scripts/utils/create_session.ps1 +34 -0
  34. data/lib/vagrant-azure/scripts/utils/write_messages.ps1 +18 -0
  35. data/lib/vagrant-azure/version.rb +10 -0
  36. data/locales/en.yml +14 -0
  37. data/vagrant-azure.gemspec +58 -0
  38. metadata +167 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f78492e99a52fd8ee84a9f22e445cdf2bc454d53
4
+ data.tar.gz: d51719729d6bed714ad83e42c7f65469607e8f3b
5
+ SHA512:
6
+ metadata.gz: ae447dd53d2cd7bc70b694a2d211d89e38c4dc074f05fbe5e8c69ac2bc8d68e0e2034eb14a4a93fa54d8ffd8a84daf9fe2a4b5d4291f303f33c05f3a1340425d
7
+ data.tar.gz: cf0b15cc0b0f116c115bd7b9c4ceb11df7a6c36e348c9b6d0aae467359ec32ce15dbaa568dd59021637be642298c7c5ca7a21d8e4a39977c17f218df4b5973b2
@@ -0,0 +1,12 @@
1
+ id
2
+ .DS_Store
3
+ Gemfile.lock
4
+ azure.box
5
+ Vagrantfile
6
+ !example_box/Vagrantfile
7
+ babu
8
+ example_box/
9
+ *.rdp
10
+ pkg/
11
+ gem/
12
+ manifests/
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+
6
+ source 'https://rubygems.org'
7
+
8
+ gemspec
9
+
10
+ group :development do
11
+ # We depend on Vagrant for development, but we don't add it as a
12
+ # gem dependency because we expect to be installed within the
13
+ # Vagrant environment itself using `vagrant plugin`.
14
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
15
+ end
16
+
17
+ group :plugins do
18
+ gem 'vagrant-azure', path: '.'
19
+ end
data/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at
3
+ http://www.apache.org/licenses/LICENSE-2.0
4
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
@@ -0,0 +1,9 @@
1
+ # Vagrant Azure Provider
2
+
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds [Windows Azure](https://www.windowsazure.com)
4
+ provider to Vagrant, allowing Vagrant to control and provision machines in
5
+ Windows Azure.
6
+
7
+ **NOTE:** This plugin requires Vagrant 1.2+,
8
+
9
+ ## Configuration
@@ -0,0 +1,14 @@
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+
6
+ require 'rubygems'
7
+ require 'bundler/setup'
8
+
9
+ $stdout.sync = true
10
+ $stderr.sync = true
11
+
12
+ Dir.chdir(File.expand_path('../', __FILE__))
13
+
14
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,24 @@
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+ require 'pathname'
6
+ require 'vagrant-azure/plugin'
7
+
8
+ module VagrantPlugins
9
+ module WinAzure
10
+ lib_path = Pathname.new(File.expand_path('../vagrant-azure', __FILE__))
11
+ autoload :Action, lib_path.join('action')
12
+ autoload :Error, lib_path.join('errors')
13
+ autoload :Driver, lib_path.join('driver')
14
+
15
+ require lib_path.join('provisioner/puppet')
16
+
17
+ # This returns the path to the source of this plugin.
18
+ #
19
+ # @return [Pathname]
20
+ def self.source_root
21
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,249 @@
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+ require 'pathname'
6
+
7
+ require 'vagrant/action/builder'
8
+
9
+ module VagrantPlugins
10
+ module WinAzure
11
+ module Action
12
+ # Include the built-in modules so we can use them as top-level things.
13
+ include Vagrant::Action::Builtin
14
+
15
+ # This action is called to halt the remote machine.
16
+ def self.action_halt
17
+ Vagrant::Action::Builder.new.tap do |b|
18
+ b.use ConfigValidate
19
+ b.use Call, IsState, :NotCreated do |env, b2|
20
+ if env[:result]
21
+ b2.use Message, I18n.t('vagrant_azure.not_created')
22
+ next
23
+ end
24
+
25
+ b2.use ConnectAzure
26
+ b2.use StopInstance
27
+ end
28
+ end
29
+ end
30
+
31
+ # This action is called to terminate the remote machine.
32
+ def self.action_destroy
33
+ Vagrant::Action::Builder.new.tap do |b|
34
+ b.use Call, DestroyConfirm do |env, b2|
35
+ if env[:result]
36
+ b2.use ConfigValidate
37
+ b.use Call, IsState, :NotCreated do |env2, b3|
38
+ if env2[:result]
39
+ b3.use Message, I18n.t('vagrant_azure.not_created')
40
+ next
41
+ end
42
+ end
43
+
44
+ b2.use ConnectAzure
45
+ b2.use TerminateInstance
46
+ b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
47
+ else
48
+ env[:machine].id =~ /@/
49
+ b2.use Message, I18n.t(
50
+ 'vagrant_azure.will_not_destroy',
51
+ :name => $`
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ # This action is called when `vagrant provision` is called.
59
+ def self.action_provision
60
+ Vagrant::Action::Builder.new.tap do |b|
61
+ b.use ConnectAzure
62
+ b.use ConfigValidate
63
+ b.use Call, IsState, :NotCreated do |env, b2|
64
+ if env[:result]
65
+ b2.use Message, I18n.t('vagrant_azure.not_created')
66
+ next
67
+ end
68
+
69
+ b2.use Provision
70
+ # b2.use SyncFolders
71
+ end
72
+ end
73
+ end
74
+
75
+ # This action is called to read the SSH info of the machine. The
76
+ # resulting state is expected to be put into the `:machine_ssh_info` key.
77
+ def self.action_read_ssh_info
78
+ Vagrant::Action::Builder.new.tap do |b|
79
+ b.use ConfigValidate
80
+ b.use ConnectAzure
81
+ b.use ReadSSHInfo, 22
82
+ end
83
+ end
84
+
85
+ def self.action_read_rdp_info
86
+ Vagrant::Action::Builder.new.tap do |b|
87
+ b.use ConfigValidate
88
+ b.use ConnectAzure
89
+ b.use ReadSSHInfo, 3389
90
+ end
91
+ end
92
+
93
+ def self.action_read_winrm_info
94
+ Vagrant::Action::Builder.new.tap do |b|
95
+ b.use ConfigValidate
96
+ b.use ConnectAzure
97
+ b.use ReadSSHInfo, 5986
98
+ end
99
+ end
100
+
101
+ def self.action_read_state
102
+ Vagrant::Action::Builder.new.tap do |b|
103
+ b.use ConfigValidate
104
+ b.use ConnectAzure
105
+ b.use ReadState
106
+ end
107
+ end
108
+
109
+ # This action is called to SSH into the machine
110
+ def self.action_ssh
111
+ Vagrant::Action::Builder.new.tap do |b|
112
+ b.use ConfigValidate
113
+ b.use Call, IsState, :NotCreated do |env, b2|
114
+ if env[:result]
115
+ b2.use Message, I18n.t('vagrant_azure.not_created')
116
+ next
117
+ end
118
+
119
+ b2.use SSHExec
120
+ end
121
+ end
122
+ end
123
+
124
+ def self.action_rdp
125
+ Vagrant::Action::Builder.new.tap do |b|
126
+ b.use ConfigValidate
127
+ b.use Call, IsState, :NotCreated do |env1, b1|
128
+ if env1[:result]
129
+ b1.use Message, I18n.t('vagrant_azure.not_created')
130
+ next
131
+ end
132
+
133
+ b1.use Call, IsState, :ReadyRole do |env2, b2|
134
+ if !env2[:result]
135
+ b2.use Message, I18n.t('vagrant_azure.rdp_not_ready')
136
+ next
137
+ end
138
+
139
+ b2.use Rdp
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ def self.action_ssh_run
146
+ Vagrant::Action::Builder.new.tap do |b|
147
+ b.use ConfigValidate
148
+ b.use Call, IsState, :NotCreated do |env, b2|
149
+ if env[:result]
150
+ b2.use Message, I18n.t('vagrant_azure.not_created')
151
+ next
152
+ end
153
+
154
+ b2.use SSHRun
155
+ end
156
+ end
157
+ end
158
+
159
+ def self.action_prepare_boot
160
+ Vagrant::Action::Builder.new.tap do |b|
161
+ b.use Provision
162
+ # b.use SyncFolders
163
+ # b.use WarnNetworks
164
+ end
165
+ end
166
+
167
+ # This action is called to bring the box up from nothing
168
+ def self.action_up
169
+ Vagrant::Action::Builder.new.tap do |b|
170
+ b.use HandleBoxUrl
171
+ b.use ConfigValidate
172
+ b.use ConnectAzure
173
+ b.use Call, IsState, :NotCreated do |env1, b1|
174
+ if !env1[:result]
175
+ b1.use Call, IsState, :StoppedDeallocated do |env2, b2|
176
+ if env2[:result]
177
+ b2.use action_prepare_boot
178
+ b2.use StartInstance # start this instance again
179
+ b2.use Call, WaitForState, :ReadyRole do |env3, b3|
180
+ if env3[:result]
181
+ env3[:machine].id =~ /@/
182
+ b3.use Message, I18n.t(
183
+ 'vagrant_azure.vm_started', :name => $`
184
+ )
185
+ end
186
+ end
187
+ else
188
+ b2.use Message, I18n.t(
189
+ 'vagrant_azure.already_status', :status => 'created'
190
+ )
191
+ end
192
+ end
193
+ else
194
+ b1.use RunInstance # Launch a new instance
195
+ b1.use Call, WaitForState, :ReadyRole do |env2, b2|
196
+ if env2[:result]
197
+ env2[:machine].id =~ /@/
198
+ b2.use Message, I18n.t(
199
+ 'vagrant_azure.vm_started', :name => $`
200
+ )
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ def self.action_reload
209
+ Vagrant::Action::Builder.new.tap do |b|
210
+ b.use ConfigValidate
211
+ b.use ConnectAzure
212
+ b.use Call, IsState, :NotCreated do |env, b2|
213
+ if env[:result]
214
+ b2.use Message, I18n.t('vagrant_azure.not_created')
215
+ next
216
+ end
217
+
218
+ b2.use RestartVM
219
+ b2.use Call, WaitForState, :ReadyRole do |env2, b3|
220
+ if env2[:result]
221
+ env2[:machine].id =~ /@/
222
+ b3.use Message, I18n.t(
223
+ 'vagrant_azure.vm_started', :name => $`
224
+ )
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ # The autoload farm
232
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
233
+ autoload :ConnectAzure, action_root.join('connect_azure')
234
+ autoload :Provision, action_root.join('provision')
235
+ autoload :Rdp, action_root.join('rdp')
236
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
237
+ autoload :ReadState, action_root.join('read_state')
238
+ autoload :RestartVM, action_root.join('restart_vm')
239
+ autoload :RunInstance, action_root.join('run_instance')
240
+ autoload :StartInstance, action_root.join('start_instance')
241
+ autoload :StopInstance, action_root.join('stop_instance')
242
+ # autoload :SyncFolders, action_root.join('sync_folders')
243
+ autoload :TerminateInstance, action_root.join('terminate_instance')
244
+ # autoload :TimedProvision, action_root.join('timed_provision')
245
+ # autoload :WarnNetworks, action_root.join('warn_networks')
246
+ autoload :WaitForState, action_root.join('wait_for_state')
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,41 @@
1
+ #---------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+ require 'azure'
6
+ require 'log4r'
7
+
8
+ module VagrantPlugins
9
+ module WinAzure
10
+ module Action
11
+ class ConnectAzure
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new('vagrant_azure::action::connect_aws')
15
+ end
16
+
17
+ def call (env)
18
+ config = env[:machine].provider_config
19
+
20
+ env[:ui].warn "Subscription ID: [#{config.subscription_id}]"
21
+ env[:ui].warn "Mangement Certificate: [#{config.mgmt_certificate}]"
22
+ env[:ui].warn "Mangement Endpoint: [#{config.mgmt_endpoint}]"
23
+ env[:ui].warn "Storage Account Name: [#{config.storage_acct_name}]"
24
+ env[:ui].warn "Storage Access Key: [#{config.storage_access_key}]"
25
+
26
+ Azure.configure do |c|
27
+ c.subscription_id = config.subscription_id
28
+ c.management_certificate = config.mgmt_certificate
29
+ c.management_endpoint = config.mgmt_endpoint
30
+ c.storage_account_name = config.storage_acct_name
31
+ c.storage_access_key = config.storage_access_key
32
+ end
33
+
34
+ env[:azure_vm_service] = Azure::VirtualMachineManagementService.new
35
+
36
+ @app.call(env)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ #---------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #---------------------------------------------------------------------------
5
+ module VagrantPlugins
6
+ module WinAzure
7
+ module Action
8
+ class Provision < Vagrant::Action::Builtin::Provision
9
+ # Override the core vagrant method and branch out for windows
10
+ def run_provisioner(env)
11
+ env[:ui].info "Provisioner: #{env[:provisioner].class.to_s}"
12
+
13
+ env[:machine].id =~ /@/
14
+ vm = env[:azure_vm_service].get_virtual_machine($`, $')
15
+ env[:ui].info "VM OS: #{vm.os_type.to_sym}"
16
+
17
+ if vm.os_type.to_sym == :Windows
18
+ # Raise an error if we're not on a Windows Host.
19
+ # Non-Windows OS will be supported once we move to WinRb/WinRm
20
+ env[:ui].info "Is Host OS Windows?: #{Vagrant::Util::Platform.windows?}"
21
+ raise 'Unsupported OS for Windows Provisioning' unless \
22
+ Vagrant::Util::Platform.windows?
23
+ env[:ui].info "Provisioning for Windows"
24
+
25
+ # TODO: Add Shell, Chef-solo and other provisioners
26
+ case env[:provisioner].class.to_s
27
+ when "VagrantPlugins::Puppet::Provisioner::Puppet"
28
+ VagrantPlugins::WinAzure::Provisioner::Puppet.new(
29
+ env
30
+ ).provision_for_windows
31
+ end
32
+ else
33
+ env[:ui].info "Provisioning using SSH"
34
+ env[:provisioner].provision
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,62 @@
1
+ #--------------------------------------------------------------------------
2
+ # Copyright (c) Microsoft Open Technologies, Inc.
3
+ # All Rights Reserved. Licensed under the Apache 2.0 License.
4
+ #--------------------------------------------------------------------------
5
+ require 'log4r'
6
+ require 'pathname'
7
+ require 'vagrant/util/subprocess'
8
+ require 'vagrant/util/platform'
9
+
10
+ module VagrantPlugins
11
+ module WinAzure
12
+ module Action
13
+ class Rdp
14
+ def initialize(app, env)
15
+ @app = app
16
+ @logger = Log4r::Logger.new('vagrant_azure::action::rdp')
17
+ @rdp_file = 'machine.rdp'
18
+ end
19
+
20
+ def call(env)
21
+ if Vagrant::Util::Platform.windows?
22
+ generate_rdp_file env[:machine]
23
+ command = ['mstsc', @rdp_file]
24
+ Vagrant::Util::Subprocess.execute(*command)
25
+ elsif Vagrant::Util::Platform.darwin?
26
+ generate_rdp_file env[:machine]
27
+ command = ['open', @rdp_file]
28
+ result = Vagrant::Util::Subprocess.execute(*command)
29
+
30
+ if result.exit_code == 1
31
+ raise result.stderr
32
+ end
33
+ else
34
+ # TODO: Add support for RDP on *Nix systems
35
+ raise 'Unsupported operating system for RDP operation.'
36
+ end
37
+
38
+ @app.call(env)
39
+ end
40
+
41
+ def generate_rdp_file(machine)
42
+ File.delete(@rdp_file) if File.exists?(@rdp_file)
43
+
44
+ info = machine.provider.rdp_info
45
+
46
+ rdp_options = {
47
+ 'drivestoredirect:s' => '*',
48
+ 'username:s' => machine.provider_config.vm_user,
49
+ 'prompt for credentials:i' => '1',
50
+ 'full address:s' => "#{info[:host]}:#{info[:port]}"
51
+ }
52
+
53
+ file = File.open(@rdp_file, 'w')
54
+ rdp_options.each do |key, value|
55
+ file.puts "#{key}:#{value}"
56
+ end
57
+ file.close
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end