Ejemplo n.º 1
0
Archivo: mib.py Proyecto: W4lken/snimpy
    def type(self):
        """Get the basic type associated with this node.

        :return: The class from :mod:`basictypes` module which can
            represent the node. When retrieving a valid value for
            this node, the returned class can be instanciated to get
            an appropriate representation.
        """
        from snimpy import basictypes

        if self._override_type:
            t = self._override_type
        else:
            t = _smi.smiGetNodeType(self.node)
        target = {
            _smi.SMI_BASETYPE_INTEGER32: basictypes.Integer,
            _smi.SMI_BASETYPE_INTEGER64: basictypes.Integer,
            _smi.SMI_BASETYPE_UNSIGNED32: {b"TimeTicks": basictypes.Timeticks, None: basictypes.Unsigned32},
            _smi.SMI_BASETYPE_UNSIGNED64: basictypes.Unsigned64,
            _smi.SMI_BASETYPE_OCTETSTRING: {b"IpAddress": basictypes.IpAddress, None: basictypes.OctetString},
            _smi.SMI_BASETYPE_OBJECTIDENTIFIER: basictypes.Oid,
            _smi.SMI_BASETYPE_ENUM: {b"TruthValue": basictypes.Boolean, None: basictypes.Enum},
            _smi.SMI_BASETYPE_BITS: basictypes.Bits,
        }.get(t.basetype, None)
        if isinstance(target, dict):
            tt = _smi.smiGetParentType(t)
            target = target.get(
                (t.name != ffi.NULL and ffi.string(t.name)) or (tt.name != ffi.NULL and ffi.string(tt.name)) or None,
                target.get(None, None),
            )

        if target is None:
            raise SMIException("unable to retrieve type of node")
        return target
Ejemplo n.º 2
0
Archivo: mib.py Proyecto: W4lken/snimpy
    def fmt(self):
        """Get node format. The node format is a string to use to display
        a user-friendly version of the node. This is can be used for
        both octet strings or integers (to make them appear as decimal
        numbers).

        :return: The node format as a string or None if there is no
            format available.

        """
        if self._override_type:
            t = self._override_type
        else:
            t = _smi.smiGetNodeType(self.node)
        tt = _smi.smiGetParentType(t)
        f = (
            t != ffi.NULL
            and t.format != ffi.NULL
            and ffi.string(t.format)
            or tt != ffi.NULL
            and tt.format != ffi.NULL
            and ffi.string(tt.format)
        ) or None
        if f is None:
            return None
        return f.decode("ascii")
Ejemplo n.º 3
0
    def type(self):
        """Get the basic type associated with this node.

        :return: The class from :mod:`basictypes` module which can
            represent the node. When retrieving a valid value for
            this node, the returned class can be instanciated to get
            an appropriate representation.
        """
        from snimpy import basictypes
        if self._override_type:
            t = self._override_type
        else:
            t = _smi.smiGetNodeType(self.node)
        if t == ffi.NULL:
            raise SMIException("unable to retrieve type of node")
        target = {
            _smi.SMI_BASETYPE_INTEGER32: basictypes.Integer,
            _smi.SMI_BASETYPE_INTEGER64: basictypes.Integer,
            _smi.SMI_BASETYPE_UNSIGNED32: {
                b"TimeTicks": basictypes.Timeticks,
                None: basictypes.Unsigned32
            },
            _smi.SMI_BASETYPE_UNSIGNED64: basictypes.Unsigned64,
            _smi.SMI_BASETYPE_OCTETSTRING: {
                b"IpAddress": basictypes.IpAddress,
                None: basictypes.OctetString
            },
            _smi.SMI_BASETYPE_OBJECTIDENTIFIER: basictypes.Oid,
            _smi.SMI_BASETYPE_ENUM: {
                b"TruthValue": basictypes.Boolean,
                None: basictypes.Enum
            },
            _smi.SMI_BASETYPE_BITS: basictypes.Bits
        }.get(t.basetype, None)
        if isinstance(target, dict):
            tt = _smi.smiGetParentType(t)
            target = target.get(
                (t.name != ffi.NULL and ffi.string(t.name))
                or (tt.name != ffi.NULL and ffi.string(tt.name)) or None,
                target.get(None, None))

        if target is None:
            raise SMIException("unable to retrieve type of node")
        return target
Ejemplo n.º 4
0
Archivo: mib.py Proyecto: W4lken/snimpy
    def typeName(self):
        """Retrieves the name of the the node's current declared type
        (not basic type).

        :return: A string representing the current declared type,
            suitable for assignment to type.setter.
        """
        if self._override_type:
            t = self._override_type
        else:
            t = _smi.smiGetNodeType(self.node)

        # This occurs when the type is "implied".
        if t.name == ffi.NULL:
            t = _smi.smiGetParentType(t)

        if t is None or t == ffi.NULL:
            raise SMIException("unable to retrieve the declared type " "of the node '{}'".format(self.node.name))

        return ffi.string(t.name)
Ejemplo n.º 5
0
    def fmt(self):
        """Get node format. The node format is a string to use to display
        a user-friendly version of the node. This is can be used for
        both octet strings or integers (to make them appear as decimal
        numbers).

        :return: The node format as a string or None if there is no
            format available.

        """
        if self._override_type:
            t = self._override_type
        else:
            t = _smi.smiGetNodeType(self.node)
        tt = _smi.smiGetParentType(t)
        f = (t != ffi.NULL and t.format != ffi.NULL and ffi.string(t.format)
             or tt != ffi.NULL and tt.format != ffi.NULL
             and ffi.string(tt.format)) or None
        if f is None:
            return None
        return f.decode("ascii")
Ejemplo n.º 6
0
    def typeName(self):
        """Retrieves the name of the the node's current declared type
        (not basic type).

        :return: A string representing the current declared type,
            suitable for assignment to type.setter.
        """
        if self._override_type:
            t = self._override_type
        else:
            t = _smi.smiGetNodeType(self.node)

        # This occurs when the type is "implied".
        if t.name == ffi.NULL:
            t = _smi.smiGetParentType(t)

        if t is None or t == ffi.NULL:
            raise SMIException("unable to retrieve the declared type "
                               "of the node '{0}'".format(self.node.name))

        return ffi.string(t.name)