forked from ggiamarchi/vagrant-openstack-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for dynamically generated password for Windows boxes (Issue
- Loading branch information
Showing
6 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
source/lib/vagrant-openstack-provider/action/read_server_password.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'log4r' | ||
|
||
require 'vagrant-openstack-provider/config_resolver' | ||
require 'vagrant-openstack-provider/utils' | ||
require 'vagrant-openstack-provider/action/abstract_action' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Action | ||
# This action reads the server password for the machine and puts it into the | ||
# `config.winrm.password` key in the environment. | ||
|
||
class ReadServerPassword < AbstractAction | ||
def initialize(app, _env) | ||
@app = app | ||
@logger = Log4r::Logger.new('vagrant_openstack::action::read_server_password') | ||
end | ||
|
||
def execute(env) | ||
read_server_password(env) | ||
@app.call(env) | ||
end | ||
|
||
private | ||
|
||
def read_server_password(env) | ||
require 'openssl' | ||
require 'base64' | ||
machine=env[:machine] | ||
if VagrantPlugins::Openstack::Cap.need_dynamic_password_update(machine.config) | ||
@logger.info 'Reading server password from openstack' | ||
encoded_passwd_b64=env[:openstack_client].nova.get_server_password(env, machine.id) | ||
if (encoded_passwd_b64==nil || encoded_passwd_b64=='') | ||
@logger.info "no password yet, the machine is not ready" | ||
else | ||
@logger.debug "encoded password b64 #{encoded_passwd_b64}" | ||
encoded_passwd=Base64.decode64(encoded_passwd_b64) | ||
ssh_key_path=env[:machine_ssh_info][:private_key_path] | ||
@logger.debug "key path #{ssh_key_path}" | ||
ssh_key = OpenSSL::PKey::RSA.new File.read(ssh_key_path) | ||
clear_passwd = ssh_key.private_decrypt(encoded_passwd) | ||
VagrantPlugins::Openstack::Cap.update_dynamic_password(machine.config,clear_passwd) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module VagrantPlugins | ||
module Openstack | ||
module Cap | ||
@logger = Log4r::Logger.new('vagrant_openstack::capability::winrm_info') | ||
|
||
def self.winrm_info(machine) | ||
# if we need dynamic password update from openstack? | ||
if need_dynamic_password_update(machine.config) | ||
@logger.info "config.winrm.password needs dynamic update, will retrieve it from openstack" | ||
env = machine.action('read_server_password', lock: false) | ||
# is password now updated? | ||
if need_dynamic_password_update(env[:machine].config) | ||
# if we have no server password yet in openstack, we are not ready. Return nil to tell that. | ||
return nil | ||
end | ||
else | ||
@logger.info "config.winrm.password is set to a non-dynamic value (i.e. not ':dynamic'), keeping it" | ||
end | ||
# if ok with password, return just nil values for host and port, so that winrm executes its default code. | ||
return { | ||
host: nil, | ||
port: nil | ||
} | ||
end | ||
|
||
def self.need_dynamic_password_update(config) | ||
return config.winrm.password == :dynamic | ||
end | ||
|
||
def self.update_dynamic_password(config,new_password) | ||
if config.winrm.password == :dynamic | ||
config.winrm.password=new_password | ||
@logger.info "config.winrm.password changed to the dynamic one from openstack" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters