vagrant-cosmic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/CHANGELOG.md +8 -0
  4. data/Docker/.dockerignore +2 -0
  5. data/Docker/Dockerfile +48 -0
  6. data/Docker/Dockerfile.chefdk_0_17 +49 -0
  7. data/Docker/Dockerfile.latest_dependencies +49 -0
  8. data/Docker/README.md +95 -0
  9. data/Docker/vac.ps1 +29 -0
  10. data/Docker/vac.sh +30 -0
  11. data/Gemfile +21 -0
  12. data/Gemfile.lock +187 -0
  13. data/LICENSE +8 -0
  14. data/README.md +409 -0
  15. data/Rakefile +106 -0
  16. data/build_rpm.sh +7 -0
  17. data/functional-tests/basic/Vagrantfile.basic_networking +34 -0
  18. data/functional-tests/basic/basic_spec.rb +15 -0
  19. data/functional-tests/networking/Vagrantfile.advanced_networking +106 -0
  20. data/functional-tests/networking/networking_spec.rb +14 -0
  21. data/functional-tests/rsync/Vagrantfile.advanced_networking +40 -0
  22. data/functional-tests/rsync/rsync_spec.rb +9 -0
  23. data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +64 -0
  24. data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +25 -0
  25. data/lib/vagrant-cosmic/action/connect_cosmic.rb +47 -0
  26. data/lib/vagrant-cosmic/action/is_created.rb +18 -0
  27. data/lib/vagrant-cosmic/action/is_stopped.rb +18 -0
  28. data/lib/vagrant-cosmic/action/message_already_created.rb +16 -0
  29. data/lib/vagrant-cosmic/action/message_not_created.rb +16 -0
  30. data/lib/vagrant-cosmic/action/message_will_not_destroy.rb +16 -0
  31. data/lib/vagrant-cosmic/action/read_rdp_info.rb +42 -0
  32. data/lib/vagrant-cosmic/action/read_ssh_info.rb +70 -0
  33. data/lib/vagrant-cosmic/action/read_state.rb +38 -0
  34. data/lib/vagrant-cosmic/action/read_transport_info.rb +59 -0
  35. data/lib/vagrant-cosmic/action/read_winrm_info.rb +69 -0
  36. data/lib/vagrant-cosmic/action/run_instance.rb +819 -0
  37. data/lib/vagrant-cosmic/action/start_instance.rb +81 -0
  38. data/lib/vagrant-cosmic/action/stop_instance.rb +28 -0
  39. data/lib/vagrant-cosmic/action/terminate_instance.rb +208 -0
  40. data/lib/vagrant-cosmic/action/timed_provision.rb +21 -0
  41. data/lib/vagrant-cosmic/action/wait_for_state.rb +41 -0
  42. data/lib/vagrant-cosmic/action/warn_networks.rb +19 -0
  43. data/lib/vagrant-cosmic/action.rb +210 -0
  44. data/lib/vagrant-cosmic/capabilities/rdp.rb +12 -0
  45. data/lib/vagrant-cosmic/capabilities/winrm.rb +12 -0
  46. data/lib/vagrant-cosmic/config.rb +422 -0
  47. data/lib/vagrant-cosmic/errors.rb +27 -0
  48. data/lib/vagrant-cosmic/exceptions/exceptions.rb +15 -0
  49. data/lib/vagrant-cosmic/model/cosmic_resource.rb +51 -0
  50. data/lib/vagrant-cosmic/plugin.rb +82 -0
  51. data/lib/vagrant-cosmic/provider.rb +58 -0
  52. data/lib/vagrant-cosmic/service/cosmic_resource_service.rb +76 -0
  53. data/lib/vagrant-cosmic/util/timer.rb +17 -0
  54. data/lib/vagrant-cosmic/version.rb +5 -0
  55. data/lib/vagrant-cosmic.rb +17 -0
  56. data/locales/en.yml +131 -0
  57. data/spec/spec_helper.rb +53 -0
  58. data/spec/vagrant-cosmic/action/read_ssh_info_spec.rb +80 -0
  59. data/spec/vagrant-cosmic/action/retrieve_public_ip_port_spec.rb +94 -0
  60. data/spec/vagrant-cosmic/action/run_instance_spec.rb +573 -0
  61. data/spec/vagrant-cosmic/action/terminate_instance_spec.rb +207 -0
  62. data/spec/vagrant-cosmic/config_spec.rb +340 -0
  63. data/spec/vagrant-cosmic/model/cosmic_resource_spec.rb +95 -0
  64. data/spec/vagrant-cosmic/service/cosmic_resource_service_spec.rb +43 -0
  65. data/spec/vagrant-cosmic/support/be_a_resource.rb +6 -0
  66. data/vagrant-cosmic.gemspec +59 -0
  67. data/vagrant-cosmic.spec +42 -0
  68. metadata +218 -0
