Class: Chef::Knife::Cloud::Bootstrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Bootstrapper

Returns a new instance of Bootstrapper.



31
32
33
34
# File 'lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb', line 31

def initialize(config)
  @config = config
  @ui ||= Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
end

Instance Method Details

#bootstrapObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb', line 36

def bootstrap
  # uses BootstrapDistribution and BootstrapProtocol to perform bootstrap
  @protocol = create_bootstrap_protocol
  @distribution = create_bootstrap_distribution
  begin
    @protocol.send_bootstrap_command
  rescue Net::SSH::AuthenticationFailed => e
    error_message = "Authentication Failed during bootstrapping. #{e.message}."
    raise CloudExceptions::BootstrapError, error_message
  end
end

#create_bootstrap_distributionObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb', line 61

def create_bootstrap_distribution
  if @config[:image_os_type] == "windows" || @config[:image_os_type] == "linux"
    Chef::Knife::Cloud::BootstrapDistribution.new(@config)
  else
    # raise an exception, invalid bootstrap distribution.
    error_message = "Invalid bootstrap distribution. image_os_type should be either windows or linux."
    ui.fatal(error_message)
    raise CloudExceptions::BootstrapError, error_message
  end
end

#create_bootstrap_protocolObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/knife/cloud/chefbootstrap/bootstrapper.rb', line 48

def create_bootstrap_protocol
  if @config[:connection_protocol].nil? || @config[:connection_protocol] == "ssh"
    SshBootstrapProtocol.new(@config)
  elsif @config[:connection_protocol] == "winrm"
    WinrmBootstrapProtocol.new(@config)
  else
    # raise an exception, invalid bootstrap protocol.
    error_message = "Invalid bootstrap protocol."
    ui.fatal(error_message)
    raise CloudExceptions::BootstrapError, error_message
  end
end