def __init__()

in libcloud/compute/drivers/vsphere.py [0:0]


    def __init__(self, host, username, password, port=443, ca_cert=None):
        """Initialize a connection by providing a hostname,
        username and password
        """

        if pyvmomi is None:
            raise ImportError(
                'Missing "pyvmomi" dependency. '
                "You can install it "
                "using pip - pip install pyvmomi"
            )
        self.host = host
        try:
            if ca_cert is None:
                self.connection = connect.SmartConnect(
                    host=host,
                    port=port,
                    user=username,
                    pwd=password,
                )
            else:
                context = ssl.create_default_context(cafile=ca_cert)
                self.connection = connect.SmartConnect(
                    host=host,
                    port=port,
                    user=username,
                    pwd=password,
                    sslContext=context,
                )
            atexit.register(connect.Disconnect, self.connection)
        except Exception as exc:
            error_message = str(exc).lower()

            if "incorrect user name" in error_message:
                raise InvalidCredsError("Check your username and " "password are valid")

            if "connection refused" in error_message or "is not a vim server" in error_message:
                raise LibcloudError(
                    "Check that the host provided is a " "vSphere installation",
                    driver=self,
                )

            if "name or service not known" in error_message:
                raise LibcloudError("Check that the vSphere host is accessible", driver=self)

            if "certificate verify failed" in error_message:
                # bypass self signed certificates
                try:
                    context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
                    context.verify_mode = ssl.CERT_NONE
                except ImportError:
                    raise ImportError(
                        "To use self signed certificates, "
                        "please upgrade to python 2.7.11 and "
                        "pyvmomi 6.0.0+"
                    )

                self.connection = connect.SmartConnect(
                    host=host,
                    port=port,
                    user=username,
                    pwd=password,
                    sslContext=context,
                )
                atexit.register(connect.Disconnect, self.connection)
            else:
                raise LibcloudError("Cannot connect to vSphere", driver=self)