Skip to content

Instantly share code, notes, and snippets.

@EdLeafe
Created April 3, 2013 17:38
Show Gist options
  • Save EdLeafe/5303407 to your computer and use it in GitHub Desktop.
Save EdLeafe/5303407 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import threading
import time
import sys
import pyrax
pyrax.keyring_auth()
cs = pyrax.cloudservers
ubu1204 = "5cebb13a-f783-4f8c-8058-c4182c724ccd"
flavor512 = 2
server_data = {}
def cb(obj):
global server_data
oid = obj.id
server_data[oid]["status"] = obj.status
server_data[oid]["networks"] = obj.networks
server_data[oid]["build_finished"] = time.time()
def main(num):
global server_data
print "Creating servers",
for ii in xrange(num):
nm = "nserver_%s" % ii
server = cs.servers.create(nm, ubu1204, flavor512)
print ".",
sid = server.id
server_data[sid] = {}
server_data[sid]["name"] = server.name
server_data[sid]["adminPass"] = server.adminPass
server_data[sid]["build_started"] = time.time()
thread = pyrax.utils.wait_until(server, "status", ["ERROR", "ACTIVE"],
attempts=0, interval=15, callback=cb)
print
if __name__ == "__main__":
num = int(sys.argv[1])
start_count = threading.active_count()
main(num)
active = threading.active_count()
while active > start_count:
print "Remaining:", active - start_count
time.sleep(3)
active = threading.active_count()
with open("nserver results", "w") as f:
json.dump(server_data, f)
print "DUMPED"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment