Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Copyright 2016 Michael Rice <michael@michaelrice.org>
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15.  
  16. from __future__ import print_function
  17. import os
  18. import ssl
  19. import sys
  20. import requests
  21.  
  22. # This is where VMWare keeps the pyVmomi and other libraries
  23. sys.path.extend(os.environ['VMWARE_PYTHON_PATH'].split(';'))
  24.  
  25. from pyVim import connect
  26. from pyVmomi import vim
  27. requests.packages.urllib3.disable_warnings()
  28. # this is to ignore SSL verification which is helpful for self signed certs
  29. try:
  30. _create_unverified_https_context = ssl._create_unverified_context
  31. except AttributeError:
  32. # Legacy Python that doesn't verify HTTPS certificates by default
  33. pass
  34. else:
  35. # Handle target environment that doesn't support HTTPS verification
  36. ssl._create_default_https_context = _create_unverified_https_context
  37. USER_NAME = "YOUR USER"
  38. PASSWORD = "YOUR PASS"
  39. HOST = "YOUR HOST"
  40. PORT = "443"
  41. service_instance = connect.SmartConnect(host=HOST,
  42. user=USER_NAME,
  43. pwd=PASSWORD,
  44. port=int(PORT))
  45.  
  46. root_folder = service_instance.content.rootFolder
  47. # again crude example here. use the logging module instead
  48. with open("/var/log/my_script_log_file.txt", 'a') as f:
  49. print(root_folder.name, file=f)
  50. for var, val in os.environ.items():
  51. # When an alarm is triggered and run a lot of environment variables are set.
  52. # This will list them all with their values.
  53. if var.startswith("VMWARE_ALARM"):
  54. print("{} = {}".format(var, val), file=f)
  55. print("##########", file=f)
  56. connect.Disconnect(service_instance)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement