Permalink
Browse files

Working challenge 1 with wait for active code loop

  • Loading branch information...
1 parent aa212e1 commit c8c311866c5d5fd52f48c3307a162771add88693 @madasi committed Apr 10, 2013
Showing with 18 additions and 6 deletions.
  1. +18 −6 challenge1.py
View
@@ -25,20 +25,32 @@
import os
import pyrax
+import time
pyrax.set_credential_file(os.path.expanduser('~/.rackspace_cloud_credentials'))
cs = pyrax.cloudservers
name = "dev_{0:02d}"
-my_image = [img for img in cs.images.list()
+centos63_image = [img for img in cs.images.list()
if "CentOS 6.3" in img.name][0]
flavor_512 = [flavor for flavor in cs.flavors.list()
if flavor.ram == 512][0]
my_servers=[]
for i in range(1,4):
servername = name.format(i)
- my_servers.append(cs.servers.create(servername, my_image.id, flavor_512.id))
-
+ my_servers.append(cs.servers.create(servername, centos63_image.id, flavor_512.id))
+ time.sleep(30) # Rackspace best practices to sleep between server creation
+completed = []
+while len(completed) < 3:
+ for server in my_servers:
+ if server in completed:
+ continue
+ server.get()
+ if server.status == 'ACTIVE':
+ completed.append(server)
+ elif server.status == 'ERROR':
+ server.delete()
+ my_servers.remove(server)
+ my_servers.append(cs.servers.create(server.name, centos63_image.id, flavor_512.id))
+ time.sleep(30)
for server in my_servers:
- print "Server ", server.name, " -- Password: ", server.adminPass, " -- Network: ", server.networks
-
-
+ print "Server ", server.name, " -- Password: ", server.adminPass, " -- Network: ", server.networks['public']

0 comments on commit c8c3118

Please sign in to comment.