コード例 #1
0
    def refresh(self):
        """Refresh the Task

        Freshly retrieves/fetches the Task.
        :raises: ResourceNotFoundError
        :raises: ConnectionError
        :raises: HTTPError
        """
        self._response = self._connector.get(path=self.task_monitor_uri)

        if self._response.status_code == http_client.ACCEPTED:
            # A Task should have been returned, but wasn't
            if not self._response.content:
                self._task = None
                return

            # Assume that the body contains a Task since we got a 202
            if not self._task:
                self._task = task.Task(self._connector,
                                       self._task_monitor_uri,
                                       redfish_version=self._redfish_version,
                                       registries=self._registries,
                                       json_doc=self._response.json())
            else:
                self._task.refresh(json_doc=self._response.json())
        else:
            self._task = None
コード例 #2
0
ファイル: taskmonitor.py プロジェクト: sapcc/sushy
    def refresh(self):
        """Refresh the Task

        Freshly retrieves/fetches the Task.
        :raises: ResourceNotFoundError
        :raises: ConnectionError
        :raises: HTTPError
        """
        self._field_data = self._reader.get_data()

        if self._field_data.status_code == http_client.ACCEPTED:
            # A Task should have been returned, but wasn't
            if int(self._field_data.headers.get('Content-Length')) == 0:
                self._task = None
                return

            # Assume that the body contains a Task since we got a 202
            if not self._task:
                self._task = task.Task(self._connector,
                                       self._task_monitor,
                                       redfish_version=self._redfish_version,
                                       registries=self._registries,
                                       json_doc=self._field_data.json_doc)
            else:
                self._task.refresh(json_doc=self._field_data.json_doc)
        else:
            self._task = None
コード例 #3
0
    def get_task(self):
        """Construct Task instance from task monitor URI.

        :returns: Task instance.
        """
        return task.Task(self._connector,
                         self._task_monitor_uri,
                         redfish_version=self._redfish_version,
                         registries=self._registries)
コード例 #4
0
    def __init__(self,
                 connector,
                 task_monitor_uri,
                 redfish_version=None,
                 registries=None,
                 field_data=None,
                 response=None):
        """A class representing a task monitor

        :param connector: A Connector instance
        :param task_monitor_uri: The task monitor URI
        :param redfish_version: The version of Redfish. Used to construct
            the object according to schema of the given version.
        :param registries: Dict of Redfish Message Registry objects to be
            used in any resource that needs registries to parse messages.
        :param field_data: the data to use populating the fields. Deprecated
            use response.
        :param response: Raw response
        """
        self._connector = connector
        self._task_monitor_uri = task_monitor_uri
        self._redfish_version = redfish_version
        self._registries = registries
        self._field_data = field_data
        if self._field_data is not None:
            LOG.warning('TaskMonitor field_data is deprecated in TaskMonitor. '
                        'Use response.')
        self._task = None
        self._response = response

        # Backward compability for deprecated field_data
        if self._field_data and not self._response:
            self._response = requests.Response()
            self._response.status_code = self._field_data.status_code
            self._response.headers = self._field_data.headers
            self._response._content = json.dumps(
                self._field_data.json_doc).encode('utf-8')

        if (self._response and self._response.content
                and self._response.status_code == http_client.ACCEPTED):
            self._task = task.Task(self._connector,
                                   self._task_monitor_uri,
                                   redfish_version=self._redfish_version,
                                   registries=self._registries,
                                   json_doc=self._response.json())
        else:
            self.refresh()
コード例 #5
0
    def setUp(self):
        super(TaskTestCase, self).setUp()
        self.conn = mock.Mock()
        with open('sushy/tests/unit/json_samples/task.json') as f:
            self.json_doc = json.load(f)

        self.conn.get.return_value.json.return_value = self.json_doc

        message_registry = mock.Mock()
        message = mock.Mock()
        message.message = "Property %1 is read only."
        message.number_of_args = 1
        message_registry.messages = {"PropertyNotWriteable": message}

        self.task = task.Task(
            self.conn, '/redfish/v1/TaskService/Tasks/545',
            redfish_version='1.4.3',
            registries={'Base.1.0': message_registry})
コード例 #6
0
ファイル: taskmonitor.py プロジェクト: sapcc/sushy
    def __init__(self,
                 connector,
                 task_monitor,
                 redfish_version=None,
                 registries=None,
                 field_data=None):
        """A class representing a task monitor

        :param connector: A Connector instance
        :param task_monitor: The task monitor
        :param retry_after: The amount of time to wait in seconds before
            calling is_processing.
        :param redfish_version: The version of RedFish. Used to construct
            the object according to schema of the given version.
        :param registries: Dict of Redfish Message Registry objects to be
            used in any resource that needs registries to parse messages.
        """
        self._connector = connector
        self._task_monitor = task_monitor
        self._redfish_version = redfish_version
        self._registries = registries
        self._field_data = field_data
        self._reader = base.get_reader(connector, task_monitor)
        self._task = None

        if self._field_data:
            # If a body was returned, assume it's a Task on a 202 status code
            content_length = int(
                self._field_data.headers.get('Content-Length'))
            if (self._field_data.status_code == http_client.ACCEPTED
                    and content_length > 0):
                self._task = task.Task(self._connector,
                                       self._task_monitor,
                                       redfish_version=self._redfish_version,
                                       registries=self._registries,
                                       json_doc=self._field_data.json_doc)
        else:
            self.refresh()
コード例 #7
0
ファイル: taskmonitor.py プロジェクト: sapcc/sushy
 def get_task(self):
     return task.Task(self._connector,
                      self._task_monitor,
                      redfish_version=self._redfish_version,
                      registries=self._registries)