コード例 #1
0
ファイル: tosession.py プロジェクト: zds05/trafficcontrol
    def login(self, username, password):
        """
		Login to the Traffic Ops API.
		:param username: Traffic Ops User Name
		:type username: Text
		:param password: Traffic Ops User Password
		:type password: Text
		:return: None
		:rtype: None
		:raises: trafficops.restapi.LoginError
		"""
        logging.info("Connecting to Traffic Ops at %s...", self.to_url)

        if not self.is_open:
            self.create()

        logging.info("Connected. Authenticating...")

        self._logged_in = False
        try:
            # Try to login to Traffic Ops
            self.post(u'user/login', data={u'u': username, u'p': password})
            self._logged_in = True
        except rex.SSLError as e:
            logging.debug("%s", e, stack_info=True, exc_info=True)
            self.close()
            msg = (
                u'{0}.  This system may have a self-signed certificate.  Try creating this TOSession '
                u'object passing verify_cert=False. e.g. TOSession(..., verify_cert=False). '
            )
            msg = msg.format(e)
            logging.error(msg)
            logging.warning(
                "disabling certificate verification is not recommended.")
            raise restapi.LoginError(msg) from e
        except restapi.OperationError as e:
            logging.debug("%s", e, exc_info=True, stack_info=True)
            msg = u'Logging in to Traffic Ops has failed. Reason: {0}'.format(
                e)
            self.close()
            logging.error(msg)
            raise restapi.OperationError(msg) from e

        logging.info("Authenticated.")
コード例 #2
0
    def login(self, username, password):
        """
        Login to the Traffic Ops API.
        :param username: Traffic Ops User Name
        :type username: Text
        :param password: Traffic Ops User Password
        :type password: Text
        :return: None
        :rtype: None
        :raises: trafficops.restapi.LoginError
        """

        if not self.is_open:
            self.create()

        self._logged_in = False
        try:
            # Try to login to Traffic Ops
            self.post(u'user/login', data={u'u': username, u'p': password})
            self._logged_in = True
        except rex.SSLError as e:
            self.close()
            msg = (
                u'{0}.  This system may have a self-signed certificate.  Try creating this TOSession '
                u'object passing verify_cert=False. e.g. TOSession(..., verify_cert=False). '
                u'WARNING: disabling certificate verification is not recommended.'
            )
            msg = msg.format(e)
            utils.log_with_debug_info(logging.ERROR, msg)
            raise restapi.LoginError(msg)
        except restapi.OperationError as e:
            msg = u'Logging in to Traffic Ops has failed. Reason: {0}'
            msg = msg.format(e)
            self.close()
            utils.log_with_debug_info(logging.ERROR, msg)
            raise restapi.OperationError(msg)