@@ -0,0 +1,14 @@
1
+ describe 'Networking features' do
2
+ it 'creates firewall and portwarding rules for both Virtual Router and VPC' do
3
+ expect(`vagrant up`).to include(
4
+ 'VRbox1: Machine is booted and ready for use!',
5
+ 'VRbox2: Machine is booted and ready for use!',
6
+ 'VPCbox1: Machine is booted and ready for use!',
7
+ 'VPCbox2: Machine is booted and ready for use!'
8
+ )
9
+ expect($?.exitstatus).to eq(0)
10
+
11
+ expect(`vagrant destroy --force`).to include('Terminating the instance...')
12
+ expect($?.exitstatus).to eq(0)
13
+ end
14
+ end
@@ -0,0 +1,40 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = '2'
6
+
7
+ Vagrant.require_version '>= 1.5.0'
8
+
9
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
10
+ config.vm.box = ENV['LINUX_TEMPLATE_NAME']
11
+
12
+ config.vm.synced_folder ".", "/vagrant", type: "rsync",
13
+ rsync__exclude: [".git/", "vendor"]
14
+
15
+ config.vm.provider :cosmic do |cosmic, override|
16
+ cosmic.display_name = ENV['TEST_NAME']
17
+
18
+ cosmic.host = ENV['COSMIC_HOST']
19
+ cosmic.path = '/client/api'
20
+ cosmic.port = '443'
21
+ cosmic.scheme = 'https'
22
+ cosmic.api_key = ENV['COSMIC_API_KEY']
23
+ cosmic.secret_key = ENV['COSMIC_SECRET_KEY']
24
+ cosmic.expunge_on_destroy = ENV['EXPUNGE_ON_DESTROY']=="true"
25
+
26
+ cosmic.zone_name = ENV['ZONE_NAME']
27
+ cosmic.network_name = ENV['NETWORK_NAME']
28
+ cosmic.service_offering_name = ENV['SERVICE_OFFERING_NAME']
29
+
30
+ cosmic.pf_ip_address = ENV['PUBLIC_SOURCE_NAT_IP']
31
+ cosmic.pf_trusted_networks = ENV['SOURCE_CIDR']
32
+ cosmic.pf_open_firewall = false
33
+
34
+ unless ENV['SSH_KEY'].nil?
35
+ cosmic.ssh_key = ENV['SSH_KEY']
36
+ cosmic.ssh_user = ENV['SSH_USER']
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,9 @@
1
+ describe 'VM RSync' do
2
+ it 'does rsync to the VM' do
3
+ expect(`vagrant up`).to include('Machine is booted and ready for use!')
4
+ expect($?.exitstatus).to eq(0)
5
+ expect(`vagrant ssh -c "ls /vagrant; echo;"`).to include('Vagrantfile.advanced_networking')
6
+ expect(`vagrant destroy --force`).to include('Terminating the instance...')
7
+ expect($?.exitstatus).to eq(0)
8
+ end
9
+ end
@@ -0,0 +1,64 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = '2'
6
+
7
+ Vagrant.require_version '>= 1.5.0'
8
+
9
+ machines = {
10
+ 'linux-box' => {
11
+ 'template' => ENV['LINUX_TEMPLATE_NAME'],
12
+ 'communicator' => 'ssh',
13
+ 'rsync_disabled' => true
14
+ },
15
+ 'windows-box' => {
16
+ 'template' => ENV['WINDOWS_TEMPLATE_NAME'],
17
+ 'communicator' => 'winrm',
18
+ 'rsync_disabled' => true
19
+ }
20
+ }
21
+
22
+
23
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |global_config|
24
+ machines.each_pair do |name, options|
25
+ global_config.vm.define name do |config|
26
+ config.vm.box = options['template']
27
+
28
+ config.vm.communicator = options['communicator']
29
+ config.winrm.retry_delay = 30
30
+ config.vm.synced_folder ".", "/vagrant", type: "rsync",
31
+ rsync__exclude: [".git/", "vendor"], disabled: options['rsync_disabled']
32
+ config.vm.provider :cosmic do |cosmic, override|
33
+
34
+ cosmic.display_name = ENV['TEST_NAME']
35
+
36
+ cosmic.host = ENV['COSMIC_HOST']
37
+ cosmic.path = '/client/api'
38
+ cosmic.port = '443'
39
+ cosmic.scheme = 'https'
40
+ cosmic.api_key = ENV['COSMIC_API_KEY']
41
+ cosmic.secret_key = ENV['COSMIC_SECRET_KEY']
42
+ cosmic.expunge_on_destroy = ENV['EXPUNGE_ON_DESTROY']=="true"
43
+
44
+ cosmic.zone_name = ENV['ZONE_NAME']
45
+ cosmic.network_name = ENV['NETWORK_NAME']
46
+ cosmic.service_offering_name = ENV['SERVICE_OFFERING_NAME']
47
+ cosmic.disk_offering_name = ENV['DISK_OFFERING_NAME']
48
+
49
+ cosmic.pf_ip_address = ENV['PUBLIC_SOURCE_NAT_IP']
50
+
51
+ cosmic.pf_public_port = options['public_port']
52
+ cosmic.pf_private_port = options['private_port']
53
+ cosmic.pf_trusted_networks = ENV['SOURCE_CIDR']
54
+ cosmic.pf_open_firewall = false
55
+
56
+
57
+ cosmic.ssh_key = ENV['SSH_KEY'] unless ENV['SSH_KEY'].nil?
58
+ cosmic.ssh_user = ENV['SSH_USER'] unless ENV['SSH_USER'].nil?
59
+ cosmic.vm_user = ENV['WINDOWS_USER'] unless ENV['WINDOWS_USER'].nil?
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ def which(cmd)
2
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
3
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
4
+ exts.each { |ext|
5
+ exe = File.join(path, "#{cmd}#{ext}")
6
+ return exe if File.executable?(exe) && !File.directory?(exe)
7
+ }
8
+ end
9
+ return nil
10
+ end
11
+ insert_tee_log = ' 2>&1 | tee -a vagrant.log ' if which('tee')
12
+
13
+ describe 'VM Life Cycle' do
14
+ it 'starts Linux and Windows VM' do
15
+ expect(`vagrant up #{insert_tee_log}`).to include(
16
+ 'linux-box: Machine is booted and ready for use!',
17
+ 'windows-box: Machine is booted and ready for use!'
18
+ )
19
+ expect($?.exitstatus).to eq(0)
20
+ end
21
+ it 'destroys Linux and Windows VM' do
22
+ expect(`vagrant destroy --force #{insert_tee_log}`).to include('Done removing resources')
23
+ expect($?.exitstatus).to eq(0)
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ require 'fog/cosmic'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module Cosmic
6
+ module Action
7
+ # This action connects to Cosmic, verifies credentials work, and
8
+ # puts the Cosmic connection object into the
9
+ # `:cosmic_compute` key in the environment.
10
+ class ConnectCosmic
11
+ def initialize(app, env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new('vagrant_cosmic::action::connect_cosmic')
14
+ end
15
+
16
+ def call(env)
17
+ # Get the domain we're going to booting up in
18
+ domain = env[:machine].provider_config.domain_id
19
+
20
+ # Get the configs
21
+ domain_config = env[:machine].provider_config.get_domain_config(domain)
22
+
23
+ # Build the fog config
24
+ fog_config = {
25
+ :provider => :cosmic
26
+ #:domain => domain_config
27
+ }
28
+
29
+ if domain_config.api_key
30
+ fog_config[:cosmic_api_key] = domain_config.api_key
31
+ fog_config[:cosmic_secret_access_key] = domain_config.secret_key
32
+ end
33
+
34
+ fog_config[:cosmic_host] = domain_config.host if domain_config.host
35
+ fog_config[:cosmic_path] = domain_config.path if domain_config.path
36
+ fog_config[:cosmic_port] = domain_config.port if domain_config.port
37
+ fog_config[:cosmic_scheme] = domain_config.scheme if domain_config.scheme
38
+
39
+ @logger.info('Connecting to Cosmic...')
40
+ env[:cosmic_compute] = Fog::Compute.new(fog_config)
41
+
42
+ @app.call(env)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id != :not_created
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is stopped and branch in the middleware.
6
+ class IsStopped
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id == :stopped
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Action
4
+ class MessageAlreadyCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_cosmic.already_status", :status => "created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Action
4
+ class MessageNotCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_cosmic.not_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Action
4
+ class MessageWillNotDestroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_cosmic.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'read_transport_info.rb'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module Cosmic
6
+ module Action
7
+ # This action reads the WinRM info for the machine and puts it into the
8
+ # `:machine_winrm_info` key in the environment.
9
+ class ReadRdpInfo < ReadTransportInfo
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_cosmic::action::read_rdp_info")
13
+
14
+ @public_port_fieldname = 'pf_public_rdp_port'
15
+ end
16
+
17
+ def call(env)
18
+ env[:machine_rdp_info] = read_rdp_info(env[:cosmic_compute], env[:machine])
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ def read_rdp_info(cosmic, machine)
24
+ return nil if (server = find_server(cosmic, machine)).nil?
25
+
26
+ # Get the Port forwarding config
27
+ domain = machine.provider_config.domain_id
28
+ domain_config = machine.provider_config.get_domain_config(domain)
29
+
30
+ pf_ip_address, pf_public_port = retrieve_public_ip_port(cosmic, domain_config, machine)
31
+
32
+ transport_info = {
33
+ :host => pf_ip_address || server.nics[0]['ipaddress'],
34
+ :port => pf_public_port
35
+ }
36
+
37
+ transport_info
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,70 @@
1
+ require_relative 'read_transport_info.rb'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module Cosmic
6
+ module Action
7
+ # This action reads the SSH info for the machine and puts it into the
8
+ # `:machine_ssh_info` key in the environment.
9
+ class ReadSSHInfo < ReadTransportInfo
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_cosmic::action::read_ssh_info")
13
+
14
+ @public_port_fieldname = 'pf_public_port'
15
+ end
16
+
17
+ def call(env)
18
+ env[:machine_ssh_info] = read_ssh_info(env[:cosmic_compute], env[:machine])
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ def read_ssh_info(cosmic, machine)
24
+ return nil if (server = find_server(cosmic, machine)).nil?
25
+
26
+ # Get the Port forwarding config
27
+ domain = machine.provider_config.domain_id
28
+ domain_config = machine.provider_config.get_domain_config(domain)
29
+
30
+ pf_ip_address, pf_public_port = retrieve_public_ip_port(cosmic, domain_config, machine)
31
+
32
+ if domain_config.keypair.nil? && domain_config.ssh_key.nil?
33
+ sshkeyfile_file = machine.data_dir.join('sshkeyfile')
34
+ if sshkeyfile_file.file?
35
+ domain_config.ssh_key = sshkeyfile_file.to_s
36
+ end
37
+ end
38
+
39
+ nic_ip_address = fetch_nic_ip_address(server.nics, domain_config)
40
+
41
+ transport_info = {
42
+ :host => pf_ip_address || nic_ip_address,
43
+ :port => pf_public_port
44
+ }
45
+ transport_info = transport_info.merge({
46
+ :private_key_path => domain_config.ssh_key,
47
+ :password => nil
48
+ }) unless domain_config.ssh_key.nil?
49
+ transport_info = transport_info.merge({ :username => domain_config.ssh_user }) unless domain_config.ssh_user.nil?
50
+ transport_info
51
+ end
52
+
53
+ def fetch_nic_ip_address(nics, domain_config)
54
+ ssh_nic =
55
+ if !domain_config.ssh_network_id.nil?
56
+ nics.find { |nic| nic["networkid"] == domain_config.ssh_network_id }
57
+ elsif !domain_config.ssh_network_name.nil?
58
+ nics.find { |nic| nic["networkname"] == domain_config.ssh_network_name }
59
+ else
60
+ # When without neither ssh_network_id and ssh_network_name, use 1st nic
61
+ nics[0]
62
+ end
63
+
64
+ ssh_nic ||= nics[0]
65
+ ssh_nic["ipaddress"]
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,38 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module Cosmic
5
+ module Action
6
+ # This action reads the state of the machine and puts it in the
7
+ # `:machine_state_id` key in the environment.
8
+ class ReadState
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_cosmic::action::read_state")
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_state_id] = read_state(env[:cosmic_compute], env[:machine])
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_state(cosmic, machine)
21
+ return :not_created if machine.id.nil?
22
+
23
+ # Find the machine
24
+ server = cosmic.servers.get(machine.id)
25
+ if server.nil? || [:"shutting-down", :terminated].include?(server.state.downcase.to_sym)
26
+ # The machine can't be found
27
+ @logger.info("Machine not found or terminated, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return :not_created
30
+ end
31
+
32
+ # Return the state
33
+ server.state.downcase.to_sym
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,59 @@
1
+ module VagrantPlugins
2
+ module Cosmic
3
+ module Action
4
+ class ReadTransportInfo
5
+ def initialize
6
+ @public_port_fieldname = 'pf_public_port'
7
+ end
8
+
9
+ def retrieve_public_ip_port(cosmic, domain_config, machine)
10
+ pf_ip_address_id = domain_config.pf_ip_address_id
11
+ pf_ip_address = domain_config.pf_ip_address
12
+ pf_public_port = domain_config.send(@public_port_fieldname)
13
+
14
+ if pf_public_port.nil?
15
+ pf_public_port_file = machine.data_dir.join(@public_port_fieldname)
16
+ if pf_public_port_file.file?
17
+ File.read(pf_public_port_file).each_line do |line|
18
+ pf_public_port = line.strip
19
+ end
20
+ domain_config.send("#{@public_port_fieldname}=", pf_public_port)
21
+ end
22
+ end
23
+
24
+ if not pf_ip_address and pf_ip_address_id and pf_public_port
25
+ begin
26
+ response = cosmic.list_public_ip_addresses({:id => pf_ip_address_id})
27
+ rescue Fog::Cosmic::Compute::Error => e
28
+ raise Errors::FogError, :message => e.message
29
+ end
30
+
31
+ if (response['listpublicipaddressesresponse']['count']).zero?
32
+ @logger.info("IP address #{pf_ip_address_id} not exists.")
33
+ env[:ui].info(I18n.t("IP address #{pf_ip_address_id} not exists."))
34
+ pf_ip_address = nil
35
+ else
36
+ pf_ip_address = response['listpublicipaddressesresponse']['publicipaddress'][0]['ipaddress']
37
+ end
38
+ end
39
+ return pf_ip_address, pf_public_port
40
+ end
41
+
42
+ def find_server(cosmic, machine)
43
+ return nil if machine.id.nil?
44
+
45
+ # Find the machine
46
+ server = cosmic.servers.get(machine.id)
47
+ if server.nil? || [:"shutting-down", :terminated].include?(server.state.downcase.to_sym)
48
+ # The machine can't be found
49
+ @logger.info("Machine couldn't be found, assuming it got destroyed.")
50
+ machine.id = nil
51
+ return nil
52
+ end
53
+
54
+ server
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,69 @@
1
+ require_relative 'read_transport_info.rb'
2
+ require 'log4r'
3
+
4
+ module VagrantPlugins
5
+ module Cosmic
6
+ module Action
7
+ # This action reads the WinRM info for the machine and puts it into the
8
+ # `:machine_winrm_info` key in the environment.
9
+ class ReadWinrmInfo < ReadTransportInfo
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_cosmic::action::read_winrm_info")
13
+
14
+ @public_port_fieldname = 'pf_public_port'
15
+ end
16
+
17
+ def call(env)
18
+ env[:machine_winrm_info] = read_winrm_info(env[:cosmic_compute], env[:machine])
19
+
20
+ @app.call(env)
21
+ end
22
+
23
+ def read_winrm_info(cosmic, machine)
24
+ return nil if (server = find_server(cosmic, machine)).nil?
25
+
26
+ # Get the Port forwarding config
27
+ domain = machine.provider_config.domain_id
28
+ domain_config = machine.provider_config.get_domain_config(domain)
29
+
30
+ pf_ip_address, pf_public_port = retrieve_public_ip_port(cosmic, domain_config, machine)
31
+
32
+
33
+ transport_info = {
34
+ :host => pf_ip_address || server.nics[0]['ipaddress'],
35
+ :port => pf_public_port
36
+ }
37
+
38
+ transport_info = transport_info.merge({
39
+ :username => domain_config.vm_user
40
+ }) unless domain_config.vm_user.nil?
41
+ machine.config.winrm.username = domain_config.vm_user unless domain_config.vm_user.nil?
42
+ # The WinRM communicator doesnt support passing
43
+ # the username via winrm_info ... yet ;-)
44
+
45
+ # Read password from file into domain_config
46
+ if domain_config.vm_password.nil?
47
+ vmcredentials_file = machine.data_dir.join("vmcredentials")
48
+ if vmcredentials_file.file?
49
+ vmcredentials_password = nil
50
+ File.read(vmcredentials_file).each_line do |line|
51
+ vmcredentials_password = line.strip
52
+ end
53
+ domain_config.vm_password = vmcredentials_password
54
+ end
55
+ end
56
+
57
+ transport_info = transport_info.merge({
58
+ :password => domain_config.vm_password
59
+ }) unless domain_config.vm_password.nil?
60
+ # The WinRM communicator doesnt support passing
61
+ # the password via winrm_info ... yet ;-)
62
+ machine.config.winrm.password = domain_config.vm_password unless domain_config.vm_password.nil?
63
+
64
+ transport_info
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end