Check vm available prior to bootstrapping

This commit is contained in:
bwhipple 2013-09-28 17:35:54 -05:00 коммит произвёл adamedx
Родитель 56f4c3163a
Коммит 3293fb6bf9
2 изменённых файлов: 54 добавлений и 17 удалений

Просмотреть файл

@ -95,6 +95,12 @@ class Azure
end
def delete(rolename)
end
def queryDeploy(hostedservicename)
deploy = Deploy.new(@connection)
deploy.retrieve(hostedservicename)
deploy
end
end
class Deploy

Просмотреть файл

@ -215,6 +215,36 @@ class Chef
(0...len).map{65.+(rand(25)).chr}.join
end
def wait_until_virtual_machine_ready()
print "\n#{ui.color("Waiting for virtual machine to be ready.", :magenta)}"
vm_ready = false
for i in 0..29
vm_ready = check_if_virtual_machine_ready()
break if vm_ready
print "."
sleep 30
end
if vm_ready
puts("vm ready.")
else
raise "Virtual machine not ready after 15 minutes."
end
end
def check_if_virtual_machine_ready()
deploy = connection.deploys.queryDeploy(locate_config_value(:azure_dns_name))
role = deploy.find_role(locate_config_value(:azure_vm_name))
if role.nil?
raise "Could not find role - status unknown."
end
Chef::Log.debug("Role status is #{role.status.to_s}")
if "ReadyRole".eql? role.status.to_s
return true
else
return false
end
end
def tcp_test_winrm(ip_addr, port)
hostname = ip_addr
socket = TCPSocket.new(hostname, port)
@ -300,53 +330,54 @@ class Chef
begin
server = connection.deploys.create(create_server_def)
fqdn = server.publicipaddress
wait_until_virtual_machine_ready()
rescue Exception => e
Chef::Log.Error("Exception being rescued: #{e.to_s}")
cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
end
puts("\n")
if is_image_windows?
# Set distro to windows-chef-client-msi
config[:distro] = "windows-chef-client-msi" if (config[:distro].nil? || config[:distro] == "chef-full")
if locate_config_value(:bootstrap_protocol) == 'ssh'
port = server.sshport
print "\n#{ui.color("Waiting for sshd on #{fqdn}:#{port}", :magenta)}"
print "#{ui.color("Waiting for sshd on #{fqdn}:#{port}", :magenta)}"
print(".") until tcp_test_ssh(fqdn,port) {
sleep @initial_sleep_delay ||= 10
puts("done")
}
}
elsif locate_config_value(:bootstrap_protocol) == 'winrm'
port = server.winrmport
print "\n#{ui.color("Waiting for winrm on #{fqdn}:#{port}", :magenta)}"
print "#{ui.color("Waiting for winrm on #{fqdn}:#{port}", :magenta)}"
print(".") until tcp_test_winrm(fqdn,port) {
sleep @initial_sleep_delay ||= 10
puts("done")
}
}
end
sleep 15
puts("\n")
bootstrap_for_windows_node(server,fqdn, port).run
else
unless server && server.publicipaddress && server.sshport
Chef::Log.fatal("server not created")
exit 1
end
exit 1
end
port = server.sshport
port = server.sshport
print "\n#{ui.color("Waiting for sshd on #{fqdn}:#{port}", :magenta)}"
print "#{ui.color("Waiting for sshd on #{fqdn}:#{port}", :magenta)}"
print(".") until tcp_test_ssh(fqdn,port) {
sleep @initial_sleep_delay ||= 10
puts("done")
}
print(".") until tcp_test_ssh(fqdn,port) {
sleep @initial_sleep_delay ||= 10
puts("done")
}
sleep 15
puts("\n")
bootstrap_for_node(server,fqdn,port).run
end
end
@ -552,4 +583,4 @@ class Chef
end
end
end
end