lib/chef/knife/winrm_bootstrap.rb in knife-windows-0.5.0 vs lib/chef/knife/winrm_bootstrap.rb in knife-windows-0.5.1
- old
+ new
@@ -15,22 +15,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/knife'
+require 'erubis'
class Chef
class Knife
- class WinrmBootstrap < Knife
+ class WinrmBootstrap < Bootstrap
deps do
+ require 'chef/knife/core/windows_bootstrap_context'
require 'chef/json_compat'
require 'tempfile'
- require 'erubis'
+ Chef::Knife::Winrm.load_deps
end
- banner "knife winrm bootstrap FQDN [RUN LIST...] (options)"
+ banner "knife winrm bootstrap FQDN (options)"
option :winrm_user,
:short => "-x USERNAME",
:long => "--winrm-user USERNAME",
:description => "The WinRM username",
@@ -88,10 +90,15 @@
option :prerelease,
:long => "--prerelease",
:description => "Install the pre-release chef gems"
+ option :bootstrap_version,
+ :long => "--bootstrap-version VERSION",
+ :description => "The version of Chef to install",
+ :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
+
option :distro,
:short => "-d DISTRO",
:long => "--distro DISTRO",
:description => "Bootstrap a distro using a template",
:default => "windows-shell"
@@ -106,10 +113,11 @@
:long => "--run-list RUN_LIST",
:description => "Comma separated list of roles/recipes to apply",
:proc => lambda { |o| o.split(",") },
:default => []
+ # TODO: This should go away when CHEF-2193 is fixed
def load_template(template=nil)
# Are we bootstrapping using an already shipped template?
if config[:template_file]
bootstrap_files = config[:template_file]
else
@@ -134,13 +142,11 @@
IO.read(template).chomp
end
def render_template(template=nil)
- context = {}
- context[:run_list] = config[:run_list]
- context[:config] = config
+ context = Knife::Core::WindowsBootstrapContext.new(config, config[:run_list], Chef::Config)
Erubis::Eruby.new(template).evaluate(context)
end
def run
@@ -161,21 +167,21 @@
# execute the bootstrap.bat file
knife_winrm(bootstrap_command).run
end
- def validate_name_args!
- if Array(@name_args).first.nil?
- ui.error("Must pass an FQDN or ip to bootstrap")
- exit 1
- end
- end
+ # def validate_name_args!
+ # if Array(@name_args).first.nil?
+ # ui.error("Must pass an FQDN or ip to bootstrap")
+ # exit 1
+ # end
+ # end
+ #
+ # def server_name
+ # Array(@name_args).first
+ # end
- def server_name
- Array(@name_args).first
- end
-
def knife_winrm(command = '')
winrm = Chef::Knife::Winrm.new
winrm.name_args = [ server_name, command ]
winrm.config[:winrm_user] = Chef::Config[:knife][:winrm_user] || config[:winrm_user]
winrm.config[:winrm_password] = Chef::Config[:knife][:winrm_password] if config[:winrm_password]
@@ -183,11 +189,11 @@
winrm.config[:kerberos_keytab_file] = Chef::Config[:knife][:kerberos_keytab_file] if Chef::Config[:knife][:kerberos_keytab_file]
winrm.config[:kerberos_realm] = Chef::Config[:knife][:kerberos_realm] if Chef::Config[:knife][:kerberos_realm]
winrm.config[:kerberos_service] = Chef::Config[:knife][:kerberos_service] if Chef::Config[:knife][:kerberos_service]
winrm.config[:ca_trust_file] = Chef::Config[:knife][:ca_trust_file] if Chef::Config[:knife][:ca_trust_file]
winrm.config[:manual] = true
- winrm.config[:winrm_port] = Chef::Config[:knife][:winrm_port]
+ winrm.config[:winrm_port] = Chef::Config[:knife][:winrm_port] || config[:winrm_port]
winrm
end
def bootstrap_command
@bootstrap_command ||= "cmd /C #{bootstrap_bat_file}"
@@ -210,9 +216,10 @@
end
def bootstrap_bat_file
"%TEMP%\\bootstrap.bat"
end
+
end
end
end