Hello everybody nowadays I interest with ESX and WMware virtualization system. Pyvmomi is such a good Api that control all of them. It’s Python project also well documented on Github.
There is a good samples for lazy peoples who want to understand easily and faster.
Main problem, while connecting vSphere it forces to use SSL . While working on GUI it’s easy to ignore it, but on console you have to add some Python command to beginning of script.
If you get this error or different which is occur because of SSL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Traceback (most recent call last): File "hello_world_vcenter.py", line 117, in <module> main() File "hello_world_vcenter.py", line 92, in main port=int(args.port)) File "/usr/local/lib/python2.7/dist-packages/pyVim/connect.py", line 575, in SmartConnect preferredApiVersions) File "/usr/local/lib/python2.7/dist-packages/pyVim/connect.py", line 518, in __FindSupportedVersion path) File "/usr/local/lib/python2.7/dist-packages/pyVim/connect.py", line 432, in __GetServiceVersionDescription with closing(urllib.urlopen(url)) as sock: File "/usr/lib/python2.7/urllib.py", line 87, in urlopen return opener.open(url) File "/usr/lib/python2.7/urllib.py", line 213, in open return getattr(self, name)(url) File "/usr/lib/python2.7/urllib.py", line 443, in open_https h.endheaders(data) File "/usr/lib/python2.7/httplib.py", line 997, in endheaders self._send_output(message_body) File "/usr/lib/python2.7/httplib.py", line 850, in _send_output self.send(msg) File "/usr/lib/python2.7/httplib.py", line 812, in send self.connect() File "/usr/lib/python2.7/httplib.py", line 1212, in connect server_hostname=server_hostname) File "/usr/lib/python2.7/ssl.py", line 350, in wrap_socket _context=self) File "/usr/lib/python2.7/ssl.py", line 566, in __init__ self.do_handshake() File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake self._sslobj.do_handshake() IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581) |
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import requests requests.packages.urllib3.disable_warnings() import ssl try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: # Legacy Python that doesn't verify HTTPS certificates by default pass else: # Handle target environment that doesn't support HTTPS verification ssl._create_default_https_context = _create_unverified_https_context |
Few links for more
https://gist.github.com/michaelrice/a6794a017e349fc65d01
Note: python2.7