Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #!/usr/bin/python2.7
  2.  
  3. import ssl
  4. import requests
  5. import pprint
  6.  
  7. from pyVim.connect import SmartConnect, Disconnect
  8. from pyVmomi import vim, vmodl
  9.  
  10. # Disabling urllib3 ssl warnings
  11. requests.packages.urllib3.disable_warnings()
  12.  
  13. # Disabling SSL certificate verification
  14. context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
  15. context.verify_mode = ssl.CERT_NONE
  16.  
  17. vc = None
  18.  
  19. #vCenter settings
  20. vcenter_host = "10.10.0.7"
  21. vcenter_port = 443
  22. vcenter_username = "administrator@kippie.lab"
  23. vcenter_password = "Q!w2e3r4"
  24.  
  25. # Connecting to vCenter
  26. try:
  27. vc = SmartConnect(host=vcenter_host, user=vcenter_username, pwd=vcenter_password, port=vcenter_port, sslContext=context)
  28. content= vc.RetrieveContent()
  29. List = content.customizationSpecManager
  30.  
  31. viewMgr = content.viewManager
  32. objView = viewMgr.CreateContainerView(content.rootFolder,[vim.VirtualMachine],True)
  33. collector = vc.content.propertyCollector
  34.  
  35. obj_spec = vmodl.query.PropertyCollector.ObjectSpec()
  36. obj_spec.obj=objView
  37. obj_spec.skip=True
  38.  
  39. traversal_spec = vmodl.query.PropertyCollector.TraversalSpec()
  40. traversal_spec.name = 'traverseEntities'
  41. traversal_spec.path = 'view'
  42. traversal_spec.skip = False
  43. traversal_spec.type = vim.ContainerView
  44.  
  45. obj_spec.selectSet.append(traversal_spec)
  46.  
  47. property_spec = vmodl.query.PropertyCollector.PropertySpec()
  48. property_spec.type = vim.HbrManager.ReplicationVmInfo
  49. property_spec.pathSet.extend(['state'])
  50.  
  51. filter_spec = vmodl.query.PropertyCollector.FilterSpec()
  52. filter_spec.objectSet.append(obj_spec)
  53. filter_spec.propSet.append(property_spec)
  54.  
  55. props = collector.RetrieveContents([filter_spec])
  56. pprint(props)
  57.  
  58. except IOError as e:
  59. print "I/O error({0}): {1}".format(e.errno, e.strerror)
  60.  
  61. Traceback (most recent call last):
  62. File "./vcConnect2.py", line 65, in <module>
  63.  
  64. File "/usr/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 570, in <lambda>
  65. self.f(*(self.args + (obj,) + args), **kwargs)
  66. File "/usr/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 376, in _InvokeMethod
  67. return self._stub.InvokeMethod(self, info, args)
  68. File "/usr/lib/python2.7/site-packages/pyVmomi/SoapAdapter.py", line 1335, in InvokeMethod
  69. raise obj # pylint: disable-msg=E0702
  70. pyVmomi.VmomiSupport.InvalidType: (vmodl.fault.InvalidType) {
  71. dynamicType = <unset>,
  72. dynamicProperty = (vmodl.DynamicProperty) [],
  73. msg = 'The request refers to an unexpected or unknown type.',
  74. faultCause = <unset>,
  75. faultMessage = (vmodl.LocalizableMessage) [],
  76. argument = u'vim.HbrManager.ReplicationVmInfo'
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement