Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # python libcloud_cloudlab_test.py <image-id> <flavor-id> <instance-name>
- #
- # python libcloud_cloudlab_test.py 91a3072b-c755-43e8-b8bc-b9cb62338ebf 2 lenardsagain
- import os
- import sys
- from libcloud.compute.types import Provider
- from libcloud.compute.providers import get_driver
- import libcloud.security
- if len(sys.argv) < 4:
- sys.exit("missing expected arguments")
- libcloud.security.VERIFY_SSL_CERT = False
- # source the admin-openrc shell script to set environment variables
- auth_username = os.environ['OS_USERNAME']
- auth_password = os.environ['OS_PASSWORD']
- auth_url = os.environ['OS_AUTH_URL'] + '/tokens'
- project_name = os.environ['OS_TENANT_NAME']
- provider = get_driver(Provider.OPENSTACK)
- conn = provider(auth_username,
- auth_password,
- ex_force_auth_url=auth_url,
- ex_force_auth_version='2.0_password',
- ex_tenant_name=project_name,
- ex_project_name=project_name)
- # Get the image that we want to use by its id
- # NOTE: the image_id may change. See the documentation to find
- # all the images available to your user
- image_id = sys.argv[1]
- image = conn.get_image(image_id)
- # Get the flavor that we want to use by its id
- flavor_id = sys.argv[2]
- flavor = conn.ex_get_size(flavor_id)
- #specify networks.
- nets = filter(lambda net: net.name == 'flat-lan-1-net', conn.ex_list_networks())
- network = [nets[0]]
- instance = conn.create_node(name=sys.argv[3], image=image, size=flavor, networks=network)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement