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
@@ -0,0 +1,43 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module WinAzure
|
3
|
+
module Command
|
4
|
+
class PowerShell < Vagrant.plugin('2', :command)
|
5
|
+
def self.synopsis
|
6
|
+
'execute PowerShell command or script on remote machine'
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
opts = OptionParser.new do |o|
|
13
|
+
o.banner = 'Usage: vagrant powershell [machine] -[c|s] [command|script file]'
|
14
|
+
o.separator ''
|
15
|
+
o.separator 'Options:'
|
16
|
+
o.separator ''
|
17
|
+
|
18
|
+
o.on('-c', '--command COMMAND', 'Execute a PowerShell command directly') do |c|
|
19
|
+
options[:command] = c
|
20
|
+
end
|
21
|
+
|
22
|
+
o.on('-s', '--script SCRIPT_FILE', 'Execute a PowerShell script directly') do |s|
|
23
|
+
raise Vagrant::Errors::CLIInvalidOptions, :help => "File #{s} can't be found. Does it exist?" unless File.exists?(s)
|
24
|
+
options[:command] = File.read(s)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
argv = parse_options(opts)
|
29
|
+
if options.empty?
|
30
|
+
raise Vagrant::Errors::CLIInvalidOptions, :help => opts.help.chomp
|
31
|
+
end
|
32
|
+
|
33
|
+
with_target_vms(argv, single_target: true) do |vm|
|
34
|
+
@logger.debug("Executing single command on remote machine: #{options[:command]}")
|
35
|
+
|
36
|
+
vm.action(:powershell_run, powershell_command: options[:command])
|
37
|
+
end
|
38
|
+
0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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
|
+
module VagrantPlugins
|
7
|
+
module WinAzure
|
8
|
+
module Command
|
9
|
+
class RDP < Vagrant.plugin('2', :command)
|
10
|
+
def self.synopsis
|
11
|
+
'opens an RDP session for a vagrant machine'
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
with_target_vms do |vm|
|
16
|
+
vm.action(:rdp)
|
17
|
+
end
|
18
|
+
|
19
|
+
0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/vagrant-azure/config.rb
CHANGED
@@ -1,147 +1,158 @@
|
|
1
|
-
#--------------------------------------------------------------------------
|
2
|
-
# Copyright (c) Microsoft Open Technologies, Inc.
|
3
|
-
# All Rights Reserved.
|
4
|
-
|
5
|
-
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attr_accessor :
|
13
|
-
attr_accessor :
|
14
|
-
attr_accessor :
|
15
|
-
attr_accessor :
|
16
|
-
|
17
|
-
|
18
|
-
attr_accessor :
|
19
|
-
attr_accessor :
|
20
|
-
attr_accessor :
|
21
|
-
attr_accessor :
|
22
|
-
attr_accessor :
|
23
|
-
|
24
|
-
|
25
|
-
attr_accessor :
|
26
|
-
attr_accessor :
|
27
|
-
attr_accessor :
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
attr_accessor :
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
attr_accessor :
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
if @
|
102
|
-
|
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
|
-
errors
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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 'vagrant'
|
7
|
+
require 'azure'
|
8
|
+
|
9
|
+
module VagrantPlugins
|
10
|
+
module WinAzure
|
11
|
+
class Config < Vagrant.plugin('2', :config)
|
12
|
+
attr_accessor :mgmt_certificate
|
13
|
+
attr_accessor :mgmt_endpoint
|
14
|
+
attr_accessor :subscription_id
|
15
|
+
attr_accessor :storage_acct_name
|
16
|
+
attr_accessor :storage_access_key
|
17
|
+
|
18
|
+
attr_accessor :vm_name
|
19
|
+
attr_accessor :vm_user
|
20
|
+
attr_accessor :vm_password
|
21
|
+
attr_accessor :vm_image
|
22
|
+
attr_accessor :vm_location
|
23
|
+
attr_accessor :vm_affinity_group
|
24
|
+
|
25
|
+
attr_accessor :cloud_service_name
|
26
|
+
attr_accessor :deployment_name
|
27
|
+
attr_accessor :tcp_endpoints
|
28
|
+
|
29
|
+
# ssh_private_key and ssh_certificate_file is overly specific and probably should be deprecated in favor of
|
30
|
+
# private_key_file and certificate_file as they are in Azure ruby sdk.
|
31
|
+
# This is here to not break compatibility with previous versions.
|
32
|
+
attr_accessor :private_key_file
|
33
|
+
alias :ssh_private_key_file :private_key_file
|
34
|
+
alias :ssh_private_key_file= :private_key_file=
|
35
|
+
|
36
|
+
attr_accessor :certificate_file
|
37
|
+
alias :ssh_certificate_file :certificate_file
|
38
|
+
alias :ssh_certificate_file= :certificate_file=
|
39
|
+
|
40
|
+
attr_accessor :ssh_port
|
41
|
+
attr_accessor :vm_size
|
42
|
+
attr_accessor :winrm_transport
|
43
|
+
attr_accessor :winrm_http_port
|
44
|
+
attr_accessor :winrm_https_port
|
45
|
+
attr_accessor :availability_set_name
|
46
|
+
|
47
|
+
attr_accessor :state_read_timeout
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
@storage_acct_name = UNSET_VALUE
|
51
|
+
@storage_access_key = UNSET_VALUE
|
52
|
+
@mgmt_certificate = UNSET_VALUE
|
53
|
+
@mgmt_endpoint = UNSET_VALUE
|
54
|
+
@subscription_id = UNSET_VALUE
|
55
|
+
|
56
|
+
@vm_name = UNSET_VALUE
|
57
|
+
@vm_user = UNSET_VALUE
|
58
|
+
@vm_password = UNSET_VALUE
|
59
|
+
@vm_image = UNSET_VALUE
|
60
|
+
@vm_location = UNSET_VALUE
|
61
|
+
@vm_affinity_group = UNSET_VALUE
|
62
|
+
|
63
|
+
@cloud_service_name = UNSET_VALUE
|
64
|
+
@deployment_name = UNSET_VALUE
|
65
|
+
@tcp_endpoints = UNSET_VALUE
|
66
|
+
@private_key_file = UNSET_VALUE
|
67
|
+
@certificate_file = UNSET_VALUE
|
68
|
+
@ssh_port = UNSET_VALUE
|
69
|
+
@vm_size = UNSET_VALUE
|
70
|
+
@winrm_transport = UNSET_VALUE
|
71
|
+
@winrm_http_port = UNSET_VALUE
|
72
|
+
@winrm_https_port = UNSET_VALUE
|
73
|
+
@availability_set_name = UNSET_VALUE
|
74
|
+
@state_read_timeout = UNSET_VALUE
|
75
|
+
end
|
76
|
+
|
77
|
+
def finalize!
|
78
|
+
@storage_acct_name = ENV["AZURE_STORAGE_ACCOUNT"] if \
|
79
|
+
@storage_acct_name == UNSET_VALUE
|
80
|
+
@storage_access_key = ENV["AZURE_STORAGE_ACCESS_KEY"] if \
|
81
|
+
@storage_access_key == UNSET_VALUE
|
82
|
+
@mgmt_certificate = ENV["AZURE_MANAGEMENT_CERTIFICATE"] if \
|
83
|
+
@mgmt_certificate == UNSET_VALUE
|
84
|
+
@mgmt_endpoint = ENV["AZURE_MANAGEMENT_ENDPOINT"] if \
|
85
|
+
@mgmt_endpoint == UNSET_VALUE
|
86
|
+
@subscription_id = ENV["AZURE_SUBSCRIPTION_ID"] if \
|
87
|
+
@subscription_id == UNSET_VALUE
|
88
|
+
|
89
|
+
@vm_name = nil if @vm_name == UNSET_VALUE
|
90
|
+
@vm_user = 'vagrant' if @vm_user == UNSET_VALUE
|
91
|
+
@vm_password = nil if @vm_password == UNSET_VALUE
|
92
|
+
@vm_image = nil if @vm_image == UNSET_VALUE
|
93
|
+
@vm_location = nil if @vm_location == UNSET_VALUE
|
94
|
+
@vm_affinity_group = nil if @vm_affinity_group == UNSET_VALUE
|
95
|
+
|
96
|
+
@cloud_service_name = nil if @cloud_service_name == UNSET_VALUE
|
97
|
+
@deployment_name = nil if @deployment_name == UNSET_VALUE
|
98
|
+
@tcp_endpoints = nil if @tcp_endpoints == UNSET_VALUE
|
99
|
+
@private_key_file = nil if @private_key_file == UNSET_VALUE
|
100
|
+
@certificate_file = nil if @certificate_file == UNSET_VALUE
|
101
|
+
@ssh_port = nil if @ssh_port == UNSET_VALUE
|
102
|
+
@vm_size = nil if @vm_size == UNSET_VALUE
|
103
|
+
@winrm_transport = nil if @winrm_transport == UNSET_VALUE
|
104
|
+
@winrm_http_port = nil if @winrm_http_port == UNSET_VALUE
|
105
|
+
@winrm_https_port = nil if @winrm_https_port == UNSET_VALUE
|
106
|
+
@availability_set_name = nil if @availability_set_name == UNSET_VALUE
|
107
|
+
|
108
|
+
@state_read_timeout = nil if @state_read_timeout == UNSET_VALUE
|
109
|
+
|
110
|
+
# This done due to a bug in Ruby SDK - it doesn't generate a storage
|
111
|
+
# account name if add_role = true
|
112
|
+
if @storage_acct_name.nil? || @storage_acct_name.empty?
|
113
|
+
@storage_acct_name = Azure::Core::Utility.random_string(
|
114
|
+
"#{@vm_name}storage"
|
115
|
+
).gsub(/[^0-9a-z ]/i, '').downcase[0..23]
|
116
|
+
end
|
117
|
+
|
118
|
+
if @cloud_service_name.nil? || @cloud_service_name.empty?
|
119
|
+
@cloud_service_name = Azure::Core::Utility.random_string(
|
120
|
+
"#{@vm_name}-service-"
|
121
|
+
)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def merge(other)
|
126
|
+
super.tap do |result|
|
127
|
+
result.mgmt_certificate = other.mgmt_certificate || \
|
128
|
+
self.mgmt_certificate
|
129
|
+
result.mgmt_endpoint = other.mgmt_endpoint || \
|
130
|
+
self.mgmt_endpoint
|
131
|
+
result.subscription_id = other.subscription_id || \
|
132
|
+
self.subscription_id
|
133
|
+
result.storage_acct_name = other.storage_acct_name || \
|
134
|
+
self.storage_acct_name
|
135
|
+
result.storage_access_key = other.storage_access_key || \
|
136
|
+
self.storage_access_key
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def validate(machine)
|
141
|
+
errors = _detected_errors
|
142
|
+
|
143
|
+
# Azure connection properties related validation.
|
144
|
+
errors << "vagrant_azure.subscription_id.required" if \
|
145
|
+
@subscription_id.nil?
|
146
|
+
errors << "vagrant_azure.mgmt_certificate.required" if \
|
147
|
+
@mgmt_certificate.nil?
|
148
|
+
errors << "vagrant_azure.mgmt_endpoint.required" if \
|
149
|
+
@mgmt_endpoint.nil?
|
150
|
+
|
151
|
+
# Azure Virtual Machine related validation
|
152
|
+
errors << "vagrant_azure.vm_name.required" if @vm_name.nil?
|
153
|
+
|
154
|
+
{ "Windows Azure Provider" => errors }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/lib/vagrant-azure/driver.rb
CHANGED
@@ -1,84 +1,48 @@
|
|
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
|
-
@ssh_info
|
19
|
-
@ssh_info[:
|
20
|
-
@ssh_info
|
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
|
-
|
48
|
-
|
49
|
-
&block
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
def upload(from, to)
|
54
|
-
options = {
|
55
|
-
host_path: windows_path(from),
|
56
|
-
guest_path: windows_path(to)
|
57
|
-
}.merge(remote_credentials)
|
58
|
-
|
59
|
-
script_path = local_script_path('upload_file.ps1')
|
60
|
-
execute(script_path, options)
|
61
|
-
end
|
62
|
-
|
63
|
-
def check_winrm
|
64
|
-
script_path = local_script_path('check_winrm.ps1')
|
65
|
-
execute(script_path, remote_credentials)
|
66
|
-
end
|
67
|
-
|
68
|
-
protected
|
69
|
-
|
70
|
-
def local_script_path(path)
|
71
|
-
lib_path = Pathname.new(File.expand_path('../scripts', __FILE__))
|
72
|
-
windows_path(lib_path.join(path).to_s)
|
73
|
-
end
|
74
|
-
|
75
|
-
def windows_path(path)
|
76
|
-
if path
|
77
|
-
path = path.gsub('/', "\\")
|
78
|
-
path = "c:#{path}" if path =~ /^\\/
|
79
|
-
end
|
80
|
-
path
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
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 'json'
|
7
|
+
require "#{Vagrant::source_root}/plugins/providers/hyperv/driver"
|
8
|
+
|
9
|
+
module VagrantPlugins
|
10
|
+
module WinAzure
|
11
|
+
class Driver < VagrantPlugins::HyperV::Driver
|
12
|
+
def initialize(machine)
|
13
|
+
@id = machine.id
|
14
|
+
@machine = machine
|
15
|
+
end
|
16
|
+
|
17
|
+
def ssh_info
|
18
|
+
@ssh_info ||= @machine.provider.winrm_info
|
19
|
+
@ssh_info[:username] ||= @machine.config.ssh.username
|
20
|
+
@ssh_info[:password] ||= @machine.config.ssh.password
|
21
|
+
@ssh_info
|
22
|
+
end
|
23
|
+
|
24
|
+
def remote_credentials
|
25
|
+
@remote_credentials ||= {
|
26
|
+
guest_ip: ssh_info[:host],
|
27
|
+
guest_port: ssh_info[:port],
|
28
|
+
username: ssh_info[:username],
|
29
|
+
password: ssh_info[:password]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_remote_ps(command, &block)
|
34
|
+
@machine.communicate.execute(command) do |*args|
|
35
|
+
block.call(args) unless block.nil?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def upload(from, to)
|
40
|
+
@machine.communicate.upload(from, to)
|
41
|
+
end
|
42
|
+
|
43
|
+
def check_winrm
|
44
|
+
@machine.communicate.ready?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|