Guest User

Untitled

a guest
Nov 14th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Pyvcloud Examples
  3. #
  4. # Copyright (c) 2017-2018 VMware, Inc. All Rights Reserved.
  5. #
  6. # This product is licensed to you under the
  7. # Apache License, Version 2.0 (the "License").
  8. # You may not use this product except in compliance with the License.
  9. #
  10. # This product may include a number of subcomponents with
  11. # separate copyright notices and license terms. Your use of the source
  12. # code for the these subcomponents is subject to the terms and
  13. # conditions of the subcomponent's license, as noted in the LICENSE file.
  14. #
  15. # Illustrates how to list all vApps within a single vDC.
  16.  
  17. import sys
  18. import os
  19. from pyvcloud.vcd.client import BasicLoginCredentials
  20. from pyvcloud.vcd.client import Client
  21. from pyvcloud.vcd.client import EntityType
  22. from pyvcloud.vcd.org import Org
  23. from pyvcloud.vcd.vdc import VDC
  24. import requests
  25.  
  26. # Collect arguments.
  27. # if len(sys.argv) != 6:
  28. # print("Usage: python3 {0} host org user password vdc".format(sys.argv[0]))
  29. # sys.exit(1)
  30. host = os.environ.get("VCD_HOST") or sys.argv[1]
  31. org = os.environ.get("VCD_ORG") or sys.argv[2]
  32. user = os.environ.get("VCD_USER") or sys.argv[3]
  33. password = os.environ.get("VCD_PASSWORD") or sys.argv[4]
  34. vdc = os.environ.get("VCD_VDC") or sys.argv[5]
  35.  
  36. # Disable warnings from self-signed certificates.
  37. requests.packages.urllib3.disable_warnings()
  38.  
  39. # Login. SSL certificate verification is turned off to allow self-signed
  40. # certificates. You should only do this in trusted environments.
  41. print("Logging in: host={0}, org={1}, user={2}".format(host, org, user))
  42. client = Client(host,
  43. api_version='29.0',
  44. verify_ssl_certs=False,
  45. log_file='pyvcloud.log',
  46. log_requests=True,
  47. log_headers=True,
  48. log_bodies=True)
  49. client.set_credentials(BasicLoginCredentials(user, org, password))
  50.  
  51. print("Fetching Org...")
  52. org_resource = client.get_org()
  53. org = Org(client, resource=org_resource)
  54.  
  55. print("Fetching VDC...")
  56. vdc_resource = org.get_vdc(vdc)
  57. vdc = VDC(client, resource=vdc_resource)
  58. print("Fetching vApps....")
  59. vapps = vdc.list_resources(EntityType.VAPP)
  60. for vapp in vapps:
  61. print("VAPP:", vapp.get('name'))
  62.  
  63. for gw in vdc.list_edge_gateways():
  64. print("EdgeGW:", gw.get('name'))
  65.  
  66. # Log out.
  67. print("Logging out")
  68. client.logout()
Add Comment
Please, Sign In to add comment