Skip to content

Instantly share code, notes, and snippets.

@etoews
Last active February 6, 2018 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etoews/54919b33474aa6b13499 to your computer and use it in GitHub Desktop.
Save etoews/54919b33474aa6b13499 to your computer and use it in GitHub Desktop.
export OS_USERNAME=your-rackspace-username
export OS_PASSWORD=your-rackspace-password
mkdir openstack-sdk
cd openstack-sdk/
virtualenv -p python3 --no-site-packages venv
source venv/bin/activate
pip3 install openstacksdk
python3
import os
import sys
import requests
from openstack import connection
from openstack import profile
from openstack import utils
# utils.enable_logging(True, stream=sys.stdout)
requests.packages.urllib3.disable_warnings()
prof = profile.Profile()
prof.set_region(prof.ALL, "IAD")
conn = connection.Connection(
auth_url='https://identity.api.rackspacecloud.com/v2.0/',
profile=prof,
username=os.getenv("OS_USERNAME"),
password=os.getenv("OS_PASSWORD"))
key_name = 'python'
public_key = os.getenv("HOME") + '/.ssh/id_rsa.python.pub'
private_key = os.getenv("HOME") + '/.ssh/id_rsa.python'
kp = conn.compute.create_keypair(name=key_name)
with open(private_key, 'w') as f:
f.write("%s" % kp.private_key)
with open(public_key, 'w') as f:
f.write("%s" % kp.public_key)
os.chmod(private_key, 0o400)
os.chmod(public_key, 0o644)
for image in conn.compute.images():
print(image)
image = conn.compute.find_image("Ubuntu 15.04 (Vivid Vervet) (PVHVM)")
print("Image: %s" % image)
for flavor in conn.compute.flavors():
print(flavor)
flavor = conn.compute.find_flavor("general1-1")
print("Flavor: %s" % flavor)
server = conn.compute.create_server(
name="Python", key_name="python", image=image, flavor=flavor)
server = conn.compute.wait_for_server(server)
print("ssh -i %s root@%s" % (private_key, server['accessIPv4']))
# DELETE ALL UNUSED RESOURCES!!! (like the server you just created)
conn.compute.delete_server(server)
# You can also delete stuff from the Cloud Control Panel at https://mycloud.rackspace.com/
ssh -i ~/.ssh/id_rsa.python root@xxx.xxx.xxx.xxx
apt-get update
apt-get -y upgrade
apt-get -y install git python-pip python-virtualenv
apt-get -y install fail2ban
# Disable password login
sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
service ssh restart
virtualenv venv
source venv/bin/activate
git clone https://github.com/MDamien/legoit.git
cd legoit
pip install -r requirements.txt
python manage.py migrate
python manage.py retrieve_data
python manage.py runserver 0.0.0.0:8000
# open xxx.xxx.xxx.xxx:8000 in a web browser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment