Advertisement
Guest User

Untitled

a guest
Jul 6th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. # python libcloud_cloudlab_test.py <image-id> <flavor-id> <instance-name>
  2. #
  3. # python libcloud_cloudlab_test.py 91a3072b-c755-43e8-b8bc-b9cb62338ebf 2 lenardsagain
  4.  
  5. import os
  6. import sys
  7.  
  8. from libcloud.compute.types import Provider
  9. from libcloud.compute.providers import get_driver
  10. import libcloud.security
  11.  
  12. if len(sys.argv) < 4:
  13. sys.exit("missing expected arguments")
  14.  
  15. libcloud.security.VERIFY_SSL_CERT = False
  16.  
  17. # source the admin-openrc shell script to set environment variables
  18. auth_username = os.environ['OS_USERNAME']
  19. auth_password = os.environ['OS_PASSWORD']
  20. auth_url = os.environ['OS_AUTH_URL'] + '/tokens'
  21. project_name = os.environ['OS_TENANT_NAME']
  22.  
  23.  
  24. provider = get_driver(Provider.OPENSTACK)
  25. conn = provider(auth_username,
  26. auth_password,
  27. ex_force_auth_url=auth_url,
  28. ex_force_auth_version='2.0_password',
  29. ex_tenant_name=project_name,
  30. ex_project_name=project_name)
  31.  
  32. # Get the image that we want to use by its id
  33. # NOTE: the image_id may change. See the documentation to find
  34. # all the images available to your user
  35. image_id = sys.argv[1]
  36. image = conn.get_image(image_id)
  37.  
  38. # Get the flavor that we want to use by its id
  39. flavor_id = sys.argv[2]
  40. flavor = conn.ex_get_size(flavor_id)
  41.  
  42. #specify networks.
  43. nets = filter(lambda net: net.name == 'flat-lan-1-net', conn.ex_list_networks())
  44. network = [nets[0]]
  45.  
  46. instance = conn.create_node(name=sys.argv[3], image=image, size=flavor, networks=network)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement