vagrant-azure 1.3.0 → 2.0.0.pre1

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -6
  5. data/LICENSE +21 -4
  6. data/README.md +36 -178
  7. data/Rakefile +3 -5
  8. data/example_box/Vagrantfile +7 -8
  9. data/lib/vagrant-azure/action/connect_azure.rb +9 -30
  10. data/lib/vagrant-azure/action/is_created.rb +19 -0
  11. data/lib/vagrant-azure/action/is_stopped.rb +19 -0
  12. data/lib/vagrant-azure/action/message_already_created.rb +19 -0
  13. data/lib/vagrant-azure/action/message_not_created.rb +19 -0
  14. data/lib/vagrant-azure/action/message_will_not_destroy.rb +19 -0
  15. data/lib/vagrant-azure/action/read_ssh_info.rb +13 -33
  16. data/lib/vagrant-azure/action/read_state.rb +28 -26
  17. data/lib/vagrant-azure/action/restart_vm.rb +11 -11
  18. data/lib/vagrant-azure/action/run_instance.rb +164 -80
  19. data/lib/vagrant-azure/action/start_instance.rb +34 -15
  20. data/lib/vagrant-azure/action/stop_instance.rb +36 -21
  21. data/lib/vagrant-azure/action/terminate_instance.rb +18 -14
  22. data/lib/vagrant-azure/action/wait_for_state.rb +17 -23
  23. data/lib/vagrant-azure/action.rb +49 -124
  24. data/lib/vagrant-azure/config.rb +107 -111
  25. data/lib/vagrant-azure/errors.rb +9 -11
  26. data/lib/vagrant-azure/plugin.rb +8 -32
  27. data/lib/vagrant-azure/provider.rb +7 -29
  28. data/lib/vagrant-azure/services/azure_resource_manager.rb +80 -0
  29. data/lib/vagrant-azure/util/machine_id_helper.rb +20 -0
  30. data/lib/vagrant-azure/util/timer.rb +15 -0
  31. data/lib/vagrant-azure/util/vm_await.rb +36 -0
  32. data/lib/vagrant-azure/util/vm_status_translator.rb +59 -0
  33. data/lib/vagrant-azure/version.rb +5 -7
  34. data/lib/vagrant-azure.rb +4 -9
  35. data/locales/en.yml +74 -3
  36. data/spec/spec_helper.rb +40 -0
  37. data/spec/vagrant-azure/config_spec.rb +18 -0
  38. data/spec/vagrant-azure/services/azure_resource_manager_spec.rb +19 -0
  39. data/templates/arm/deployment.json.erb +264 -0
  40. data/vagrant-azure.gemspec +19 -14
  41. metadata +96 -51
  42. data/lib/vagrant-azure/action/os_type.rb +0 -34
  43. data/lib/vagrant-azure/action/powershell_run.rb +0 -28
  44. data/lib/vagrant-azure/action/rdp.rb +0 -63
  45. data/lib/vagrant-azure/action/read_winrm_info.rb +0 -57
  46. data/lib/vagrant-azure/action/sync_folders.rb +0 -64
  47. data/lib/vagrant-azure/action/vagrant_azure_service.rb +0 -44
  48. data/lib/vagrant-azure/capabilities/winrm.rb +0 -12
  49. data/lib/vagrant-azure/command/powershell.rb +0 -43
  50. data/lib/vagrant-azure/command/rdp.rb +0 -24
  51. data/lib/vagrant-azure/driver.rb +0 -48
  52. data/lib/vagrant-azure/monkey_patch/winrm.rb +0 -12
