You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. import getpass
  2. import libcloud.security
  3. from libcloud.compute.providers import get_driver
  4. from libcloud.compute.types import Provider
  5. auth_username = 'fdai109'
  6. auth_url = 'https://private-cloud2.informatik.hs-fulda.de:5000'
  7. project_name = 'ai-netlab-pro'
  8. region_name = 'RegionOne'
  9. domain_name = "hsfulda"
  10. ubuntu_image_name = "Ubuntu 14.04 - Trusty Tahr - 64-bit - Cloud Based Image"
  11. def main():
  12. print(auth_username)
  13. auth_password = getpass.getpass("Enter your OpenStack password:")
  14. # libcloud.security.VERIFY_SSL_CERT = False
  15. provider = get_driver(Provider.OPENSTACK)
  16. conn = provider(auth_username,
  17. auth_password,
  18. ex_force_auth_url=auth_url,
  19. ex_force_auth_version='3.x_password',
  20. ex_tenant_name=project_name,
  21. ex_force_service_region=region_name,
  22. ex_domain_name=domain_name)
  23. images = conn.list_images()
  24. image = ''
  25. for img in images:
  26. if img.name == ubuntu_image_name:
  27. image = img
  28. print(img)
  29. flavors = conn.list_sizes()
  30. for flavor in flavors:
  31. print(flavor)
  32. flavor_id = '2'
  33. flavor = conn.ex_get_size(flavor_id)
  34. print(flavor)
  35. networks = conn.ex_list_networks()
  36. network = ''
  37. for net in networks:
  38. if net.name == "ai-netlab-pro-net":
  39. network = net
  40. instance_name = 'testing'
  41. testing_instance = conn.create_node(name=instance_name, image=image, size=flavor, networks={network})
  42. print(testing_instance)
  43. instances = conn.list_nodes()
  44. for instance in instances:
  45. print(instance)
  46. conn.destroy_node(testing_instance)
  47. if __name__ == '__main__':
  48. main()