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.

97 lines
3.5 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-29 for X in the following variable to specify your group number. (will be used for the username,
  11. # project etc., as coordinated in the lab sessions)
  12. group_number = 30
  13. # web service endpoint of the private cloud infrastructure
  14. auth_url = 'https://private-cloud.informatik.hs-fulda.de:5000'
  15. # your username in OpenStack
  16. auth_username = 'CloudComp' + str(group_number)
  17. # your project in OpenStack
  18. project_name = 'CloudComp' + str(group_number)
  19. # default region
  20. region_name = 'RegionOne'
  21. # domain to use, "default" for local accounts, "hsfulda" for RZ LDAP, e.g., using fdaiXXXX as auth_username
  22. domain_name = "default"
  23. def main():
  24. ###########################################################################
  25. #
  26. # get credentials
  27. #
  28. ###########################################################################
  29. # if "OS_PASSWORD" in os.environ:
  30. # auth_password = os.environ["OS_PASSWORD"]
  31. # else:
  32. # auth_password = getpass.getpass("Enter your OpenStack password:")
  33. auth_password = "demo"
  34. ###########################################################################
  35. #
  36. # create connection
  37. #
  38. ###########################################################################
  39. # libcloud.security.VERIFY_SSL_CERT = False
  40. provider = get_driver(Provider.OPENSTACK)
  41. conn = provider(auth_username,
  42. auth_password,
  43. ex_force_auth_url=auth_url,
  44. ex_force_auth_version='3.x_password',
  45. ex_tenant_name=project_name,
  46. ex_force_service_region=region_name,
  47. ex_domain_name=domain_name)
  48. ###########################################################################
  49. #
  50. # clean up resources from previous demos
  51. #
  52. ###########################################################################
  53. # destroy running demo instances
  54. for instance in conn.list_nodes():
  55. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
  56. 'app-services', 'app-api-1', 'app-api-2']:
  57. print('Destroying Instance: %s' % instance.name)
  58. conn.destroy_node(instance)
  59. # wait until all nodes are destroyed to be able to remove depended security groups
  60. nodes_still_running = True
  61. while nodes_still_running:
  62. nodes_still_running = False
  63. time.sleep(3)
  64. instances = conn.list_nodes()
  65. for instance in instances:
  66. # if we see any demo instances still running continue to wait for them to stop
  67. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
  68. 'app-services', 'app-api-1', 'app-api-2']:
  69. nodes_still_running = True
  70. print('There are still instances running, waiting for them to be destroyed...')
  71. # delete security groups
  72. for group in conn.ex_list_security_groups():
  73. if group.name in ['control', 'worker', 'api', 'services']:
  74. print('Deleting security group: %s' % group.name)
  75. conn.ex_delete_security_group(group)
  76. if __name__ == '__main__':
  77. main()