コード例 #1
0
ファイル: easy_client.py プロジェクト: kancowitz/brewtils
    def find_unique_request(self, **kwargs):
        """Find a unique request

        .. note::
            If 'id' is a given keyword argument then all other parameters will
            be ignored.

        Args:
            **kwargs: Search parameters

        Returns:
            Request, None: The Request if found, None otherwise

        Raises:
            FetchError: More than one matching Request was found

        """
        if "id" in kwargs:
            return self._find_request_by_id(kwargs.pop("id"))
        else:
            all_requests = self.find_requests(**kwargs)

            if not all_requests:
                return None

            if len(all_requests) > 1:
                raise FetchError("More than one matching Request found")

            return all_requests[0]
コード例 #2
0
ファイル: easy_client.py プロジェクト: kancowitz/brewtils
    def find_unique_system(self, **kwargs):
        """Find a unique system

        .. note::
            If 'id' is a given keyword argument then all other parameters will
            be ignored.

        Args:
            **kwargs: Search parameters

        Returns:
            System, None: The System if found, None otherwise

        Raises:
            FetchError: More than one matching System was found

        """
        if "id" in kwargs:
            return self._find_system_by_id(kwargs.pop("id"), **kwargs)
        else:
            systems = self.find_systems(**kwargs)

            if not systems:
                return None

            if len(systems) > 1:
                raise FetchError("More than one matching System found")

            return systems[0]
コード例 #3
0
ファイル: system_client.py プロジェクト: hazmat345/brewtils
    def load_bg_system(self):
        """Query beer-garden for a System definition

        This method will make the query to beer-garden for a System matching the name and version
        constraints specified during SystemClient instance creation.

        If this method completes successfully the SystemClient will be ready to create and send
        Requests.

        :raise FetchError: If unable to find a matching System
        :return: None
        """

        if self._version_constraint == 'latest':
            systems = self._easy_client.find_systems(name=self._system_name)
            self._system = sorted(systems,
                                  key=lambda x: x.version,
                                  reverse=True)[0] if systems else None
        else:
            self._system = self._easy_client.find_unique_system(
                name=self._system_name, version=self._version_constraint)

        if self._system is None:
            raise FetchError(
                "Beer-garden has no system named '%s' with a version matching '%s'"
                % (self._system_name, self._version_constraint))

        self._commands = {
            command.name: command
            for command in self._system.commands
        }
        self._loaded = True
コード例 #4
0
ファイル: easy_client.py プロジェクト: hazmat345/brewtils
    def remove_system(self, **kwargs):
        """Remove a specific system by DELETEing, using keyword arguments as search parameters

        :param kwargs: Search parameters
        :return: The response
        """
        system = self.find_unique_system(**kwargs)

        if system is None:
            raise FetchError(
                "Could not find system matching the given search parameters")

        return self._remove_system_by_id(system.id)
コード例 #5
0
ファイル: easy_client.py プロジェクト: kancowitz/brewtils
    def remove_system(self, **kwargs):
        """Remove a unique System

        Args:
            **kwargs: Search parameters

        Returns:
            bool: True if removal was successful

        Raises:
            FetchError: Couldn't find a System matching given parameters

        """
        system = self.find_unique_system(**kwargs)

        if system is None:
            raise FetchError("No matching System found")

        return self._remove_system_by_id(system.id)
コード例 #6
0
ファイル: system_client.py プロジェクト: beer-garden/brewtils
    def load_bg_system(self):
        # type: () -> None
        """Query beer-garden for a System definition

        This method will make the query to beer-garden for a System matching the name
        and version constraints specified during SystemClient instance creation.

        If this method completes successfully the SystemClient will be ready to create
        and send Requests.

        Returns:
            None

        Raises:
            FetchError: Unable to find a matching System
        """

        if self._version_constraint == "latest":
            self._system = self._determine_latest(
                self._easy_client.find_systems(
                    name=self._system_name, namespace=self._system_namespace))
        else:
            self._system = self._easy_client.find_unique_system(
                name=self._system_name,
                version=self._version_constraint,
                namespace=self._system_namespace,
            )

        if self._system is None:
            raise FetchError(
                "Beer-garden has no system named '%s' with a version matching '%s' in "
                "namespace '%s'" % (
                    self._system_name,
                    self._version_constraint,
                    self._system_namespace
                    if self._system_namespace else "<garden default>",
                ))

        self._commands = {
            command.name: command
            for command in self._system.commands
        }
        self._loaded = True
コード例 #7
0
ファイル: easy_client.py プロジェクト: hazmat345/brewtils
    def find_unique_system(self, **kwargs):
        """Find a unique system using keyword arguments as search parameters

        :param kwargs: Search parameters
        :return: One system instance
        """
        if 'id' in kwargs:
            return self._find_system_by_id(kwargs.pop('id'), **kwargs)
        else:
            systems = self.find_systems(**kwargs)

            if not systems:
                return None

            if len(systems) > 1:
                raise FetchError(
                    "More than one system found that specifies the given constraints"
                )

            return systems[0]
コード例 #8
0
ファイル: easy_client.py プロジェクト: hazmat345/brewtils
    def find_unique_request(self, **kwargs):
        """Find a unique request using keyword arguments as search parameters

        .. note::
            If 'id' is present in kwargs then all other parameters will be ignored.

        :param kwargs: Search parameters
        :return: One request instance
        """
        if 'id' in kwargs:
            return self._find_request_by_id(kwargs.pop('id'))
        else:
            requests = self.find_requests(**kwargs)

            if not requests:
                return None

            if len(requests) > 1:
                raise FetchError("More than one request found that specifies "
                                 "the given constraints")

            return requests[0]