Class: Chef::Knife::RaxClusterBuild

Inherits:
RackspaceServerCreate
  • Object
show all
Includes:
Knife::RackspaceBase
Defined in:
lib/chef/knife/rax_cluster_build.rb

Instance Method Summary collapse

Instance Method Details

#runObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/chef/knife/rax_cluster_build.rb', line 137

def run
  $stdout.sync = true

  unless Chef::Config[:knife][:image]
    ui.error("You have not provided a valid image value.  Please note the short option for this value recently changed from '-i' to '-I'.")
    exit 1
  end

  node_name = get_node_name(config[:chef_node_name] || config[:server_name])

  server = connection.servers.create(
    :name => node_name,
    :image_id => Chef::Config[:knife][:image],
    :flavor_id => locate_config_value(:flavor),
    :metadata => Chef::Config[:knife][:rackspace_metadata]
    )

  msg_pair("Instance ID", server.id)
  msg_pair("Host ID", server.host_id)
  msg_pair("Name", server.name)
  msg_pair("Flavor", server.flavor.name)
  msg_pair("Image", server.image.name)
  msg_pair("Metadata", server.)

  print "\n#{ui.color("Waiting server", :magenta)}"

  # wait for it to be ready to do stuff
  server.wait_for { print "."; ready? }

  puts("\n")

  msg_pair("Public DNS Name", public_dns_name(server))
  msg_pair("Public IP Address", public_ip(server))
  msg_pair("Private IP Address", private_ip(server))
  msg_pair("Password", server.password)

  print "\n#{ui.color("Waiting for sshd", :magenta)}"

  #which IP address to bootstrap
  bootstrap_ip_address = public_ip(server)
  if config[:private_network]
    bootstrap_ip_address = private_ip(server)
  end
  Chef::Log.debug("Bootstrap IP Address #{bootstrap_ip_address}")
  if bootstrap_ip_address.nil?
    ui.error("No IP address available for bootstrapping.")
    exit 1
  end

  print(".") until tcp_test_ssh(bootstrap_ip_address) {
    sleep @initial_sleep_delay ||= 10
    puts("done")
  }
  bootstrap_for_node(server, bootstrap_ip_address).run

  puts "\n"
  msg_pair("Instance ID", server.id)
  msg_pair("Host ID", server.host_id)
  msg_pair("Name", server.name)
  msg_pair("Flavor", server.flavor.name)
  msg_pair("Image", server.image.name)
  msg_pair("Metadata", server.)
  msg_pair("Public DNS Name", public_dns_name(server))
  msg_pair("Public IP Address", public_ip(server))
  msg_pair("Private IP Address", private_ip(server))
  msg_pair("Password", server.password)
  msg_pair("Environment", config[:environment] || '_default')
  msg_pair("Run List", config[:run_list].join(', '))
  ipaddress = ''
  #if not server.private_ip_address
  #  ipaddress = server.public_ip_address
  #end
  #if not ipaddress
  #  ipaddress = "false"
  #end
  return_hash = {"public_ip" => public_ip(server), "private_ip" => private_ip(server), "server_name" => server.name, "server_id" => server.id}
  return return_hash
end

#tcp_test_ssh(hostname) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/chef/knife/rax_cluster_build.rb', line 113

def tcp_test_ssh(hostname)
  tcp_socket = TCPSocket.new(hostname, 22)
  readable = IO.select([tcp_socket], nil, nil, 5)
  if readable
    Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
    yield
    true
  else
    false
  end
rescue Errno::ETIMEDOUT
  false
rescue Errno::EPERM
  false
rescue Errno::ECONNREFUSED
  sleep 2
  false
rescue Errno::EHOSTUNREACH
  sleep 2
  false
ensure
  tcp_socket && tcp_socket.close
end