Exemplo n.º 1
0
    def remove_label(self, name, silent_failure=False):
        """Remove label by name.
        :var: name: name of label
        :var: silent_failure: whether to raise an error or not in case of failure.

        Returns:
            :py:type:`bool` pass or fail
        Raises:
            :py:class:`LabelNotFoundException`.
        """
        json_content = self._get_json()
        if name not in json_content['metadata'].get('labels', {}).keys():
            failure_signature = 'Could not find label "{}", labels: {}' \
                .format(name, json_content['metadata']['labels'])
            if silent_failure:
                logger.warning(failure_signature)
                return False
            else:
                raise exceptions.LabelNotFoundException(failure_signature)
        self.provider.cli.run_command(
            'oc label {} {} {}-'.format(
                self._cli_resource_type,
                ('sha256:{}'.format(self.sha256)
                 if (self.__class__.__name__ == 'Image') else self.name),
                name
            )
        )
        return True
Exemplo n.º 2
0
    def remove_label(self, name, silent_failure=False):
        """Remove label by name.
        :var: name: name of label
        :var: silent_failure: whether to raise an error or not in case of failure.

        Returns:
            :py:type:`bool` pass or fail
        Raises:
            :py:class:`LabelNotFoundException`.
        """
        try:
            self.mgmt.delete_label(name)
            return True
        except Exception:  # TODO: add appropriate exception in wrapanapi
            failure_signature = format_exc()
            if silent_failure:
                logger.warning(failure_signature)
                return False
            raise exceptions.LabelNotFoundException(failure_signature)