Created
April 20, 2011 17:14
-
-
Save chmouel/932008 to your computer and use it in GitHub Desktop.
Create Cloud Server using novaclient library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
import novaclient | |
import sys | |
import time | |
# User Configuration | |
USERNAME="" | |
API_KEY="" | |
AUTH_URL="https://lon.auth.api.rackspacecloud.com/v1.0" | |
# Size of the servers, Flavour ID are : | |
# 1 -- 256 server | |
# 2 -- 512 server | |
# 3 -- 1GB server | |
# 4 -- 2GB server | |
# 5 -- 4GB server | |
# 6 -- 8GB server | |
# 7 -- 15.5GB server | |
FLAVOR_ID=3 | |
# IMAGE_ID the Operating System or image IDs are : | |
# 55 -- Arch 2010.05 | |
# 187811 -- CentOS 5.4 | |
# 51 -- CentOS 5.5 | |
# 4 -- Debian 5.0 (lenny -- | |
# 53 -- Fedora 13 (Goddard -- | |
# 71 -- Fedora 14 | |
# 19 -- Gentoo 10.1 | |
# 41 -- Oracle EL JeOS Release 5 Update 3 | |
# 40 -- Oracle EL Server Release 5 Update 4 | |
# 14 -- Red Hat Enterprise Linux 5.4 | |
# 62 -- Red Hat Enterprise Linux 5.5 | |
# 49 -- Ubuntu 10.04 LTS (lucid -- | |
# 69 -- Ubuntu 10.10 (maverick -- | |
# 10 -- Ubuntu 8.04.2 LTS (hardy -- | |
# 14362 -- Ubuntu 9.10 (karmic -- | |
# 23 -- Windows Server 2003 R2 SP2 x64 | |
# 29 -- Windows Server 2003 R2 SP2 x86 | |
# 28 -- Windows Server 2008 R2 x64 | |
# 58 -- Windows Server 2008 R2 x64 - MSSQL2K8R2 | |
# 24 -- Windows Server 2008 SP2 x64 | |
# 57 -- Windows Server 2008 SP2 x64 - MSSQL2K8R2 | |
# 31 -- Windows Server 2008 SP2 x86 | |
# 56 -- Windows Server 2008 SP2 x86 - MSSQL2K8R2 | |
IMAGE_ID=23 | |
# Set your server name here | |
SERVER_NAME="new_windows_001" | |
# Get connection | |
cnx = novaclient.OpenStack(USERNAME, API_KEY, auth_url=AUTH_URL) | |
# Create Server | |
server = cnx.servers.create( | |
image=IMAGE_ID, | |
flavor=FLAVOR_ID, | |
name=SERVER_NAME | |
) | |
server_id = server.id | |
# server password is only given at creation. | |
server_password = server.adminPass | |
# Request has been sent, now we are waiting until this is created | |
while cnx.servers.get(server_id).status != "ACTIVE": | |
status = cnx.servers.get(server_id).status | |
if status == "ACTIVE": | |
break | |
elif status == "ERROR": | |
print "We have an error while building which is unfortunate" + \ | |
", you may have to restart the process again and contact" + \ | |
" cloud support providing this id: %s" % (server_id) | |
sys.exit(1) | |
time.sleep(0.5) | |
# The servers is created we can get info about it now | |
server_created = cnx.servers.get(server_id) | |
print "Name: %s" % (server_created.name) | |
print "Admin Password: %s" % (server_password) | |
print "PublicIP: %s" % (server_created.public_ip) | |
print "PrivateIP: %s" % (server_created.private_ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment