Пример #1
0
    @staticmethod
    def recv(conn):
        msg = conn.recv()
        packet = msg.payload
        hdr = _genl_hdr_parse(packet[:4])

        genlmsg = GeNlMessage(msg.type, hdr.cmd, [], msg.flags)
        genlmsg.attrs = parse_attributes(packet[4:])
        genlmsg.version = hdr.version

        return genlmsg


class Controller:
    def __init__(self, conn):
        self.conn = conn

    def get_family_id(self, family):
        a = NulStrAttr(CTRL_ATTR_FAMILY_NAME, family)
        m = GeNlMessage(GENL_ID_CTRL,
                        CTRL_CMD_GETFAMILY,
                        flags=NLM_F_REQUEST,
                        attrs=[a])
        m.send(self.conn)
        m = GeNlMessage.recv(self.conn)
        return m.attrs[CTRL_ATTR_FAMILY_ID].u16()


connection = Connection(NETLINK_GENERIC)
controller = Controller(connection)
Пример #2
0
 def __init__(self, options):
     self.options = options
     self.connection = Connection(NETLINK_GENERIC)
     controller = Controller(self.connection)
     self.family_id = controller.get_family_id('TASKSTATS')
Пример #3
0
class TaskStatHelper(object):
    connection = Connection(NETLINK_GENERIC)
    controller = Controller(connection)
    family_id = controller.get_family_id('TASKSTATS')