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.

102 lines
3.6 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. #ubuntu_image_name = "Ubuntu 18.04 - Bionic Beaver - 64-bit - Cloud Based Image"
  23. flavor_name = 'm1.small'
  24. network_name = "CloudCompGrpX-net"
  25. keypair_name = 'srieger-pub'
  26. pub_key_file = '~/.ssh/id_rsa.pub'
  27. def main():
  28. ###########################################################################
  29. #
  30. # get credentials
  31. #
  32. ###########################################################################
  33. # if "OS_PASSWORD" in os.environ:
  34. # auth_password = os.environ["OS_PASSWORD"]
  35. # else:
  36. # auth_password = getpass.getpass("Enter your OpenStack password:")
  37. auth_password = "demo"
  38. ###########################################################################
  39. #
  40. # create connection
  41. #
  42. ###########################################################################
  43. # libcloud.security.VERIFY_SSL_CERT = False
  44. provider = get_driver(Provider.OPENSTACK)
  45. conn = provider(auth_username,
  46. auth_password,
  47. ex_force_auth_url=auth_url,
  48. ex_force_auth_version='3.x_password',
  49. ex_tenant_name=project_name,
  50. ex_force_service_region=region_name,
  51. ex_domain_name=domain_name)
  52. ###########################################################################
  53. #
  54. # clean up resources from previous demos
  55. #
  56. ###########################################################################
  57. # destroy running demo instances
  58. for instance in conn.list_nodes():
  59. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
  60. 'app-services', 'app-api-1', 'app-api-2']:
  61. print('Destroying Instance: %s' % instance.name)
  62. conn.destroy_node(instance)
  63. # wait until all nodes are destroyed to be able to remove depended security groups
  64. nodes_still_running = True
  65. while nodes_still_running:
  66. nodes_still_running = False
  67. time.sleep(3)
  68. instances = conn.list_nodes()
  69. for instance in instances:
  70. # if we see any demo instances still running continue to wait for them to stop
  71. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
  72. 'app-services', 'app-api-1', 'app-api-2']:
  73. nodes_still_running = True
  74. print('There are still instances running, waiting for them to be destroyed...')
  75. # delete security groups
  76. for group in conn.ex_list_security_groups():
  77. if group.name in ['control', 'worker', 'api', 'services']:
  78. print('Deleting security group: %s' % group.name)
  79. conn.ex_delete_security_group(group)
  80. if __name__ == '__main__':
  81. main()