Permalink
Browse files

Better output, added wait between server builds per RAX best practices

  • Loading branch information...
1 parent cb686bf commit 87922cc51ad353c5a6caff16895f40a0cdd0c59d @madasi committed Apr 25, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 challenge1.py
View
@@ -26,14 +26,17 @@
import os
import pyrax
import threading
+import time
def server_done(server):
with threading.Semaphore() as s:
global completed
if server.status == 'ACTIVE':
inventory[server.name]["network"] = server.networks['public']
completed += 1
+ print "Server {0:s} is ready.".format(server.name)
else:
+ print "Something went wrong with server {0:s} so I'm building a replacement.".format(server.name)
del inventory[server.name]
server.delete()
replacement = cs.servers.create(server.name, centos63_image.id, flavor_512.id)
@@ -61,11 +64,11 @@ def server_done(server):
inventory[started.name] = {"password":started.adminPass,"name":started.name}
wait_thread = pyrax.utils.wait_until(started,"status",['ACTIVE','ERROR'],callback=server_done,interval=5,attempts=0,verbose=True,verbose_atts=["name","status"])
threads.append(wait_thread)
+ time.sleep(30) # Rackspace best practices to sleep between server creation
print "3 Servers are now building."
goal_reached.wait()
print "Your servers are ready!"
for server in inventory.values():
- print server
print "Server ", server["name"], "-- Password: ", server["password"], " -- Network: ", server["network"]
for thread in threads:
thread.join()

0 comments on commit 87922cc

Please sign in to comment.