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.

100 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 = "CloudCompGrpX-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. auth_password = "demo"
  37. ###########################################################################
  38. #
  39. # create connection
  40. #
  41. ###########################################################################
  42. # libcloud.security.VERIFY_SSL_CERT = False
  43. provider = get_driver(Provider.OPENSTACK)
  44. conn = provider(auth_username,
  45. auth_password,
  46. ex_force_auth_url=auth_url,
  47. ex_force_auth_version='3.x_password',
  48. ex_tenant_name=project_name,
  49. ex_force_service_region=region_name,
  50. ex_domain_name=domain_name)
  51. ###########################################################################
  52. #
  53. # clean up resources from previous demos
  54. #
  55. ###########################################################################
  56. # destroy running demo instances
  57. for instance in conn.list_nodes():
  58. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-worker-3', 'app-controller',
  59. 'app-services', 'app-api-1', 'app-api-2']:
  60. print('Destroying Instance: %s' % instance.name)
  61. conn.destroy_node(instance)
  62. # wait until all nodes are destroyed to be able to remove depended security groups
  63. nodes_still_running = True
  64. while nodes_still_running:
  65. nodes_still_running = False
  66. time.sleep(3)
  67. instances = conn.list_nodes()
  68. for instance in instances:
  69. # if we see any demo instances still running continue to wait for them to stop
  70. if instance.name in ['all-in-one', 'app-worker-1', 'app-worker-2', 'app-controller']:
  71. nodes_still_running = True
  72. print('There are still instances running, waiting for them to be destroyed...')
  73. # delete security groups
  74. for group in conn.ex_list_security_groups():
  75. if group.name in ['control', 'worker', 'api', 'services']:
  76. print('Deleting security group: %s' % group.name)
  77. conn.ex_delete_security_group(group)
  78. if __name__ == '__main__':
  79. main()