Module: Chef::Knife::VcBootstrapCommon

Included in:
VcVappBootstrap, VcVmBootstrap
Defined in:
lib/chef/knife/common/vc_bootstrap_common.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/chef/knife/common/vc_bootstrap_common.rb', line 22

def self.included(includer)
  includer.class_eval do
    deps do
      require 'chef/knife/bootstrap'
      require 'chef/knife/bootstrap_windows_winrm'
      require 'chef/knife/core/windows_bootstrap_context'
      Chef::Knife::Bootstrap.load_deps
    end

    option :run_list,
      :short => "-r RUN_LIST",
      :long => "--run-list RUN_LIST",
      :description => "Comma separated list of roles/recipes to apply",
      :proc => lambda { |o| o.split(/[\s,]+/) },
      :default => []

    option :distro,
      :short => "-d DISTRO",
      :long => "--distro DISTRO",
      :description => "Bootstrap a distro using a template; default is 'chef-full'",
      :proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
      :default => "chef-full"

    option :bootstrap_windows,
      :long => "--[no-]bootstrap-windows",
      :description => "The machine to be bootstrapped is Windows",
      :boolean => true,
      :default => false

    option :bootstrap_proxy,
      :long => "--bootstrap-proxy PROXY_URL",
      :description => "The proxy server for the node being bootstrapped",
      :proc => Proc.new { |v| Chef::Config[:knife][:bootstrap_proxy] = v }

    option :ssh_user,
      :short => "-x USERNAME",
      :long => "--ssh-user USERNAME",
      :description => "The ssh username",
      :default => "root"

    option :ssh_password,
      :short => "-P PASSWORD",
      :long => "--ssh-password PASSWORD",
      :description => "The ssh password"

    option :ssh_port,
      :short => "-p PORT",
      :long => "--ssh-port PORT",
      :description => "The ssh port",
      :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key },
      :default => 22

    option :ssh_gateway,
      :short => "-G GATEWAY",
      :long => "--ssh-gateway GATEWAY",
      :description => "The ssh gateway",
      :proc => Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }

    option :forward_agent,
      :short => "-A",
      :long => "--forward-agent",
      :description => "Enable SSH agent forwarding",
      :boolean => true

    option :identity_file,
      :short => "-i IDENTITY_FILE",
      :long => "--identity-file IDENTITY_FILE",
      :description => "The SSH identity file used for authentication"

    option :host_key_verify,
      :long => "--[no-]host-key-verify",
      :description => "Verify host key, enabled by default.",
      :boolean => true,
      :default => true

    option :max_tries,
      :long => "--max-tries MAX_TRIES",
      :description => "Max number of connection tries for each VM",
      :default => 5

    option :secret,
      :short => "-s SECRET",
      :long  => "--secret ",
      :description => "The secret key to use to encrypt data bag item values",
      :proc => Proc.new { |s| Chef::Config[:knife][:secret] = s }

    option :secret_file,
      :long => "--secret-file SECRET_FILE",
      :description => "A file containing the secret key to use to encrypt data bag item values",
      :proc => Proc.new { |sf| Chef::Config[:knife][:secret_file] = sf }

    option :template_file,
      :long => "--template-file TEMPLATE_FILE",
      :description => "Template file to use for bootstrap",
      :proc => Proc.new { |sf| Chef::Config[:knife][:template_file] = tf }

    Chef::Config[:knife][:hints] ||= {"vcloud" => {}}
    option :hint,
      :long => "--hint HINT_FILE",
      :description => "Specify Ohai Hint to be set on the bootstrap target.",
      :proc => Proc.new { |path| Chef::Config[:knife][:hints]["vcloud"] = path ? JSON.parse(::File.read(path)) : Hash.new }
  end
end

Instance Method Details

#bootstrap_vm(vm_name, id, addresses) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/chef/knife/common/vc_bootstrap_common.rb', line 126

def bootstrap_vm(vm_name, id, addresses)
  ui.msg "Bootstrap VM: #{vm_name}..."

  max_tries = locate_config_value(:max_tries)
  ssh_port = locate_config_value(:ssh_port)

  # Stop at the first reachable IP address
  reachable_ip = nil
  addresses.each do |address|
    tries = 1

    until tries > max_tries
      ui.info "Trying to reach #{address} (try #{tries}/#{max_tries})"

      if test_connection_ssh(address, ssh_port)
        reachable_ip = address
        break
      end
      tries += 1
    end
    break if reachable_ip
  end

  if reachable_ip
    ui.msg "Bootstrap IP: #{reachable_ip}"
    bootstrap_for_node(reachable_ip).run
  else
    ui.warn "No reachable IPs. Not bootstrapping."
  end
end