Class: VagrantPlugins::Google::Action::SetupWinrmPassword
- Inherits:
-
Object
- Object
- VagrantPlugins::Google::Action::SetupWinrmPassword
- Defined in:
- lib/vagrant-google/action/setup_winrm_password.rb
Overview
Sets up a temporary WinRM password using Google’s method for establishing a new password over encrypted channels.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ SetupWinrmPassword
constructor
A new instance of SetupWinrmPassword.
- #setup_password(env, instance, zone, user) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ SetupWinrmPassword
Returns a new instance of SetupWinrmPassword.
26 27 28 29 |
# File 'lib/vagrant-google/action/setup_winrm_password.rb', line 26 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant_google::action::setup_winrm_password") end |
Instance Method Details
#call(env) ⇒ Object
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 |
# File 'lib/vagrant-google/action/setup_winrm_password.rb', line 42 def call(env) # Get the configs zone = env[:machine].provider_config.zone zone_config = env[:machine].provider_config.get_zone_config(zone) instance = zone_config.name user = env[:machine].config.winrm.username pass = env[:machine].config.winrm.password # Get Temporary Password, set WinRM password temp_pass = setup_password(env, instance, zone, user) env[:machine].config.winrm.password = temp_pass # Wait for WinRM To be Ready env[:ui].info("Waiting for WinRM To be ready") env[:machine].communicate.wait_for_ready(60) # Use WinRM to Change Password to one in Vagrantfile env[:ui].info("Changing password from temporary to winrm password") winrmcomm = VagrantPlugins::CommunicatorWinRM::Communicator.new(env[:machine]) cmd = "net user #{user} #{pass}" opts = { elevated: true } winrmcomm.test(cmd, opts) # Update WinRM password to reflect updated one env[:machine].config.winrm.password = pass end |
#setup_password(env, instance, zone, user) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vagrant-google/action/setup_winrm_password.rb', line 31 def setup_password(env, instance, zone, user) # Setup compute = env[:google_compute] server = compute.servers.get(instance, zone) password = server.reset_windows_password(user) env[:ui].info("Temp Password: #{password}") password end |