Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

[KNIFE-335] Wait for RackConnect and/or Service Level automation before bootstrapping #42

Merged
merged 14 commits into from Sep 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/chef/knife/rackspace_base.rb
Expand Up @@ -139,7 +139,7 @@ def public_ip(server)
if version_one?
v1_public_ip(server)
else
v2_public_ip(server)
v2_access_ip(server) ? v2_access_ip(server) : v2_public_ip(server)
end
end

Expand Down Expand Up @@ -190,6 +190,10 @@ def v2_private_ip(server)
extract_ipv4_address(private_ips) if private_ips
end

def v2_access_ip(server)
server.access_ipv4_address == nil ? "" : server.access_ipv4_address
end

def extract_ipv4_address(ip_addresses)
address = ip_addresses.select { |ip| ip["version"] == 4 }.first
address ? address["addr"] : ""
Expand Down
49 changes: 49 additions & 0 deletions lib/chef/knife/rackspace_server_create.rb
Expand Up @@ -129,6 +129,18 @@ class RackspaceServerCreate < Knife
:proc => Proc.new { |m| Chef::Config[:knife][:rackspace_metadata] = JSON.parse(m) },
:default => ""

option :rackconnect_wait,
:long => "--rackconnect-wait",
:description => "Wait until the Rackconnect automation setup is complete before bootstrapping chef",
:boolean => true,
:default => false

option :rackspace_servicelevel_wait,
:long => "--rackspace-servicelevel-wait",
:description => "Wait until the Rackspace service level automation setup is complete before bootstrapping chef",
:boolean => true,
:default => false

option :hint,
:long => "--hint HINT_NAME[=HINT_FILE]",
:description => "Specify Ohai Hint to be set on the bootstrap target. Use multiple --hint options to specify multiple hints.",
Expand Down Expand Up @@ -282,6 +294,9 @@ def run
node_name = get_node_name(config[:chef_node_name] || config[:server_name])
networks = get_networks(Chef::Config[:knife][:rackspace_networks])

rackconnect_wait = Chef::Config[:knife][:rackconnect_wait] || config[:rackconnect_wait]
rackspace_servicelevel_wait = Chef::Config[:knife][:rackspace_servicelevel_wait] || config[:rackspace_servicelevel_wait]

server = connection.servers.new(
:name => node_name,
:image_id => Chef::Config[:knife][:image],
Expand All @@ -298,6 +313,36 @@ def run
msg_pair("Name", server.name)
msg_pair("Flavor", server.flavor.name)
msg_pair("Image", server.image.name)
msg_pair("Metadata", server.metadata.all)
msg_pair("RackConnect Wait", rackconnect_wait ? 'yes' : 'no')
msg_pair("ServiceLevel Wait", rackspace_servicelevel_wait ? 'yes' : 'no')

# wait for it to be ready to do stuff
begin
server.wait_for(1200) {
print ".";
Chef::Log.debug("#{progress}%")
if rackconnect_wait and rackspace_servicelevel_wait
Chef::Log.debug("rackconnect_automation_status: #{metadata.all['rackconnect_automation_status']}")
Chef::Log.debug("rax_service_level_automation: #{metadata.all['rax_service_level_automation']}")
ready? and metadata.all['rackconnect_automation_status'] == 'DEPLOYED' and metadata.all['rax_service_level_automation'] == 'Complete'
elsif rackconnect_wait
Chef::Log.debug("rackconnect_automation_status: #{metadata.all['rackconnect_automation_status']}")
ready? and metadata.all['rackconnect_automation_status'] == 'DEPLOYED'
elsif rackspace_servicelevel_wait
Chef::Log.debug("rax_service_level_automation: #{metadata.all['rax_service_level_automation']}")
ready? and metadata.all['rax_service_level_automation'] == 'Complete'
else
ready?
end
}
rescue Fog::Errors::TimeoutError
ui.error('Timeout waiting for the server to be created')
msg_pair('Progress', "#{server.progress}%")
msg_pair('rackconnect_automation_status', server.metadata.all['rackconnect_automation_status'])
msg_pair('rax_service_level_automation', server.metadata.all['rax_service_level_automation'])
Chef::Application.fatal! 'Server didn\'t finish on time'
end
msg_pair("Metadata", server.metadata)
if(networks && Chef::Config[:knife][:rackspace_networks])
msg_pair("Networks", Chef::Config[:knife][:rackspace_networks].sort.join(', '))
Expand All @@ -314,6 +359,10 @@ def run
msg_pair("Public IP Address", public_ip(server))
msg_pair("Private IP Address", private_ip(server))
msg_pair("Password", server.password)
msg_pair("Metadata", server.metadata.all)

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

#which IP address to bootstrap
bootstrap_ip_address = public_ip(server)
if config[:private_network]
Expand Down