コード例 #1
0
ファイル: ucssession.py プロジェクト: kraz4glf/ucsmsdk
    def __validate_connection(self):
        """
        Internal method to validate if needs to reconnect or if exist use the
        existing connection.
        """

        from mometa.top.TopSystem import TopSystem
        from ucsmethodfactory import config_resolve_dn

        if self.__cookie is not None and self.__cookie != "":
            if not self.__force:
                top_system = TopSystem()
                elem = config_resolve_dn(cookie=self.__cookie,
                                            dn=top_system.dn)
                response = self.post_elem(elem)
                if response.error_code != 0:
                    raise UcsException(response.error_code,
                                       response.error_descr)
                return True
            else:
                self._logout()
        return False
コード例 #2
0
ファイル: ucssession.py プロジェクト: kraz4glf/ucsmsdk
    def _login(self, auto_refresh=False, force=False):
        """
        Internal method responsible to do a login on UCSM server.

        Args:
            auto_refresh (bool): if set to True, it refresh the cookie
                                    continuously
            force (bool): if set to True it reconnects even if cookie exists
                                    and is valid for respective connection.

        Returns:
            True on successful connect
        """

        from mometa.top.TopSystem import TopSystem
        from mometa.firmware.FirmwareRunning import FirmwareRunning, \
            FirmwareRunningConsts
        from ucscoremeta import UcsVersion
        from ucsmethodfactory import aaa_login
        from ucsmethodfactory import config_resolve_class
        from ucsmethodfactory import config_resolve_dn

        if self.__validate_connection():
            return True

        elem = aaa_login(in_name=self.__username,
                            in_password=self.__password)
        response = self.post_elem(elem)
        if response.error_code != 0:
            self.__clear()
            raise UcsException(response.error_code, response.error_descr)
        self.__update(response)

        # Verify not to connect to IMC
        nw_elem = config_resolve_class(cookie=self.__cookie,
                                          in_filter=None,
                                          class_id="networkElement")
        nw_elem_response = self.post_elem(nw_elem)
        # To Do - returns error tag
        if nw_elem_response.error_code != 0:
            self.__clear()
            return False

        top_system = TopSystem()
        if response.out_version is None or response.out_version == "":
            firmware = FirmwareRunning(top_system,
                                       FirmwareRunningConsts.DEPLOYMENT_SYSTEM)
            elem = config_resolve_dn(cookie=self.__cookie,
                                        dn=firmware.dn)
            response = self.post_elem(elem)
            if response.error_code != 0:
                raise UcsException(response.error_code,
                                   response.error_descr)
            firmware = response.out_config.child[0]
            self._version = UcsVersion(firmware.version)

        top_system = TopSystem()
        elem = config_resolve_dn(cookie=self.__cookie, dn=top_system.dn)
        response = self.post_elem(elem)
        if response.error_code != 0:
            raise UcsException(response.error_code, response.error_descr)
        top_system = response.out_config.child[0]
        self._ucs = top_system.name
        self.__virtual_ipv4_address = top_system.address

        if auto_refresh:
            self.__start_refresh_timer()

        return True