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.

98 lines
3.4 KiB

  1. import getpass
  2. import os
  3. #import libcloud.security
  4. import time
  5. from libcloud.compute.providers import get_driver
  6. from libcloud.compute.types import Provider
  7. # reqs:
  8. # services: nova, glance, neutron
  9. # resources: 2 instances (m1.small), 2 floating ips (1 keypair, 2 security groups)
  10. # Please use 1-25 for X in username, project etc., as coordinated in the lab sessions
  11. # web service endpoint of the private cloud infrastructure
  12. auth_url = 'https://private-cloud2.informatik.hs-fulda.de:5000'
  13. # your username in OpenStack
  14. auth_username = 'CloudCompX'
  15. # your project in OpenStack
  16. project_name = 'CloudCompGrpX'
  17. # default region
  18. region_name = 'RegionOne'
  19. # domain to use, "default" for local accounts, "hsfulda" for LDAP of DVZ, e.g., using fdaiXXXX as auth_username
  20. domain_name = "default"
  21. ubuntu_image_name = "Ubuntu 14.04 - Trusty Tahr - 64-bit - Cloud Based Image"
  22. flavor_name = 'm1.small'
  23. network_name = "CloudCompX-net"
  24. keypair_name = 'srieger-pub'
  25. pub_key_file = '~/.ssh/id_rsa.pub'
  26. def main():
  27. ###########################################################################
  28. #
  29. # get credentials
  30. #
  31. ###########################################################################
  32. if "OS_PASSWORD" in os.environ:
  33. auth_password = os.environ["OS_PASSWORD"]
  34. else:
  35. auth_password = getpass.getpass("Enter your OpenStack password:")
  36. ###########################################################################
  37. #
  38. # create connection
  39. #
  40. ###########################################################################
  41. #libcloud.security.VERIFY_SSL_CERT = False
  42. provider = get_driver(Provider.OPENSTACK)
  43. conn = provider(auth_username,
  44. auth_password,
  45. ex_force_auth_url=auth_url,
  46. ex_force_auth_version='3.x_password',
  47. ex_tenant_name=project_name,
  48. ex_force_service_region=region_name,
  49. ex_domain_name=domain_name)
  50. ###########################################################################
  51. #
  52. # clean up resources from previous demos
  53. #
  54. ###########################################################################
  55. # destroy running demo instances
  56. for instance in conn.list_nodes():
  57. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
  58. 'app-services', 'app-api-1', 'app-api-2']:
  59. print('Destroying Instance: %s' % instance.name)
  60. conn.destroy_node(instance)
  61. # wait until all nodes are destroyed to be able to remove depended security groups
  62. nodes_still_running = True
  63. while nodes_still_running:
  64. nodes_still_running = False
  65. time.sleep(3)
  66. instances = conn.list_nodes()
  67. for instance in instances:
  68. # if we see any demo instances still running continue to wait for them to stop
  69. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-controller']:
  70. nodes_still_running = True
  71. print('There are still instances running, waiting for them to be destroyed...')
  72. # delete security groups
  73. for group in conn.ex_list_security_groups():
  74. if group.name in ['control', 'worker', 'api', 'services']:
  75. print('Deleting security group: %s' % group.name)
  76. conn.ex_delete_security_group(group)
  77. if __name__ == '__main__':
  78. main()