@@ -1,63 +0,0 @@
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 'log4r'
7
- require 'pathname'
8
- require 'vagrant/util/subprocess'
9
- require 'vagrant/util/platform'
10
-
11
- module VagrantPlugins
12
- module WinAzure
13
- module Action
14
- class Rdp
15
- def initialize(app, env)
16
- @app = app
17
- @logger = Log4r::Logger.new('vagrant_azure::action::rdp')
18
- @rdp_file = 'machine.rdp'
19
- end
20
-
21
- def call(env)
22
- if Vagrant::Util::Platform.windows?
23
- generate_rdp_file env[:machine]
24
- command = ['mstsc', @rdp_file]
25
- Vagrant::Util::Subprocess.execute(*command)
26
- elsif Vagrant::Util::Platform.darwin?
27
- generate_rdp_file env[:machine]
28
- command = ['open', @rdp_file]
29
- result = Vagrant::Util::Subprocess.execute(*command)
30
-
31
- if result.exit_code == 1
32
- raise result.stderr
33
- end
34
- else
35
- # TODO: Add support for RDP on *Nix systems
36
- raise 'Unsupported operating system for RDP operation.'
37
- end
38
-
39
- @app.call(env)
40
- end
41
-
42
- def generate_rdp_file(machine)
43
- File.delete(@rdp_file) if File.exists?(@rdp_file)
44
-
45
- info = machine.provider.rdp_info
46
-
47
- rdp_options = {
48
- 'drivestoredirect:s' => '*',
49
- 'username:s' => machine.provider_config.vm_user,
50
- 'prompt for credentials:i' => '1',
51
- 'full address:s' => "#{info[:host]}:#{info[:port]}"
52
- }
53
-
54
- file = File.open(@rdp_file, 'w')
55
- rdp_options.each do |key, value|
56
- file.puts "#{key}:#{value}"
57
- end
58
- file.close
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,57 +0,0 @@
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 'log4r'
7
-
8
- module VagrantPlugins
9
- module WinAzure
10
- module Action
11
- class ReadWinrmInfo
12
- def initialize(app, env)
13
- @app = app
14
- @logger = Log4r::Logger.new('vagrant_azure::action::read_winrm_info')
15
- end
16
-
17
- def call(env)
18
- if env[:machine].config.vm.guest == :windows
19
- env[:ui].detail 'Looking for WinRM'
20
- env[:machine_winrm_info] = read_winrm_info(env[:azure_vm_service], env[:machine])
21
- env[:ui].detail "Found public port #{env[:machine_winrm_info][:port]}"
22
- end
23
-
24
- @app.call(env)
25
- end
26
-
27
- def read_winrm_info(azure, machine)
28
- return nil if machine.id.nil?
29
- machine.id =~ /@/
30
- vm = azure.get_virtual_machine($`, $')
31
-
32
- if vm.nil? || !vm.instance_of?(Azure::VirtualMachineManagement::VirtualMachine)
33
- # Machine cannot be found
34
- @logger.info 'Machine not found. Assuming it was destroyed'
35
- machine.id = nil
36
- return nil
37
- end
38
-
39
- types = %w(PowerShell WinRm-Http)
40
-
41
- endpoint = vm.tcp_endpoints.reject { |i| !types.include?(i[:name]) }.sort{ |i| i[:name] }.first
42
- if endpoint
43
- machine.config.winrm.host = "#{vm.cloud_service_name}.cloudapp.net"
44
- machine.config.winrm.port = endpoint[:public_port]
45
-
46
- if endpoint[:name] == types[0] # if it's PowerShell, then it's over https so use ssl (cert is self signed)
47
- machine.config.winrm.ssl_peer_verification = false
48
- machine.config.winrm.transport = :ssl
49
- end
50
- return {:host => "#{vm.cloud_service_name}.cloudapp.net", :port => endpoint[:public_port]}
51
- end
52
- nil
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,64 +0,0 @@
1
- # Copyright (c) 2014 Mitchell Hashimoto
2
- # Under The MIT License (MIT)
3
- #---------------------------------------------------------------------------
4
- # Copyright (c) Microsoft Open Technologies, Inc.
5
- # All Rights Reserved. Licensed under the Apache License, Version 2.0.
6
- # See License.txt in the project root for license information.
7
- #--------------------------------------------------------------------------
8
- require "log4r"
9
- require "vagrant/util/subprocess"
10
- require "vagrant/util/scoped_hash_override"
11
- require "vagrant/util/which"
12
- require "#{Vagrant::source_root}/lib/vagrant/action/builtin/synced_folders"
13
-
14
- module VagrantPlugins
15
- module WinAzure
16
- module Action
17
- # This middleware uses `rsync` to sync the folders
18
- class SyncFolders < Vagrant::Action::Builtin::SyncedFolders
19
- include Vagrant::Util::ScopedHashOverride
20
-
21
- def initialize(app, env)
22
- @app = app
23
- @logger = Log4r::Logger.new("vagrant_azure::action::sync_folders")
24
- end
25
-
26
- def call(env)
27
- if env[:machine].config.vm.guest != :windows
28
- super
29
- else
30
- @app.call(env)
31
- env[:machine].config.vm.synced_folders.each do |id, data|
32
- data = scoped_hash_override(data, :azure)
33
-
34
- # Ignore disabled shared folders
35
- next if data[:disabled]
36
-
37
- hostpath = File.expand_path(data[:hostpath], env[:root_path])
38
- guestpath = data[:guestpath]
39
-
40
- env[:ui].info(I18n.t("vagrant_azure.copy_folder",
41
- :hostpath => hostpath,
42
- :guestpath => guestpath))
43
-
44
- # Create the host path if it doesn't exist and option flag is set
45
- if data[:create]
46
- begin
47
- FileUtils::mkdir_p(hostpath)
48
- rescue => err
49
- raise Errors::MkdirError,
50
- :hostpath => hostpath,
51
- :err => err
52
- end
53
- end
54
-
55
- env[:machine].communicate.upload(hostpath, guestpath)
56
-
57
- end
58
- end
59
- end
60
-
61
- end
62
- end
63
- end
64
- end
@@ -1,44 +0,0 @@
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
- # FIXME:
7
- # This is a stop gap arrangement until the azure ruby SDK fixes the exceptions
8
- # and gracefully fails.
9
-
10
- module VagrantPlugins
11
- module WinAzure
12
- module Action
13
- class VagrantAzureService
14
- attr_reader :azure
15
- def initialize(azure)
16
- @azure = azure
17
- end
18
-
19
- # At times due to network latency the SDK raises SocketError, this can
20
- # be rescued and re-try for three attempts.
21
- def get_virtual_machine(*args)
22
- vm = nil
23
- attempt = 0
24
- while true
25
- begin
26
- vm = azure.get_virtual_machine(*args)
27
- rescue SocketError
28
- attempt = attempt + 1
29
- sleep 5
30
- next if attempt < 3
31
- end
32
- break
33
- end
34
- vm
35
- end
36
-
37
- def method_missing(method, *args, &block)
38
- azure.send(method, *args, &block)
39
- end
40
-
41
- end
42
- end
43
- end
44
- end
@@ -1,12 +0,0 @@
1
- module VagrantPlugins
2
- module WinAzure
3
- module Cap
4
- class WinRM
5
- def self.winrm_info(machine)
6
- env = machine.action('read_winrm_info')
7
- env[:machine_winrm_info]
8
- end
9
- end
10
- end
11
- end
12
- end
@@ -1,43 +0,0 @@
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
@@ -1,24 +0,0 @@
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
@@ -1,48 +0,0 @@
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
@@ -1,12 +0,0 @@
1
- VagrantPlugins::CommunicatorWinRM::WinRMShell.class_eval do
2
- def endpoint_options
3
- {user: @username,
4
- pass: @password,
5
- host: @host,
6
- port: @port,
7
- basic_auth_only: false,
8
- no_ssl_peer_verification: !@config.ssl_peer_verification,
9
- disable_sspi: true
10
- }
11
- end
12
- end