How to access and use the OpenStack based Switch Engine IaaS?
OpenStack is a free open standard cloud computing platform, mostly deployed as infrastructure-as-a-service (IaaS) in both public and private clouds. In this course, we will use the OpenStack based SwitchEngine IaaS
Account creation
- Join one of the groups on this link. Please take note that you cannot be more than 5 members in the same group.
- Wait for the invitation voucher you will receive by email
- Once you receive your email voucher, click the link and follow the instructions on the web page.
- Create your Keystone API credentials https://help.switch.ch/engines/faq/how-to-create-api-credentials/
- Store the password you created above.
Create an instance on SwitchEngine
The following tutorial will guide you through the creation of your first instance on an OpenStack based IaaS:
https://docs.openstack.org/horizon/latest/user/launch-instances.html
As for SwitchEngine, the following tutorial will guide you through the creation of your first instance:
https://help.switch.ch/engines/documentation/start-virtual-machines/
Note: Do not create an instance using the "Create instance" button on the QuickStart page.
Setting up a local dev. environment
-
Install the OpenStack Python SDK
https://docs.openstack.org/openstacksdk/latest/user/index.html
-
The URL below explains how to connect to Switch Engine using OpenStack SDK. 3 options of connection are possible:
https://docs.openstack.org/openstacksdk/latest/user/guides/connect_from_config.html
-
We will use the config file option. Switch Engine provides you with a pre-filled config file. Download your pre-filled clouds.yaml config file and put it in your project folder. (Connect on Switch Engine before clicking the link below)
https://engines.switch.ch/horizon/project/api_access/clouds.yaml
- Download the following file, and change the $API_KEY_INPUT for the credential you got from step 4 of the Account Creation
https://engines.switch.ch/horizon/project/api_access/openrc/ - Run the following command:
source <Name of the file downloaded in the previous step> - Open the clouds.yaml file and add your password between the username and the project_id lines, and put as a password the credentials you got from step 4 of Account Creation
...
username: "<FIRSTNAME.LASTNAME@etu.hesge.ch>"
password: <YOUR_PASSWORD>
project_id: <PROJECT_ID>
...
Be sure that the clouds.yaml is either in the folder where you have the code or on ~/.config/openstack/
Resources and code examples
Creation of an instance
def create_server(conn):
print("Create Server:")
image = conn.compute.find_image(IMAGE_NAME)
flavor = conn.compute.find_flavor(FLAVOR_NAME)
network = conn.network.find_network(NETWORK_NAME)
keypair = create_keypair(conn)
server = conn.compute.create_server(
name=SERVER_NAME, image_id=image.id, flavor_id=flavor.id,
networks=[{"uuid": network.id}], key_name=keypair.name)
server = conn.compute.wait_for_server(server)
print("ssh -i {key} root@{ip}".format(
key=PRIVATE_KEYPAIR_FILE,
ip=server.access_ipv4))
Get the status of an instance
def list_servers(conn):
print("List Servers:")
for server in conn.compute.servers():
print(server)
deletion of an instance
conn.compute.servers.delete(server.id)
More Information
OpenStack Python SDK documentation
https://docs.openstack.org/openstacksdk/latest/user/index.html
API Documentation
https://docs.openstack.org/openstacksdk/latest/user/index.html#api-documentation
Code examples
https://docs.openstack.org/openstacksdk/latest/user/guides/compute.html
If you have any questions, please contact francisco(dot)mendonca(at)hesge(dot)ch