class ConfigurationDiagnosticPage(Buffer):
    def _calc_num_type_descriptor_headers(self):
        return sum(desc.type_descriptor_headers_num for desc in self.enclosure_descriptor_list)

    def _unpack_type_descriptor_text(self, buffer, index, **kwargs):
        l = self.type_descriptor_header_list[index].type_descriptor_text_length
        return buffer[0:l].to_bytes(), l

    page_code = be_int_field(where=bytes_ref[0])
    secondary_subenclosures_num = be_int_field(where=bytes_ref[1])
    page_length = be_int_field(where=bytes_ref[2:4], set_before_pack=total_size - 4)
    generation_code = be_int_field(where=bytes_ref[4:8])
    enclosure_descriptor_list = list_field(type=EnclosureDescriptor,
                                           where=bytes_ref[8:],
                                           n=secondary_subenclosures_num + 1)
    type_descriptor_header_list = list_field(where=bytes_ref[after_ref(enclosure_descriptor_list):],
                                             type=TypeDescriptorHeader,
                                             n=member_func_ref(_calc_num_type_descriptor_headers))
    type_descriptor_text_list = list_field(where=bytes_ref[after_ref(type_descriptor_header_list):],
                                           type=str_type,
                                           unpack_selector=_unpack_type_descriptor_text,
                                           n=member_func_ref(_calc_num_type_descriptor_headers))

    def _calc_num_type_descriptor_headers(self):
        return sum(o.type_descriptor_headers_num for o in self.enclosure_descriptor_list)
class ElementDescriptor(Buffer):
    def _possible_elements_num(self):
        return self.type_descriptor_header.possible_elements_num

    overall_element = buffer_field(where=bytes_ref[0:], type=Descriptor)
    individual_elements = list_field(where=bytes_ref[after_ref(overall_element):], type=Descriptor,
                                     n=member_func_ref(_possible_elements_num))

    def unpack(self, buffer, type_descriptor_header):
        self.type_descriptor_header = type_descriptor_header
        return super(ElementDescriptor, self).unpack(buffer)
class ElementDescriptorDiagnosticPagesData(DiagnosticDataBuffer):
    def _unpack_status_descriptor(self, buffer, index, **kwargs):
        descriptor = ElementDescriptor()
        bytes = descriptor.unpack(buffer, self.conf_page.type_descriptor_header_list[index])
        return descriptor, bytes

    def _possible_elements_num(self):
        return len(self.conf_page.type_descriptor_header_list)

    page_code = be_int_field(where=bytes_ref[0])
    page_length = be_int_field(where=bytes_ref[2:4])
    generation_code = be_int_field(where=bytes_ref[4:8])
    element_descriptors = list_field(where=bytes_ref[8:], type=ElementDescriptor,
                                     unpack_selector=_unpack_status_descriptor,
                                     n=member_func_ref(_possible_elements_num))
Exemple #4
0
class StatusDescriptor(Buffer):
    def _unpack_status_element(self, buffer, index, **kwargs):
        elem_type = self.type_descriptor_header.element_type
        if elem_type in ELEMENT_TYPE_TO_ELEMENT_INFO:
            return ELEMENT_TYPE_TO_ELEMENT_INFO[elem_type]
        else:
            return GeneralStatusElement

    def _possible_elements_num(self):
        return self.type_descriptor_header.possible_elements_num

    overall_element = buffer_field(where=bytes_ref[0:4],
                                   type=GeneralStatusElement)
    individual_elements = list_field(where=bytes_ref[4:],
                                     type=GeneralStatusElement,
                                     unpack_selector=_unpack_status_element,
                                     n=member_func_ref(_possible_elements_num))

    def unpack(self, buffer, type_descriptor_header):
        self.type_descriptor_header = type_descriptor_header
        return super(StatusDescriptor, self).unpack(buffer)
Exemple #5
0
class EnclosureStatusDiagnosticPagesData(DiagnosticDataBuffer):
    def _unpack_status_descriptor(self, buffer, index, **kwargs):
        descriptor = StatusDescriptor()
        bytes = descriptor.unpack(
            buffer, self.conf_page.type_descriptor_header_list[index])
        return descriptor, bytes

    def _possible_elements_num(self):
        return len(self.conf_page.type_descriptor_header_list)

    page_code = be_int_field(where=bytes_ref[0])
    unrecov = be_int_field(where=bytes_ref[1].bits[0])
    crit = be_int_field(where=bytes_ref[1].bits[1])
    non_crit = be_int_field(where=bytes_ref[1].bits[2])
    info = be_int_field(where=bytes_ref[1].bits[3])
    invop = be_int_field(where=bytes_ref[1].bits[4])
    page_length = be_int_field(where=bytes_ref[2:4])
    generation_code = be_int_field(where=bytes_ref[4:8])
    status_descriptors = list_field(where=bytes_ref[8:],
                                    type=StatusDescriptor,
                                    unpack_selector=_unpack_status_descriptor,
                                    n=member_func_ref(_possible_elements_num))