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
2.9 KiB

6 years ago
6 years ago
6 years ago
  1. import getpass
  2. import json
  3. import os
  4. import libcloud
  5. import libcloud.security
  6. import requests
  7. from libcloud.storage.providers import get_driver
  8. from libcloud.storage.types import Provider
  9. # HS-Fulda Private Cloud
  10. auth_url = 'https://192.168.72.40:5000'
  11. region_name = 'RegionOne'
  12. domain_name = "hsfulda"
  13. api_ip = '192.168.72.102'
  14. def main():
  15. ###########################################################################
  16. #
  17. # get credentials
  18. #
  19. ###########################################################################
  20. if "OS_PROJECT_NAME" in os.environ:
  21. project_name = os.environ["OS_PROJECT_NAME"]
  22. else:
  23. project_name = eval(input("Enter your OpenStack project:"))
  24. if "OS_USERNAME" in os.environ:
  25. auth_username = os.environ["OS_USERNAME"]
  26. else:
  27. auth_username = eval(input("Enter your OpenStack username:"))
  28. if "OS_PASSWORD" in os.environ:
  29. auth_password = os.environ["OS_PASSWORD"]
  30. else:
  31. auth_password = getpass.getpass("Enter your OpenStack password:")
  32. ###########################################################################
  33. #
  34. # create connection
  35. #
  36. ###########################################################################
  37. libcloud.security.VERIFY_SSL_CERT = False
  38. provider = get_driver(Provider.OPENSTACK_SWIFT)
  39. swift = provider(auth_username,
  40. auth_password,
  41. ex_force_auth_url=auth_url,
  42. ex_force_auth_version='3.x_password',
  43. ex_tenant_name=project_name,
  44. ex_force_service_region=region_name,
  45. ex_domain_name=domain_name)
  46. ###########################################################################
  47. #
  48. # create container
  49. #
  50. ###########################################################################
  51. container_name = 'fractals'
  52. containers = swift.list_containers()
  53. container = False
  54. for con in containers:
  55. if con.name == container_name:
  56. container = con
  57. if not container:
  58. container = swift.create_container(container_name=container_name)
  59. print(container)
  60. ###########################################################################
  61. #
  62. # backup existing fractals to container
  63. #
  64. ###########################################################################
  65. endpoint = 'http://' + api_ip
  66. params = { 'results_per_page': '-1' }
  67. response = requests.get('%s/v1/fractal' % endpoint, params=params)
  68. data = json.loads(response.text)
  69. for fractal in data['objects']:
  70. response = requests.get('%s/fractal/%s' % (endpoint, fractal['uuid']), stream=True)
  71. container.upload_object_via_stream(response.iter_content(), object_name=fractal['uuid'])
  72. for object_data in container.list_objects():
  73. print(object_data)
  74. if __name__ == '__main__':
  75. main()