Skip to content

Instantly share code, notes, and snippets.

@EdLeafe
Created June 11, 2013 23:57
Show Gist options
  • Save EdLeafe/5761868 to your computer and use it in GitHub Desktop.
Save EdLeafe/5761868 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import pyrax
pyrax.keyring_auth()
cs = pyrax.cloudservers
keyfile = os.path.expanduser("~/.ssh/id_rsa.pub")
with open(keyfile, "rb") as ff:
keytext = ff.read()
flavors = cs.list_flavors()
images = cs.list_base_images()
images.sort(key=lambda x: x.name)
servers = []
for image in images:
available_flavors = [flavor for flavor in flavors
if flavor.disk >= image.minDisk
and flavor.ram >= image.minRam]
for flavor in available_flavors:
nm = "%s; %s" % (image.name, flavor.name)
print "Creating:", nm,
srv = cs.servers.create(nm, image=image.id, flavor=flavor.id,
files={"/root/.ssh/authorized_keys": keytext})
print srv.id, "Admin Pass", srv.adminPass
servers.append(srv)
for server in servers:
print server.name, server.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment