vagrant-azure 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -15
- data/CHANGELOG.md +24 -24
- data/Gemfile +20 -15
- data/LICENSE +4 -4
- data/README.md +189 -125
- data/Rakefile +15 -14
- data/lib/vagrant-azure.rb +31 -33
- data/lib/vagrant-azure/action.rb +267 -243
- data/lib/vagrant-azure/action/connect_azure.rb +49 -46
- data/lib/vagrant-azure/action/os_type.rb +34 -0
- data/lib/vagrant-azure/action/powershell_run.rb +28 -0
- data/lib/vagrant-azure/action/provision.rb +42 -49
- data/lib/vagrant-azure/action/rdp.rb +63 -62
- data/lib/vagrant-azure/action/read_ssh_info.rb +54 -51
- data/lib/vagrant-azure/action/read_state.rb +47 -46
- data/lib/vagrant-azure/action/read_winrm_info.rb +57 -0
- data/lib/vagrant-azure/action/restart_vm.rb +28 -27
- data/lib/vagrant-azure/action/run_instance.rb +123 -115
- data/lib/vagrant-azure/action/start_instance.rb +35 -35
- data/lib/vagrant-azure/action/stop_instance.rb +42 -38
- data/lib/vagrant-azure/action/sync_folders.rb +64 -63
- data/lib/vagrant-azure/action/terminate_instance.rb +34 -34
- data/lib/vagrant-azure/action/vagrant_azure_service.rb +44 -43
- data/lib/vagrant-azure/action/wait_for_communicate.rb +39 -38
- data/lib/vagrant-azure/action/wait_for_state.rb +50 -49
- data/lib/vagrant-azure/capabilities/winrm.rb +12 -0
- data/lib/vagrant-azure/command/powershell.rb +43 -0
- data/lib/vagrant-azure/command/rdp.rb +24 -0
- data/lib/vagrant-azure/config.rb +158 -147
- data/lib/vagrant-azure/driver.rb +48 -84
- data/lib/vagrant-azure/errors.rb +28 -27
- data/lib/vagrant-azure/monkey_patch/azure.rb +46 -0
- data/lib/vagrant-azure/monkey_patch/winrm.rb +77 -0
- data/lib/vagrant-azure/plugin.rb +102 -91
- data/lib/vagrant-azure/provider.rb +74 -70
- data/lib/vagrant-azure/provisioner/chef-solo.rb +178 -177
- data/lib/vagrant-azure/provisioner/puppet.rb +116 -115
- data/lib/vagrant-azure/version.rb +11 -10
- data/locales/en.yml +37 -37
- data/templates/provisioners/chef-solo/solo.erb +51 -51
- data/vagrant-azure.gemspec +59 -58
- metadata +48 -38
- data/lib/vagrant-azure/command/rdp/command.rb +0 -21
- data/lib/vagrant-azure/communication/powershell.rb +0 -41
- data/lib/vagrant-azure/monkey_patch/machine.rb +0 -22
- data/lib/vagrant-azure/provisioner/shell.rb +0 -83
- data/lib/vagrant-azure/scripts/check_winrm.ps1 +0 -47
- data/lib/vagrant-azure/scripts/export_vm.ps1 +0 -31
- data/lib/vagrant-azure/scripts/file_sync.ps1 +0 -145
- data/lib/vagrant-azure/scripts/host_info.ps1 +0 -25
- data/lib/vagrant-azure/scripts/hyperv_manager.ps1 +0 -36
- data/lib/vagrant-azure/scripts/run_in_remote.ps1 +0 -32
- data/lib/vagrant-azure/scripts/upload_file.ps1 +0 -95
- data/lib/vagrant-azure/scripts/utils/create_session.ps1 +0 -34
- data/lib/vagrant-azure/scripts/utils/write_messages.ps1 +0 -18
@@ -1,177 +1,178 @@
|
|
1
|
-
#-------------------------------------------------------------------------
|
2
|
-
# Copyright (c) Microsoft Open Technologies, Inc.
|
3
|
-
# All Rights Reserved.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
require "
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
copy_folder_to_guest(provisioner.
|
24
|
-
copy_folder_to_guest(provisioner.
|
25
|
-
copy_folder_to_guest(provisioner.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
json
|
43
|
-
json =
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
|
48
|
-
temp.
|
49
|
-
temp.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
temp.
|
102
|
-
temp.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
"-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
@
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
#
|
161
|
-
|
162
|
-
|
163
|
-
return
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
end
|
1
|
+
#-------------------------------------------------------------------------
|
2
|
+
# Copyright (c) Microsoft Open Technologies, Inc.
|
3
|
+
# All Rights Reserved. Licensed under the Apache License, Version 2.0.
|
4
|
+
# See License.txt in the project root for license information.
|
5
|
+
#--------------------------------------------------------------------------
|
6
|
+
|
7
|
+
require "fileutils"
|
8
|
+
require "tempfile"
|
9
|
+
|
10
|
+
module VagrantPlugins
|
11
|
+
module WinAzure
|
12
|
+
module Provisioner
|
13
|
+
class ChefSolo
|
14
|
+
attr_reader :provisioner
|
15
|
+
|
16
|
+
def initialize(env)
|
17
|
+
@env = env
|
18
|
+
@provisioner = env[:provisioner]
|
19
|
+
end
|
20
|
+
|
21
|
+
def provision_for_windows
|
22
|
+
# Copy the chef cookbooks roles data bags and environment folders to Guest
|
23
|
+
copy_folder_to_guest(provisioner.cookbook_folders)
|
24
|
+
copy_folder_to_guest(provisioner.role_folders)
|
25
|
+
copy_folder_to_guest(provisioner.data_bags_folders)
|
26
|
+
copy_folder_to_guest(provisioner.environments_folders)
|
27
|
+
|
28
|
+
# Upload Encrypted data bag
|
29
|
+
upload_encrypted_data_bag_secret if config.encrypted_data_bag_secret_key_path
|
30
|
+
setup_json
|
31
|
+
setup_solo_config
|
32
|
+
run_chef_solo
|
33
|
+
|
34
|
+
# TODO
|
35
|
+
# delete_encrypted_data_bag_secret
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_json
|
39
|
+
@env[:machine].env.ui.info I18n.t("vagrant.provisioners.chef.json")
|
40
|
+
|
41
|
+
# Get the JSON that we're going to expose to Chef
|
42
|
+
json = config.json
|
43
|
+
json[:run_list] = config.run_list if !config.run_list.empty?
|
44
|
+
json = JSON.pretty_generate(json)
|
45
|
+
|
46
|
+
# Create a temporary file to store the data so we
|
47
|
+
# can upload it
|
48
|
+
temp = Tempfile.new("vagrant")
|
49
|
+
temp.write(json)
|
50
|
+
temp.close
|
51
|
+
|
52
|
+
remote_file = File.join(config.provisioning_path, "dna.json")
|
53
|
+
@env[:machine].provider.driver.upload(temp.path, remote_file)
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_solo_config
|
57
|
+
cookbooks_path = guest_paths(provisioner.cookbook_folders)
|
58
|
+
roles_path = guest_paths(provisioner.role_folders)
|
59
|
+
data_bags_path = guest_paths(provisioner.data_bags_folders).first
|
60
|
+
environments_path = guest_paths(provisioner.environments_folders).first
|
61
|
+
source_path = "#{VagrantPlugins::WinAzure.source_root}"
|
62
|
+
template_path = source_path + "/templates/provisioners/chef-solo/solo"
|
63
|
+
setup_config(template_path, "solo.rb", {
|
64
|
+
:cookbooks_path => cookbooks_path,
|
65
|
+
:recipe_url => config.recipe_url,
|
66
|
+
:roles_path => roles_path,
|
67
|
+
:data_bags_path => data_bags_path,
|
68
|
+
:environments_path => environments_path
|
69
|
+
})
|
70
|
+
end
|
71
|
+
|
72
|
+
def setup_config(template, filename, template_vars)
|
73
|
+
# If we have custom configuration, upload it
|
74
|
+
remote_custom_config_path = nil
|
75
|
+
if config.custom_config_path
|
76
|
+
expanded = File.expand_path(
|
77
|
+
config.custom_config_path, @machine.env.root_path)
|
78
|
+
remote_custom_config_path = File.join(
|
79
|
+
config.provisioning_path, "custom-config.rb")
|
80
|
+
|
81
|
+
@env[:machine].provider.driver.upload(expanded, remote_custom_config_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
config_file = Vagrant::Util::TemplateRenderer.render(template, {
|
85
|
+
:custom_configuration => remote_custom_config_path,
|
86
|
+
:file_cache_path => config.file_cache_path,
|
87
|
+
:file_backup_path => config.file_backup_path,
|
88
|
+
:log_level => config.log_level.to_sym,
|
89
|
+
:verbose_logging => config.verbose_logging,
|
90
|
+
:http_proxy => config.http_proxy,
|
91
|
+
:http_proxy_user => config.http_proxy_user,
|
92
|
+
:http_proxy_pass => config.http_proxy_pass,
|
93
|
+
:https_proxy => config.https_proxy,
|
94
|
+
:https_proxy_user => config.https_proxy_user,
|
95
|
+
:https_proxy_pass => config.https_proxy_pass,
|
96
|
+
:no_proxy => config.no_proxy,
|
97
|
+
:formatter => config.formatter
|
98
|
+
}.merge(template_vars))
|
99
|
+
|
100
|
+
# Create a temporary file to store the data so we can upload it
|
101
|
+
temp = Tempfile.new("vagrant")
|
102
|
+
temp.write(config_file)
|
103
|
+
temp.close
|
104
|
+
|
105
|
+
remote_file = File.join(config.provisioning_path, filename)
|
106
|
+
@env[:machine].provider.driver.upload(temp.path, remote_file)
|
107
|
+
end
|
108
|
+
|
109
|
+
def run_chef_solo
|
110
|
+
if config.run_list && config.run_list.empty?
|
111
|
+
@env[:machine].ui.warn(I18n.t("vagrant.chef_run_list_empty"))
|
112
|
+
end
|
113
|
+
|
114
|
+
options = [
|
115
|
+
"-c #{config.provisioning_path}/solo.rb",
|
116
|
+
"-j #{config.provisioning_path}/dna.json"
|
117
|
+
]
|
118
|
+
|
119
|
+
command_env = config.binary_env ? "#{config.binary_env} " : ""
|
120
|
+
command_args = config.arguments ? " #{config.arguments}" : ""
|
121
|
+
command = "#{command_env}#{chef_binary_path("chef-solo")} " +
|
122
|
+
"#{options.join(" ")} #{command_args}"
|
123
|
+
config.attempts.times do |attempt|
|
124
|
+
if attempt == 0
|
125
|
+
@env[:machine].env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
|
126
|
+
else
|
127
|
+
@env[:machine].env.ui.info I18n.t("vagrant.provisioners.chef.running_solo_again")
|
128
|
+
end
|
129
|
+
|
130
|
+
command
|
131
|
+
|
132
|
+
@env[:machine].provider.driver.run_remote_ps(command) do |type, data|
|
133
|
+
# Output the data with the proper color based on the stream.
|
134
|
+
if (type == :stdout || type == :stderr)
|
135
|
+
@env[:ui].detail data
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
def upload_encrypted_data_bag_secret
|
143
|
+
@machine.env.ui.info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
|
144
|
+
@env[:machine].provider.driver.upload(encrypted_data_bag_secret_key_path,
|
145
|
+
config.encrypted_data_bag_secret)
|
146
|
+
end
|
147
|
+
|
148
|
+
def encrypted_data_bag_secret_key_path
|
149
|
+
File.expand_path(config.encrypted_data_bag_secret_key_path, @env[:machine].env.root_path)
|
150
|
+
end
|
151
|
+
|
152
|
+
def config
|
153
|
+
provisioner.config
|
154
|
+
end
|
155
|
+
|
156
|
+
def guest_paths(folders)
|
157
|
+
folders.map { |parts| parts[2] }
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns the path to the Chef binary, taking into account the
|
161
|
+
# `binary_path` configuration option.
|
162
|
+
def chef_binary_path(binary)
|
163
|
+
return binary if !config.binary_path
|
164
|
+
return File.join(config.binary_path, binary)
|
165
|
+
end
|
166
|
+
|
167
|
+
def copy_folder_to_guest(folders)
|
168
|
+
folders.each do |type, local_path, remote_path|
|
169
|
+
if type == :host
|
170
|
+
@env[:machine].provider.driver.upload(local_path, remote_path)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -1,115 +1,116 @@
|
|
1
|
-
#---------------------------------------------------------------------------
|
2
|
-
# Copyright (c) Microsoft Open Technologies, Inc.
|
3
|
-
# All Rights Reserved.
|
4
|
-
|
5
|
-
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
module_paths.
|
48
|
-
|
49
|
-
path =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
options << "--
|
74
|
-
options <<
|
75
|
-
options
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
@env[:
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
1
|
+
#---------------------------------------------------------------------------
|
2
|
+
# Copyright (c) Microsoft Open Technologies, Inc.
|
3
|
+
# All Rights Reserved. Licensed under the Apache License, Version 2.0.
|
4
|
+
# See License.txt in the project root for license information.
|
5
|
+
#---------------------------------------------------------------------------
|
6
|
+
require 'fileutils'
|
7
|
+
require 'tempfile'
|
8
|
+
|
9
|
+
module VagrantPlugins
|
10
|
+
module WinAzure
|
11
|
+
module Provisioner
|
12
|
+
class Puppet
|
13
|
+
attr_reader :provisioner
|
14
|
+
|
15
|
+
def initialize(env)
|
16
|
+
@env = env
|
17
|
+
@provisioner = env[:provisioner]
|
18
|
+
end
|
19
|
+
|
20
|
+
def provision_for_windows
|
21
|
+
options = [config.options].flatten
|
22
|
+
@module_paths = provisioner.instance_variable_get('@module_paths')
|
23
|
+
@hiera_config_path = provisioner.instance_variable_get(
|
24
|
+
'@hiera_config_path'
|
25
|
+
)
|
26
|
+
@manifest_file = provisioner.instance_variable_get('@manifest_file')
|
27
|
+
|
28
|
+
# Copy the manifests directory to the guest
|
29
|
+
if config.manifests_path[0].to_sym == :host
|
30
|
+
@env[:machine].provider.driver.upload(
|
31
|
+
File.expand_path(
|
32
|
+
config.manifests_path[1], @env[:machine].env.root_path
|
33
|
+
),
|
34
|
+
provisioner.manifests_guest_path
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Copy the module paths to the guest
|
39
|
+
@module_paths.each do |from, to|
|
40
|
+
@env[:machine].provider.driver.upload(from.to_s, to)
|
41
|
+
end
|
42
|
+
|
43
|
+
module_paths = @module_paths.map { |_, to| to }
|
44
|
+
unless module_paths.empty?
|
45
|
+
win_paths = []
|
46
|
+
# Prepend the default module path
|
47
|
+
module_paths.unshift('/ProgramData/PuppetLabs/puppet/etc/modules')
|
48
|
+
module_paths.each do |path|
|
49
|
+
path = path.gsub('/', '\\')
|
50
|
+
path = "C:#{path}" if path =~/^\\/
|
51
|
+
win_paths << path
|
52
|
+
end
|
53
|
+
|
54
|
+
# Add the command line switch to add the module path
|
55
|
+
options << "--modulepath \"#{win_paths.join(';')}\""
|
56
|
+
end
|
57
|
+
|
58
|
+
if @hiera_config_path
|
59
|
+
options << "--hiera_config=#{@hiera_config_path}"
|
60
|
+
|
61
|
+
# Upload Hiera configuration if we have it
|
62
|
+
local_hiera_path = File.expand_path(
|
63
|
+
config.hiera_config_path,
|
64
|
+
@env[:machine].env.root_path
|
65
|
+
)
|
66
|
+
|
67
|
+
@env[:machine].provider.driver.upload(
|
68
|
+
local_hiera_path,
|
69
|
+
@hiera_config_path
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
options << "--manifestdir #{provisioner.manifests_guest_path}"
|
74
|
+
options << "--detailed-exitcodes"
|
75
|
+
options << @manifest_file
|
76
|
+
options = options.join(' ')
|
77
|
+
|
78
|
+
# Build up the custome facts if we have any
|
79
|
+
facter = ''
|
80
|
+
unless config.facter.empty?
|
81
|
+
facts = []
|
82
|
+
config.facter.each do |key, value|
|
83
|
+
facts << "FACTER_#{key}='#{value}'"
|
84
|
+
end
|
85
|
+
|
86
|
+
facter = "#{facts.join(' ')}"
|
87
|
+
end
|
88
|
+
|
89
|
+
command = "#{facter}puppet apply #{options}"
|
90
|
+
|
91
|
+
if config.working_directory
|
92
|
+
command = "cd #{config.working_directory} && #{command}"
|
93
|
+
end
|
94
|
+
|
95
|
+
@env[:ui].info I18n.t(
|
96
|
+
'vagrant.provisioners.puppet.running_puppet',
|
97
|
+
manifest: config.manifest_file
|
98
|
+
)
|
99
|
+
@env[:ui].info 'Executing puppet script in Windows Azure VM'
|
100
|
+
@env[:machine].provider.driver.run_remote_ps(command) do |type, data|
|
101
|
+
# Output the data with the proper color based on the stream.
|
102
|
+
if (type == :stdout || type == :stderr)
|
103
|
+
@env[:ui].detail data
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
protected
|
109
|
+
|
110
|
+
def config
|
111
|
+
provisioner.config
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|