コード例 #1
0
    def _create_config_item(self, resource_type, obj):
        """Create an API resource object and handle exceptions.

        This is a factory method to create resource objects in
        such a way that any exceptions that are raised might
        be handled and the appropriate F5CcclConfigurationReadError.

        :param resource_type: The type of resource to create.
        :param obj: The configuration object.
        :returns: A resource object.
        :rtype: f5_cccl.resource.Resource
        :raises:  f5_cccl.exceptions.F5CcclConfigurationReadError
        """
        config_resource = None
        try:
            config_resource = resource_type(partition=self._partition, **obj)
        except (ValueError, TypeError) as error:
            msg_format = \
                "Failed to create resource {}, {} from config: error({})"
            msg = msg_format.format(obj.get('name'), resource_type.__name__,
                                    str(error))
            LOGGER.error(msg)
            raise cccl_error.F5CcclConfigurationReadError(msg)

        return config_resource
コード例 #2
0
    def _create_config_item(self,
                            resource_type,
                            obj,
                            default_route_domain=None,
                            user_agent=None):
        """Create an API resource object and handle exceptions.

        This is a factory method to create resource objects in
        such a way that any exceptions that are raised might
        be handled and the appropriate F5CcclConfigurationReadError.

        :param resource_type: The type of resource to create.
        :param obj: The configuration object.
        :returns: A resource object.
        :rtype: f5_cccl.resource.Resource
        :raises:  f5_cccl.exceptions.F5CcclConfigurationReadError
        """
        config_resource = None

        # Update the object with metadata
        if user_agent is not None:

            metadata = {
                'metadata': [{
                    'name': 'user_agent',
                    'persist': 'true',
                    'value': user_agent
                }]
            }
            obj.update(metadata)

        try:
            if default_route_domain is not None:
                config_resource = resource_type(
                    partition=self._partition,
                    default_route_domain=default_route_domain,
                    **obj)
            else:
                config_resource = resource_type(partition=self._partition,
                                                **obj)
        except (ValueError, TypeError) as error:
            msg_format = \
                "Failed to create resource {}, {} from config: error({})"
            msg = msg_format.format(obj.get('name'), resource_type.__name__,
                                    str(error))
            LOGGER.error(msg)
            raise cccl_error.F5CcclConfigurationReadError(msg)

        return config_resource
コード例 #3
0
 def f():
     raise exceptions.F5CcclConfigurationReadError()