mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-26 01:37:04 +00:00
Merge pull request #248 from carlroth/roth_onlp
Python bindings for libonlp
This commit is contained in:
@@ -26,6 +26,12 @@ packages:
|
||||
builds/onlp-platform/$BUILD_DIR/${TOOLCHAIN}/bin/libonlp-platform.so : $libdir/
|
||||
builds/onlp-platform-defaults/$BUILD_DIR/${TOOLCHAIN}/bin/libonlp-platform-defaults.so : $libdir/
|
||||
builds/onlpd/$BUILD_DIR/${TOOLCHAIN}/bin/onlpd : $bindir/
|
||||
${ONL}/packages/base/any/onlp/src/onlpdump.py: $bindir/
|
||||
${ONL}/packages/base/any/onlp/src/onlp/module/python/onlp/__init__.py: ${PY_INSTALL}/onlp/
|
||||
${ONL}/packages/base/any/onlp/src/onlp/module/python/onlp/onlp: ${PY_INSTALL}/onlp/onlp
|
||||
${ONL}/packages/base/any/onlp/src/onlp/module/python/onlp/test: ${PY_INSTALL}/onlp/test
|
||||
${ONL}/packages/base/any/onlp/src/onlplib/module/python/onlp/onlplib: ${PY_INSTALL}/onlp/onlplib
|
||||
${ONL}/packages/base/any/onlp/src/sff/module/python/onlp/sff: ${PY_INSTALL}/onlp/sff
|
||||
|
||||
init: $ONL/packages/base/any/onlp/src/onlpd.init
|
||||
|
||||
|
||||
@@ -24,5 +24,5 @@
|
||||
############################################################
|
||||
|
||||
onlp_AUTO_DEFS := module/auto/onlp.yml
|
||||
onlp_AUTO_DIRS := module/inc/onlp module/src module/py
|
||||
onlp_AUTO_DIRS := module/inc/onlp module/src module/python/onlp/onlp
|
||||
include $(BUILDER)/auto.mk
|
||||
|
||||
@@ -109,6 +109,17 @@ oid_types: &oid_types
|
||||
- MODULE : 6
|
||||
- RTC : 7
|
||||
|
||||
# OID dump options
|
||||
oid_dump: &oid_dump
|
||||
- RECURSE
|
||||
- EVEN_IF_ABSENT
|
||||
|
||||
# OID show options
|
||||
oid_show: &oid_show
|
||||
- RECURSE
|
||||
- EXTENDED
|
||||
- YAML
|
||||
|
||||
# SFP Control
|
||||
sfp_control: &sfp_control
|
||||
- RESET
|
||||
@@ -255,6 +266,14 @@ definitions:
|
||||
onlp_oid_type:
|
||||
tag: oid
|
||||
members: *oid_types
|
||||
onlp_oid_show:
|
||||
tag: oid
|
||||
members: *oid_show
|
||||
flags: True
|
||||
onlp_oid_dump:
|
||||
tag: oid
|
||||
members: *oid_dump
|
||||
flags: True
|
||||
onlp_thermal_status:
|
||||
tag: thermal
|
||||
members: *thermal_status
|
||||
|
||||
@@ -47,6 +47,19 @@
|
||||
typedef uint32_t onlp_oid_t;
|
||||
|
||||
/* <auto.start.enum(tag:oid).define> */
|
||||
/** onlp_oid_dump */
|
||||
typedef enum onlp_oid_dump_e {
|
||||
ONLP_OID_DUMP_RECURSE = (1 << 0),
|
||||
ONLP_OID_DUMP_EVEN_IF_ABSENT = (1 << 1),
|
||||
} onlp_oid_dump_t;
|
||||
|
||||
/** onlp_oid_show */
|
||||
typedef enum onlp_oid_show_e {
|
||||
ONLP_OID_SHOW_RECURSE = (1 << 0),
|
||||
ONLP_OID_SHOW_EXTENDED = (1 << 1),
|
||||
ONLP_OID_SHOW_YAML = (1 << 2),
|
||||
} onlp_oid_show_t;
|
||||
|
||||
/** onlp_oid_type */
|
||||
typedef enum onlp_oid_type_e {
|
||||
ONLP_OID_TYPE_SYS = 1,
|
||||
@@ -121,13 +134,6 @@ typedef struct onlp_oid_hdr_s {
|
||||
} onlp_oid_hdr_t;
|
||||
|
||||
|
||||
#define ONLP_OID_DUMP_F_RECURSE 0x1
|
||||
#define ONLP_OID_DUMP_F_EVEN_IF_ABSENT 0x2
|
||||
|
||||
#define ONLP_OID_SHOW_F_RECURSE 0x1
|
||||
#define ONLP_OID_SHOW_F_EXTENDED 0x2
|
||||
#define ONLP_OID_SHOW_F_YAML 0x4
|
||||
|
||||
void onlp_oid_dump(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags);
|
||||
void onlp_oid_table_dump(onlp_oid_table_t table, aim_pvs_t* pvs,
|
||||
uint32_t flags);
|
||||
@@ -199,6 +205,48 @@ int onlp_oid_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t* hdr);
|
||||
*
|
||||
*****************************************************************************/
|
||||
/* <auto.start.enum(tag:oid).supportheader> */
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_dump_name(onlp_oid_dump_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_dump_value(const char* str, onlp_oid_dump_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_dump_desc(onlp_oid_dump_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_dump_valid(onlp_oid_dump_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_DUMP_VALID(_e) \
|
||||
(onlp_oid_dump_valid((_e)))
|
||||
|
||||
/** onlp_oid_dump_map table. */
|
||||
extern aim_map_si_t onlp_oid_dump_map[];
|
||||
/** onlp_oid_dump_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_dump_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_show_name(onlp_oid_show_t e);
|
||||
|
||||
/** Enum values. */
|
||||
int onlp_oid_show_value(const char* str, onlp_oid_show_t* e, int substr);
|
||||
|
||||
/** Enum descriptions. */
|
||||
const char* onlp_oid_show_desc(onlp_oid_show_t e);
|
||||
|
||||
/** Enum validator. */
|
||||
int onlp_oid_show_valid(onlp_oid_show_t e);
|
||||
|
||||
/** validator */
|
||||
#define ONLP_OID_SHOW_VALID(_e) \
|
||||
(onlp_oid_show_valid((_e)))
|
||||
|
||||
/** onlp_oid_show_map table. */
|
||||
extern aim_map_si_t onlp_oid_show_map[];
|
||||
/** onlp_oid_show_desc_map table. */
|
||||
extern aim_map_si_t onlp_oid_show_desc_map[];
|
||||
|
||||
/** Enum names. */
|
||||
const char* onlp_oid_type_name(onlp_oid_type_t e);
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ ONLP_ENUMERATION_ENTRY(onlp_fan_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_led_caps, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_led_mode, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_led_status, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_dump, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_show, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_oid_type, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_psu_caps, "")
|
||||
ONLP_ENUMERATION_ENTRY(onlp_psu_status, "")
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for onlp.
|
||||
"""
|
||||
@@ -0,0 +1,652 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for onlp.onlp
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
|
||||
libonlp = ctypes.cdll.LoadLibrary("libonlp.so")
|
||||
libonlp.onlp_init()
|
||||
|
||||
import ctypes.util
|
||||
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c"))
|
||||
|
||||
import onlp.onlplib
|
||||
import onlp.sff
|
||||
|
||||
from onlp.onlp.enums import *
|
||||
|
||||
# AIM/aim_memory.h
|
||||
|
||||
class aim_void_p(ctypes.c_void_p):
|
||||
"""Generic data allocated by AIM."""
|
||||
def __del__(self):
|
||||
libonlp.aim_free(self)
|
||||
|
||||
class aim_char_p(aim_void_p):
|
||||
"""AIM data that is a printable string."""
|
||||
|
||||
def __init__(self, stringOrAddress):
|
||||
|
||||
if stringOrAddress is None:
|
||||
aim_void_p.__init__(self, stringOrAddress)
|
||||
return
|
||||
|
||||
if isinstance(stringOrAddress, aim_void_p):
|
||||
aim_void_p.__init__(self, stringOrAddress)
|
||||
return
|
||||
|
||||
if isinstance(stringOrAddress, basestring):
|
||||
cs = ctypes.c_char_p(stringOrAddress)
|
||||
ptr = libonlp.aim_malloc(len(stringOrAddress)+1)
|
||||
libc.strcpy(ptr, ctypes.addressof(cs))
|
||||
aim_void_p.__init__(self, ptr)
|
||||
return
|
||||
|
||||
if type(stringOrAddress) == int:
|
||||
aim_void_p.__init__(self, stringOrAddress)
|
||||
return
|
||||
|
||||
raise ValueError("invalid initializer for aim_char_p: %s"
|
||||
% repr(stringOrAddress))
|
||||
|
||||
def string_at(self):
|
||||
if self.value:
|
||||
return ctypes.string_at(self.value)
|
||||
else:
|
||||
return None
|
||||
|
||||
def __eq__(self, other):
|
||||
return (isinstance(other, aim_char_p)
|
||||
and (self.string_at()==other.string_at()))
|
||||
|
||||
def __neq__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.string_at())
|
||||
|
||||
def aim_memory_init_prototypes():
|
||||
|
||||
libonlp.aim_malloc.restype = aim_void_p
|
||||
libonlp.aim_malloc.argtypes = (ctypes.c_size_t,)
|
||||
|
||||
libonlp.aim_free.restype = None
|
||||
libonlp.aim_free.argtypes = (aim_void_p,)
|
||||
|
||||
# AIM/aim_object.h
|
||||
|
||||
aim_object_dtor = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
|
||||
|
||||
class aim_object(ctypes.Structure):
|
||||
_fields_ = [("_id", ctypes.c_char_p,),
|
||||
("subtype", ctypes.c_int,),
|
||||
("cookie", ctypes.c_void_p,),
|
||||
("destructor", aim_object_dtor,),]
|
||||
|
||||
# AIM/aim_pvs.h
|
||||
# AIM/aim_pvs_*.h
|
||||
|
||||
aim_vprintf_f = ctypes.CFUNCTYPE(ctypes.c_int)
|
||||
|
||||
class aim_pvs(ctypes.Structure):
|
||||
_fields_ = [("object", aim_object,),
|
||||
("description", ctypes.c_char_p,),
|
||||
("vprintf", aim_vprintf_f,),
|
||||
("enabled", ctypes.c_int,),
|
||||
("counter", ctypes.c_uint32,),
|
||||
("isatty", aim_vprintf_f,),]
|
||||
|
||||
def aim_pvs_init_prototypes():
|
||||
|
||||
libonlp.aim_pvs_buffer_create.restype = ctypes.POINTER(aim_pvs)
|
||||
|
||||
libonlp.aim_pvs_destroy.restype = None
|
||||
libonlp.aim_pvs_destroy.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.aim_pvs_buffer_size.restype = ctypes.c_int
|
||||
libonlp.aim_pvs_buffer_size.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.aim_pvs_buffer_get.restype = aim_char_p
|
||||
libonlp.aim_pvs_buffer_get.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.aim_pvs_buffer_reset.restype = None
|
||||
libonlp.aim_pvs_buffer_reset.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
# AIM/aim_bitmap.h
|
||||
|
||||
aim_bitmap_word = ctypes.c_uint32
|
||||
AIM_BITMAP_BITS_PER_WORD = 32
|
||||
|
||||
def AIM_BITMAP_WORD_COUNT(bitcount):
|
||||
return ((bitcount // AIM_BITMAP_BITS_PER_WORD)
|
||||
+ (1 if (bitcount % AIM_BITMAP_BITS_PER_WORD) else 0))
|
||||
|
||||
# ugh, most of aim_bitmap.h is inline C
|
||||
|
||||
def AIM_BITMAP_HDR_WORD_GET(hdr, word):
|
||||
"""Return a specific ctypes word."""
|
||||
return hdr.words[word]
|
||||
|
||||
def AIM_BITMAP_HDR_BIT_WORD_GET(hdr, bit):
|
||||
"""Return the ctypes word holding this bit."""
|
||||
return hdr.words[bit/AIM_BITMAP_BITS_PER_WORD]
|
||||
|
||||
def AIM_BITMAP_HDR_BIT_WORD_SET(hdr, bit, word):
|
||||
"""Return the ctypes word holding this bit."""
|
||||
hdr.words[bit/AIM_BITMAP_BITS_PER_WORD] = word
|
||||
|
||||
def AIM_BITMAP_BIT_POS(bit):
|
||||
return (1<<(bit % AIM_BITMAP_BITS_PER_WORD))
|
||||
|
||||
def AIM_BITMAP_INIT(bitmap, count):
|
||||
"""Initialize a static bitmap."""
|
||||
libc.memset(ctypes.byref(bitmap), 0, ctypes.sizeof(bitmap))
|
||||
bitmap.hdr.maxbit = count
|
||||
bitmap.hdr.words = ctypes.cast(ctypes.byref(bitmap.words), ctypes.POINTER(ctypes.c_uint))
|
||||
bitmap.hdr.wordcount = AIM_BITMAP_WORD_COUNT(count)
|
||||
|
||||
class aim_bitmap_hdr(ctypes.Structure):
|
||||
_fields_ = [("wordcount", ctypes.c_int,),
|
||||
("words", ctypes.POINTER(aim_bitmap_word),),
|
||||
("maxbit", ctypes.c_int,),
|
||||
("allocated", ctypes.c_int,),]
|
||||
|
||||
class aim_bitmap(ctypes.Structure):
|
||||
_fields_ = [("hdr", aim_bitmap_hdr,),]
|
||||
|
||||
@classmethod
|
||||
def fromAim(cls, bitcount):
|
||||
"""Return a pointer to a bitmap from aim_alloc().
|
||||
|
||||
Pre-initialized; needs to be freed with aim_free().
|
||||
"""
|
||||
return libonlp.aim_bitmap_alloc(None, bitcount)
|
||||
|
||||
class aim_bitmap256(aim_bitmap):
|
||||
"""Statically-allocated AIM bitmap."""
|
||||
_fields_ = [("words", aim_bitmap_word * AIM_BITMAP_WORD_COUNT(256),),]
|
||||
|
||||
def __init__(self):
|
||||
super(aim_bitmap256, self).__init__()
|
||||
AIM_BITMAP_INIT(self, 255)
|
||||
|
||||
def aim_bitmap_set(hdr, bit):
|
||||
word = AIM_BITMAP_HDR_BIT_WORD_GET(hdr, bit)
|
||||
word |= AIM_BITMAP_BIT_POS(bit)
|
||||
AIM_BITMAP_HDR_BIT_WORD_SET(hdr, bit, word)
|
||||
|
||||
def aim_bitmap_clr(hdr, bit):
|
||||
word = AIM_BITMAP_HDR_BIT_WORD_GET(hdr, bit)
|
||||
word &= ~(AIM_BITMAP_BIT_POS(bit))
|
||||
AIM_BITMAP_HDR_BIT_WORD_SET(hdr, bit, word)
|
||||
|
||||
def aim_bitmap_mod(hdr, bit, value):
|
||||
if value:
|
||||
aim_bitmap_set(hdr, bit)
|
||||
else:
|
||||
aim_bitmap_clr(hdr, bit)
|
||||
|
||||
def aim_bitmap_get(hdr, bit):
|
||||
val = AIM_BITMAP_HDR_BIT_WORD_GET(hdr,bit) & AIM_BITMAP_BIT_POS(bit)
|
||||
return 1 if val else 0
|
||||
|
||||
# Huh, these is inline too, but calls into glibc memset
|
||||
|
||||
def aim_bitmap_set_all(hdr):
|
||||
libc.memset(ctypes.byref(hdr.words), 0xFF, hdr.wordcount*ctypes.sizeof(aim_bitmap_word))
|
||||
|
||||
def aim_bitmap_clr_all(hdr):
|
||||
libc.memset(ctypes.byref(hdr.words), 0x00, hdr.wordcount*ctypes.sizeof(aim_bitmap_word))
|
||||
|
||||
# XXX aim_bitmap_count is left out
|
||||
|
||||
def aim_bitmap_init_prototypes():
|
||||
|
||||
libonlp.aim_bitmap_alloc.restype = ctypes.POINTER(aim_bitmap)
|
||||
libonlp.aim_bitmap_alloc.argtypes = (ctypes.POINTER(aim_bitmap), ctypes.c_int,)
|
||||
|
||||
libonlp.aim_bitmap_free.restype = None
|
||||
libonlp.aim_bitmap_free.argtypes = (ctypes.POINTER(aim_bitmap),)
|
||||
|
||||
# onlp.yml
|
||||
|
||||
##ONLP_CONFIG_INFO_STR_MAX = int(libonlp.onlp_config_lookup("ONLP_CONFIG_INFO_STR_MAX"))
|
||||
ONLP_CONFIG_INFO_STR_MAX = 64
|
||||
# prototype for onlp_config_lookup is not defined yet, see below
|
||||
|
||||
# onlp/oids.h
|
||||
|
||||
onlp_oid = ctypes.c_uint32
|
||||
|
||||
ONLP_OID_SYS = (ONLP_OID_TYPE.SYS<<24) | 1
|
||||
# XXX not a config option
|
||||
|
||||
ONLP_OID_DESC_SIZE = 128
|
||||
ONLP_OID_TABLE_SIZE = 32
|
||||
# XXX not a config option
|
||||
|
||||
class OidTableIterator(object):
|
||||
|
||||
def __init__(self, hdr):
|
||||
self.hdr = hdr
|
||||
self.idx = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def next(self):
|
||||
if self.idx >= ONLP_OID_TABLE_SIZE:
|
||||
raise StopIteration
|
||||
oid = self.hdr.coids[self.idx]
|
||||
self.idx += 1
|
||||
if oid == 0:
|
||||
raise StopIteration
|
||||
oidHdr = onlp_oid_hdr()
|
||||
libonlp.onlp_oid_hdr_get(oid, ctypes.byref(oidHdr))
|
||||
return oidHdr
|
||||
|
||||
class onlp_oid_hdr(ctypes.Structure):
|
||||
|
||||
_fields_ = [("_id", onlp_oid,),
|
||||
("description", ctypes.c_char * ONLP_OID_DESC_SIZE,),
|
||||
("poid", onlp_oid,),
|
||||
("coids", onlp_oid * ONLP_OID_TABLE_SIZE,),]
|
||||
|
||||
def getType(self):
|
||||
return self._id >> 24
|
||||
|
||||
def isSystem(self):
|
||||
return self.getType() == ONLP_OID_TYPE.SYS
|
||||
def isThermal(self):
|
||||
return self.getType() == ONLP_OID_TYPE.THERMAL
|
||||
def isFan(self):
|
||||
return self.getType() == ONLP_OID_TYPE.FAN
|
||||
def isPsu(self):
|
||||
return self.getType() == ONLP_OID_TYPE.PSU
|
||||
def isLed(self):
|
||||
return self.getType() == ONLP_OID_TYPE.LED
|
||||
def isModule(self):
|
||||
return self.getType() == ONLP_OID_TYPE.MODULE
|
||||
def isRtc(self):
|
||||
return self.getType() == ONLP_OID_TYPE.RTC
|
||||
|
||||
def children(self):
|
||||
return OidTableIterator(self)
|
||||
|
||||
onlp_oid_iterate_f = ctypes.CFUNCTYPE(ctypes.c_int, onlp_oid, ctypes.c_void_p)
|
||||
|
||||
def onlp_oid_init_prototypes():
|
||||
|
||||
libonlp.onlp_oid_dump.restype = None
|
||||
libonlp.onlp_oid_dump.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_oid_table_dump.restype = None
|
||||
libonlp.onlp_oid_table_dump.argtypes = (ctypes.POINTER(onlp_oid), ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_oid_show.restype = None
|
||||
libonlp.onlp_oid_show.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_oid_table_show.restype = None
|
||||
libonlp.onlp_oid_table_show.argtypes = (ctypes.POINTER(onlp_oid), ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_oid_iterate.restype = ctypes.c_int
|
||||
libonlp.onlp_oid_iterate.argtypes = (onlp_oid, ctypes.c_int,
|
||||
onlp_oid_iterate_f, ctypes.c_void_p,)
|
||||
|
||||
libonlp.onlp_oid_hdr_get.restype = ctypes.c_int
|
||||
libonlp.onlp_oid_hdr_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_oid_hdr,))
|
||||
|
||||
# onlp/sys.h
|
||||
|
||||
class onlp_sys_info(ctypes.Structure):
|
||||
|
||||
initialized = False
|
||||
|
||||
_fields_ = [("hdr", onlp_oid_hdr,),
|
||||
("onie_info", onlp.onlplib.onlp_onie_info,),
|
||||
("platform_info", onlp.onlplib.onlp_platform_info,),]
|
||||
|
||||
def __del__(self):
|
||||
if self.initialized:
|
||||
libonlp.onlp_sys_info_free(ctypes.byref(self))
|
||||
|
||||
def onlp_sys_init_prototypes():
|
||||
|
||||
libonlp.onlp_sys_init.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_sys_info_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sys_info_get.argtypes = (ctypes.POINTER(onlp_sys_info),)
|
||||
|
||||
libonlp.onlp_sys_info_free.restype = None
|
||||
libonlp.onlp_sys_info_get.argtypes = (ctypes.POINTER(onlp_sys_info),)
|
||||
|
||||
libonlp.onlp_sys_hdr_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sys_hdr_get.argtypes = (ctypes.POINTER(onlp_oid_hdr),)
|
||||
|
||||
libonlp.onlp_sys_dump.restype = None
|
||||
libonlp.onlp_sys_dump.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_sys_show.restype = None
|
||||
libonlp.onlp_sys_show.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_sys_ioctl.restype = ctypes.c_int
|
||||
# leave the parameters empty (varargs)
|
||||
|
||||
##libonlp.onlp_sys_vioctl.restype = ctypes.c_int
|
||||
# NOTE that ctypes cannot automatically handle va_list
|
||||
|
||||
libonlp.onlp_sys_platform_manage_start.restype = ctypes.c_int
|
||||
libonlp.onlp_sys_platform_manage_start.argtypes = (ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_sys_platform_manage_stop.restype = ctypes.c_int
|
||||
libonlp.onlp_sys_platform_manage_stop.argtypes = (ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_sys_platform_manage_join.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_sys_platform_manage_now.restype = None
|
||||
|
||||
libonlp.onlp_sys_debug.restype = ctypes.c_int
|
||||
libonlp.onlp_sys_debug.argtypes = (ctypes.POINTER(aim_pvs), ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.POINTER(ctypes.c_char)),)
|
||||
|
||||
# onlp/fan.h
|
||||
|
||||
class onlp_fan_info(ctypes.Structure):
|
||||
_fields_ = [("hdr", onlp_oid_hdr,),
|
||||
("status", ctypes.c_uint32,),
|
||||
("caps", ctypes.c_uint32,),
|
||||
("rpm", ctypes.c_int,),
|
||||
("percentage", ctypes.c_int,),
|
||||
("mode", ctypes.c_uint32,),
|
||||
("model", ctypes.c_char * ONLP_CONFIG_INFO_STR_MAX,),
|
||||
("serial", ctypes.c_char * ONLP_CONFIG_INFO_STR_MAX,),]
|
||||
|
||||
def isPresent(self):
|
||||
return self.status & ONLP_FAN_STATUS.PRESENT
|
||||
|
||||
def isMissing(self):
|
||||
return not self.PRESENT()
|
||||
|
||||
def isFailed(self):
|
||||
return self.status & ONLP_FAN_STATUS.FAILED
|
||||
|
||||
def isNormal(self):
|
||||
return self.isPresent() and not self.isFailed()
|
||||
|
||||
def onlp_fan_init_prototypes():
|
||||
|
||||
libonlp.onlp_fan_init.restype = None
|
||||
|
||||
libonlp.onlp_fan_info_get.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_info_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_fan_info),)
|
||||
|
||||
libonlp.onlp_fan_status_get.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_status_get.argtypes = (onlp_oid, ctypes.POINTER(ctypes.c_uint32),)
|
||||
|
||||
libonlp.onlp_fan_hdr_get.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_hdr_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_oid_hdr),)
|
||||
|
||||
libonlp.onlp_fan_rpm_set.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_rpm_set.argtypes = (onlp_oid, ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_fan_percentage_set.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_percentage_set.argtypes = (onlp_oid, ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_fan_mode_set.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_mode_set.argtypes = (onlp_oid, ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_fan_dir_set.restype = ctypes.c_int
|
||||
libonlp.onlp_fan_dir_set.argtypes = (onlp_oid, ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_fan_dump.restype = None
|
||||
libonlp.onlp_fan_dump.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_fan_show.restype = None
|
||||
libonlp.onlp_fan_show.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
# onlp/led.h
|
||||
|
||||
class onlp_led_info(ctypes.Structure):
|
||||
_fields_ = [("hdr", onlp_oid_hdr,),
|
||||
("status", ctypes.c_uint32,),
|
||||
("caps", ctypes.c_uint32,),
|
||||
("mode", ctypes.c_uint32,),
|
||||
("character", ctypes.c_char,),]
|
||||
|
||||
def onlp_led_init_prototypes():
|
||||
|
||||
libonlp.onlp_led_init.restype = None
|
||||
|
||||
libonlp.onlp_led_info_get.restype = ctypes.c_int
|
||||
libonlp.onlp_led_info_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_led_info),)
|
||||
|
||||
libonlp.onlp_led_status_get.restype = ctypes.c_int
|
||||
libonlp.onlp_led_status_get.argtypes = (onlp_oid, ctypes.POINTER(ctypes.c_uint32),)
|
||||
|
||||
libonlp.onlp_led_hdr_get.restype = ctypes.c_int
|
||||
libonlp.onlp_led_hdr_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_oid_hdr),)
|
||||
|
||||
libonlp.onlp_led_set.restype = ctypes.c_int
|
||||
libonlp.onlp_led_set.argtypes = (onlp_oid, ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_led_mode_set.restype = ctypes.c_int
|
||||
libonlp.onlp_led_mode_set.argtypes = (onlp_oid, ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_led_char_set.restype = ctypes.c_int
|
||||
libonlp.onlp_led_char_set.argtypes = (onlp_oid, ctypes.c_char,)
|
||||
|
||||
libonlp.onlp_led_dump.restype = None
|
||||
libonlp.onlp_led_dump.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
libonlp.onlp_led_show.restype = None
|
||||
libonlp.onlp_led_show.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs), ctypes.c_uint32,)
|
||||
|
||||
# onlp/onlp_config.h
|
||||
|
||||
# don't need the actual config structure, since we'll be using lookups
|
||||
|
||||
def onlp_config_init_prototypes():
|
||||
|
||||
libonlp.onlp_config_lookup.restype = ctypes.c_char_p
|
||||
libonlp.onlp_config_lookup.argtypes = (ctypes.c_char_p,)
|
||||
|
||||
libonlp.onlp_config_show.restype = ctypes.c_int
|
||||
libonlp.onlp_config_show.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
# onlp/thermal.h
|
||||
|
||||
class onlp_thermal_info_thresholds(ctypes.Structure):
|
||||
_fields_ = [('warning', ctypes.c_int,),
|
||||
('error', ctypes.c_int,),
|
||||
('shutdown', ctypes.c_int,),]
|
||||
|
||||
class onlp_thermal_info(ctypes.Structure):
|
||||
_fields_ = [('hdr', onlp_oid_hdr,),
|
||||
('status', ctypes.c_uint32,),
|
||||
('caps', ctypes.c_uint32,),
|
||||
('mcelcius', ctypes.c_int,),
|
||||
('thresholds', onlp_thermal_info_thresholds,),]
|
||||
|
||||
def onlp_thermal_init_prototypes():
|
||||
|
||||
libonlp.onlp_thermal_init.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_thermal_info_get.restype = ctypes.c_int
|
||||
libonlp.onlp_thermal_info_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_thermal_info),)
|
||||
|
||||
libonlp.onlp_thermal_status_get.restype = ctypes.c_int
|
||||
libonlp.onlp_thermal_status_get.argtypes = (onlp_oid, ctypes.POINTER(ctypes.c_uint32),)
|
||||
|
||||
libonlp.onlp_thermal_hdr_get.restype = ctypes.c_int
|
||||
libonlp.onlp_thermal_hdr_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_oid_hdr),)
|
||||
|
||||
libonlp.onlp_thermal_ioctl.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_thermal_dump.restype = None
|
||||
libonlp.onlp_thermal_dump.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.onlp_thermal_show.restype = None
|
||||
libonlp.onlp_thermal_show.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs),)
|
||||
|
||||
# onlp/psu.h
|
||||
|
||||
class onlp_psu_info(ctypes.Structure):
|
||||
_fields_ = [("hdr", onlp_oid_hdr,),
|
||||
("model", ctypes.c_char * ONLP_CONFIG_INFO_STR_MAX,),
|
||||
("serial", ctypes.c_char * ONLP_CONFIG_INFO_STR_MAX,),
|
||||
("status", ctypes.c_uint32,),
|
||||
("caps", ctypes.c_uint32,),
|
||||
("mvin", ctypes.c_int,),
|
||||
("mvout", ctypes.c_int,),
|
||||
("miin", ctypes.c_int,),
|
||||
("miout", ctypes.c_int,),
|
||||
("mpin", ctypes.c_int,),
|
||||
("mpout", ctypes.c_int,),]
|
||||
|
||||
def onlp_psu_init_prototypes():
|
||||
|
||||
libonlp.onlp_psu_init.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_psu_info_get.restype = ctypes.c_int
|
||||
libonlp.onlp_psu_info_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_psu_info),)
|
||||
|
||||
libonlp.onlp_psu_status_get.restype = ctypes.c_int
|
||||
libonlp.onlp_psu_status_get.argtypes = (onlp_oid, ctypes.POINTER(ctypes.c_uint32),)
|
||||
|
||||
libonlp.onlp_psu_hdr_get.restype = ctypes.c_int
|
||||
libonlp.onlp_psu_hdr_get.argtypes = (onlp_oid, ctypes.POINTER(onlp_oid_hdr),)
|
||||
|
||||
libonlp.onlp_psu_ioctl.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_psu_dump.restype = None
|
||||
libonlp.onlp_psu_dump.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.onlp_psu_show.restype = None
|
||||
libonlp.onlp_psu_show.argtypes = (onlp_oid, ctypes.POINTER(aim_pvs),)
|
||||
|
||||
# sff/sff.h
|
||||
|
||||
def sff_init_prototypes():
|
||||
|
||||
libonlp.sff_sfp_type_get.restype = onlp.sff.sff_sfp_type
|
||||
libonlp.sff_sfp_type_get.argtypes = (ctypes.POINTER(ctypes.c_ubyte),)
|
||||
|
||||
libonlp.sff_module_type_get.restype = onlp.sff.sff_module_type
|
||||
libonlp.sff_module_type_get.argtypes = (ctypes.POINTER(ctypes.c_ubyte),)
|
||||
|
||||
libonlp.sff_media_type_get.restype = onlp.sff.sff_media_type
|
||||
libonlp.sff_media_type_get.argtypes = (onlp.sff.sff_module_type,)
|
||||
|
||||
libonlp.sff_module_caps_get.restype = ctypes.c_int
|
||||
libonlp.sff_module_caps_get.argtypes = (onlp.sff.sff_module_type, ctypes.POINTER(ctypes.c_uint32),)
|
||||
|
||||
libonlp.sff_eeprom_parse.restype = ctypes.c_int
|
||||
libonlp.sff_eeprom_parse.argtypes = (ctypes.POINTER(onlp.sff.sff_eeprom), ctypes.POINTER(ctypes.c_ubyte),)
|
||||
|
||||
libonlp.sff_eeprom_parse_file.restype = ctypes.c_int
|
||||
libonlp.sff_eeprom_parse_file.argtypes = (ctypes.POINTER(onlp.sff.sff_eeprom), ctypes.c_char_p,)
|
||||
|
||||
libonlp.sff_eeprom_invalidate.restype = None
|
||||
libonlp.sff_eeprom_invalidate.argtypes = (ctypes.POINTER(onlp.sff.sff_eeprom),)
|
||||
|
||||
libonlp.sff_eeprom_validate.restype = ctypes.c_int
|
||||
libonlp.sff_eeprom_validate.argtypes = (ctypes.POINTER(onlp.sff.sff_eeprom), ctypes.c_int,)
|
||||
|
||||
libonlp.sff_info_show.restype = None
|
||||
libonlp.sff_info_show.argtypes = (ctypes.POINTER(onlp.sff.sff_info), ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.sff_info_init.restype = ctypes.c_int
|
||||
libonlp.sff_info_init.argtypes = (ctypes.POINTER(onlp.sff.sff_info), onlp.sff.sff_module_type,
|
||||
ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p,
|
||||
ctypes.c_int,)
|
||||
|
||||
# onlp/sff.h
|
||||
|
||||
onlp_sfp_bitmap = aim_bitmap256
|
||||
|
||||
onlp_sfp_control = ctypes.c_int
|
||||
|
||||
def onlp_sfp_init_prototypes():
|
||||
|
||||
libonlp.onlp_sfp_init.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_sfp_bitmap_t_init.restype = None
|
||||
libonlp.onlp_sfp_bitmap_t_init.argtypes = (ctypes.POINTER(onlp_sfp_bitmap),)
|
||||
|
||||
libonlp.onlp_sfp_bitmap_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_bitmap_get.argtypes = (ctypes.POINTER(onlp_sfp_bitmap),)
|
||||
|
||||
libonlp.onlp_sfp_port_valid.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_port_valid.argtypes = (ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_sfp_is_present.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_is_present.argtypes = (ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_sfp_presence_bitmap_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_presence_bitmap_get.argtypes = (ctypes.POINTER(onlp_sfp_bitmap),)
|
||||
|
||||
libonlp.onlp_sfp_eeprom_read.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_eeprom_read.argtypes = (ctypes.c_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_ubyte,)),)
|
||||
|
||||
libonlp.onlp_sfp_dom_read.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_dom_read.argtypes = (ctypes.c_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_ubyte)),)
|
||||
|
||||
libonlp.onlp_sfp_denit.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_sfp_rx_los_bitmap_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_rx_los_bitmap_get.argtypes = (ctypes.POINTER(onlp_sfp_bitmap),)
|
||||
|
||||
libonlp.onlp_sfp_dev_readb.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_dev_readb.argtypes = (ctypes.c_int, ctypes.c_ubyte, ctypes.c_ubyte,)
|
||||
|
||||
libonlp.onlp_sfp_dev_writeb.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_dev_writeb.argtypes = (ctypes.c_int, ctypes.c_ubyte, ctypes.c_ubyte, ctypes.c_ubyte)
|
||||
|
||||
libonlp.onlp_sfp_dev_readw.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_dev_readw.argtypes = (ctypes.c_int, ctypes.c_ubyte, ctypes.c_ubyte,)
|
||||
|
||||
libonlp.onlp_sfp_dev_writew.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_dev_writew.argtypes = (ctypes.c_int, ctypes.c_ubyte, ctypes.c_ubyte, ctypes.c_ushort)
|
||||
|
||||
libonlp.onlp_sfp_dump.restype = None
|
||||
libonlp.onlp_sfp_dump.argtypes = (ctypes.POINTER(aim_pvs),)
|
||||
|
||||
libonlp.onlp_sfp_ioctl.restype = ctypes.c_int
|
||||
|
||||
libonlp.onlp_sfp_post_insert.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_post_insert.argtypes = (ctypes.c_int, ctypes.POINTER(onlp.sff.sff_info),)
|
||||
|
||||
libonlp.onlp_sfp_control_set.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_control_set.argtypes = (ctypes.c_int, onlp_sfp_control, ctypes.c_int,)
|
||||
|
||||
libonlp.onlp_sfp_control_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_control_get.argtypes = (ctypes.c_int, onlp_sfp_control, ctypes.POINTER(ctypes.c_int))
|
||||
|
||||
libonlp.onlp_sfp_control_flags_get.restype = ctypes.c_int
|
||||
libonlp.onlp_sfp_control_flags_get.argtyeps = (ctypes.c_int, ctypes.POINTER(ctypes.c_uint32),)
|
||||
|
||||
# onlp/onlp.h
|
||||
|
||||
def init_prototypes():
|
||||
aim_memory_init_prototypes()
|
||||
aim_pvs_init_prototypes()
|
||||
aim_bitmap_init_prototypes()
|
||||
onlp_oid_init_prototypes()
|
||||
onlp_sys_init_prototypes()
|
||||
onlp_fan_init_prototypes()
|
||||
onlp_led_init_prototypes()
|
||||
|
||||
onlp_config_init_prototypes()
|
||||
|
||||
strMax = int(libonlp.onlp_config_lookup("ONLP_CONFIG_INFO_STR_MAX"))
|
||||
if ONLP_CONFIG_INFO_STR_MAX != strMax:
|
||||
raise AssertionError("ONLP_CONFIG_INFO_STR_MAX changed from %d to %d"
|
||||
% (ONLP_CONFIG_INFO_STR_MAX, strMax,))
|
||||
|
||||
onlp_thermal_init_prototypes()
|
||||
onlp_psu_init_prototypes()
|
||||
sff_init_prototypes()
|
||||
onlp_sfp_init_prototypes()
|
||||
|
||||
init_prototypes()
|
||||
@@ -88,6 +88,17 @@ class ONLP_LED_STATUS(Enumeration):
|
||||
ON = (1 << 2)
|
||||
|
||||
|
||||
class ONLP_OID_DUMP(Enumeration):
|
||||
RECURSE = (1 << 0)
|
||||
EVEN_IF_ABSENT = (1 << 1)
|
||||
|
||||
|
||||
class ONLP_OID_SHOW(Enumeration):
|
||||
RECURSE = (1 << 0)
|
||||
EXTENDED = (1 << 1)
|
||||
YAML = (1 << 2)
|
||||
|
||||
|
||||
class ONLP_OID_TYPE(Enumeration):
|
||||
SYS = 1
|
||||
THERMAL = 2
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
"""__init__.py
|
||||
|
||||
Test code for the onlp Python bindings.
|
||||
"""
|
||||
@@ -281,7 +281,7 @@ onlp_fan_show(onlp_oid_t oid, aim_pvs_t* pvs, uint32_t flags)
|
||||
|
||||
rv = onlp_fan_info_get(oid, &fi);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_F_YAML;
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "- ");
|
||||
|
||||
@@ -215,7 +215,7 @@ onlp_led_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
VALIDATENR(id);
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_F_YAML;
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, " -");
|
||||
|
||||
@@ -216,7 +216,7 @@ onlp_oid_iterate(onlp_oid_t oid, onlp_oid_type_t type,
|
||||
}
|
||||
|
||||
ONLP_OID_TABLE_ITER(hdr.coids, oidp) {
|
||||
if(type == 0 || ONLP_OID_IS_TYPE(*oidp, type)) {
|
||||
if(type == 0 || ONLP_OID_IS_TYPE(type, *oidp)) {
|
||||
int rv = itf(*oidp, cookie);
|
||||
if(rv < 0) {
|
||||
return rv;
|
||||
|
||||
@@ -145,7 +145,7 @@ onlp_config_lookup(const char* setting)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; onlp_config_settings[i].name; i++) {
|
||||
if(strcmp(onlp_config_settings[i].name, setting)) {
|
||||
if(!strcmp(onlp_config_settings[i].name, setting)) {
|
||||
return onlp_config_settings[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,6 +519,128 @@ onlp_led_status_valid(onlp_led_status_t e)
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_dump_map[] =
|
||||
{
|
||||
{ "RECURSE", ONLP_OID_DUMP_RECURSE },
|
||||
{ "EVEN_IF_ABSENT", ONLP_OID_DUMP_EVEN_IF_ABSENT },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_dump_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_DUMP_RECURSE },
|
||||
{ "None", ONLP_OID_DUMP_EVEN_IF_ABSENT },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_dump_name(onlp_oid_dump_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_dump_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_dump'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_dump_value(const char* str, onlp_oid_dump_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_dump_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_dump_desc(onlp_oid_dump_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_dump_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_dump'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_dump_valid(onlp_oid_dump_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_dump_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_show_map[] =
|
||||
{
|
||||
{ "RECURSE", ONLP_OID_SHOW_RECURSE },
|
||||
{ "EXTENDED", ONLP_OID_SHOW_EXTENDED },
|
||||
{ "YAML", ONLP_OID_SHOW_YAML },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
aim_map_si_t onlp_oid_show_desc_map[] =
|
||||
{
|
||||
{ "None", ONLP_OID_SHOW_RECURSE },
|
||||
{ "None", ONLP_OID_SHOW_EXTENDED },
|
||||
{ "None", ONLP_OID_SHOW_YAML },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
const char*
|
||||
onlp_oid_show_name(onlp_oid_show_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_show_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_show'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_show_value(const char* str, onlp_oid_show_t* e, int substr)
|
||||
{
|
||||
int i;
|
||||
AIM_REFERENCE(substr);
|
||||
if(aim_map_si_s(&i, str, onlp_oid_show_map, 0)) {
|
||||
/* Enum Found */
|
||||
*e = i;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
onlp_oid_show_desc(onlp_oid_show_t e)
|
||||
{
|
||||
const char* name;
|
||||
if(aim_map_si_i(&name, e, onlp_oid_show_desc_map, 0)) {
|
||||
return name;
|
||||
}
|
||||
else {
|
||||
return "-invalid value for enum type 'onlp_oid_show'";
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
onlp_oid_show_valid(onlp_oid_show_t e)
|
||||
{
|
||||
return aim_map_si_i(NULL, e, onlp_oid_show_map, 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
aim_map_si_t onlp_oid_type_map[] =
|
||||
{
|
||||
{ "SYS", ONLP_OID_TYPE_SYS },
|
||||
|
||||
@@ -203,8 +203,8 @@ onlpdump_main(int argc, char* argv[])
|
||||
switch(c)
|
||||
{
|
||||
case 's': show=1; break;
|
||||
case 'r': show=1; showflags |= ONLP_OID_SHOW_F_RECURSE; break;
|
||||
case 'e': show=1; showflags |= ONLP_OID_SHOW_F_EXTENDED; break;
|
||||
case 'r': show=1; showflags |= ONLP_OID_SHOW_RECURSE; break;
|
||||
case 'e': show=1; showflags |= ONLP_OID_SHOW_EXTENDED; break;
|
||||
case 'd': show=0; break;
|
||||
case 'h': help=1; rv = 0; break;
|
||||
case 'j': j=1; break;
|
||||
@@ -220,7 +220,7 @@ onlpdump_main(int argc, char* argv[])
|
||||
case 'l': l=1; break;
|
||||
case 'b': b=1; break;
|
||||
case 'J': J = optarg; break;
|
||||
case 'y': show=1; showflags |= ONLP_OID_SHOW_F_YAML; break;
|
||||
case 'y': show=1; showflags |= ONLP_OID_SHOW_YAML; break;
|
||||
default: help=1; rv = 1; break;
|
||||
}
|
||||
}
|
||||
@@ -305,8 +305,8 @@ onlpdump_main(int argc, char* argv[])
|
||||
int oid;
|
||||
if(sscanf(O, "0x%x", &oid) == 1) {
|
||||
onlp_oid_dump(oid, &aim_pvs_stdout,
|
||||
ONLP_OID_DUMP_F_RECURSE |
|
||||
ONLP_OID_DUMP_F_EVEN_IF_ABSENT);
|
||||
ONLP_OID_DUMP_RECURSE |
|
||||
ONLP_OID_DUMP_EVEN_IF_ABSENT);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ onlpdump_main(int argc, char* argv[])
|
||||
if(show == 0) {
|
||||
/* Default to full dump */
|
||||
onlp_platform_dump(&aim_pvs_stdout,
|
||||
ONLP_OID_DUMP_F_RECURSE | ONLP_OID_DUMP_F_EVEN_IF_ABSENT);
|
||||
ONLP_OID_DUMP_RECURSE | ONLP_OID_DUMP_EVEN_IF_ABSENT);
|
||||
}
|
||||
else {
|
||||
onlp_platform_show(&aim_pvs_stdout,
|
||||
|
||||
@@ -69,7 +69,7 @@ onlp_psu_status_get_locked__(onlp_oid_t id, uint32_t* status)
|
||||
}
|
||||
if(ONLP_UNSUPPORTED(rv)) {
|
||||
onlp_psu_info_t pi;
|
||||
rv = onlp_psu_info_get(id, &pi);
|
||||
rv = onlp_psui_info_get(id, &pi);
|
||||
*status = pi.status;
|
||||
}
|
||||
return rv;
|
||||
@@ -143,7 +143,7 @@ onlp_psu_dump(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
iof_iprintf(&iof, "Iout: %d", info.miout);
|
||||
iof_iprintf(&iof, "Pin: %d", info.mpin);
|
||||
iof_iprintf(&iof, "Pout: %d", info.mpout);
|
||||
if(flags & ONLP_OID_DUMP_F_RECURSE) {
|
||||
if(flags & ONLP_OID_DUMP_RECURSE) {
|
||||
onlp_oid_table_dump(info.hdr.coids, &iof.inherit, flags);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ onlp_psu_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
rv = onlp_psu_info_get(id, &pi);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_F_YAML;
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "- ");
|
||||
@@ -235,7 +235,7 @@ onlp_psu_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
ONLP_MILLI_NORMAL_INTEGER_TENTHS(pi.mpout));
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_SHOW_F_RECURSE) {
|
||||
if(flags & ONLP_OID_SHOW_RECURSE) {
|
||||
/*
|
||||
* Display sub oids.
|
||||
*
|
||||
@@ -264,7 +264,7 @@ onlp_psu_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
iof_pop(&iof);
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_SHOW_F_EXTENDED) {
|
||||
if(flags & ONLP_OID_SHOW_EXTENDED) {
|
||||
/* Include all other types as well. */
|
||||
ONLP_OID_TABLE_ITER_TYPE(pi.hdr.coids, oidp, LED) {
|
||||
onlp_oid_show(*oidp, &iof.inherit, flags);
|
||||
|
||||
@@ -214,7 +214,7 @@ onlp_sys_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
int yaml;
|
||||
|
||||
onlp_oid_show_iof_init_default(&iof, pvs, flags);
|
||||
yaml = (flags & ONLP_OID_SHOW_F_YAML);
|
||||
yaml = (flags & ONLP_OID_SHOW_YAML);
|
||||
|
||||
if(id && ONLP_OID_TYPE_GET(id) != ONLP_OID_TYPE_SYS) {
|
||||
return;
|
||||
@@ -234,14 +234,14 @@ onlp_sys_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
* unless you specify EXTENDED or !RECURSIVE
|
||||
*/
|
||||
if(yaml ||
|
||||
flags & ONLP_OID_SHOW_F_EXTENDED ||
|
||||
(flags & ONLP_OID_SHOW_F_RECURSE) == 0) {
|
||||
flags & ONLP_OID_SHOW_EXTENDED ||
|
||||
(flags & ONLP_OID_SHOW_RECURSE) == 0) {
|
||||
iof_push(&iof, "System Information:");
|
||||
onlp_onie_show(&si.onie_info, &iof.inherit);
|
||||
iof_pop(&iof);
|
||||
}
|
||||
|
||||
if(flags & ONLP_OID_SHOW_F_RECURSE) {
|
||||
if(flags & ONLP_OID_SHOW_RECURSE) {
|
||||
|
||||
onlp_oid_t* oidp;
|
||||
|
||||
@@ -266,7 +266,7 @@ onlp_sys_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
}
|
||||
YPOP();
|
||||
|
||||
if(flags & ONLP_OID_SHOW_F_EXTENDED) {
|
||||
if(flags & ONLP_OID_SHOW_EXTENDED) {
|
||||
/** Show all LEDs */
|
||||
YPUSH("LEDs:");
|
||||
ONLP_OID_TABLE_ITER_TYPE(si.hdr.coids, oidp, LED) {
|
||||
|
||||
@@ -202,7 +202,7 @@ onlp_thermal_show(onlp_oid_t id, aim_pvs_t* pvs, uint32_t flags)
|
||||
|
||||
rv = onlp_thermal_info_get(id, &ti);
|
||||
|
||||
yaml = flags & ONLP_OID_SHOW_F_YAML;
|
||||
yaml = flags & ONLP_OID_SHOW_YAML;
|
||||
|
||||
if(yaml) {
|
||||
iof_push(&iof, "- ");
|
||||
|
||||
@@ -115,9 +115,9 @@ aim_main(int argc, char* argv[])
|
||||
|
||||
/* Example Platform Dump */
|
||||
onlp_init();
|
||||
onlp_platform_dump(&aim_pvs_stdout, ONLP_OID_DUMP_F_RECURSE);
|
||||
onlp_platform_dump(&aim_pvs_stdout, ONLP_OID_DUMP_RECURSE);
|
||||
onlp_oid_iterate(0, 0, iter__, NULL);
|
||||
onlp_platform_show(&aim_pvs_stdout, ONLP_OID_SHOW_F_RECURSE|ONLP_OID_SHOW_F_EXTENDED);
|
||||
onlp_platform_show(&aim_pvs_stdout, ONLP_OID_SHOW_RECURSE|ONLP_OID_SHOW_EXTENDED);
|
||||
|
||||
if(argv[1] && !strcmp("manage", argv[1])) {
|
||||
onlp_sys_platform_manage_start();
|
||||
|
||||
36
packages/base/any/onlp/src/onlpdump.py
Executable file
36
packages/base/any/onlp/src/onlpdump.py
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""onldump.py
|
||||
|
||||
Test harness for Python bindings.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from ctypes import *
|
||||
|
||||
import logging
|
||||
|
||||
import onlp.onlp
|
||||
import onlp.onlplib
|
||||
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger("onlpdump")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
onlp.onlp.onlp_init()
|
||||
|
||||
libonlp = onlp.onlp.libonlp
|
||||
si = onlp.onlp.onlp_sys_info()
|
||||
libonlp.onlp_sys_info_get(byref(si))
|
||||
|
||||
logger.info("hello")
|
||||
|
||||
import pdb
|
||||
pdb.set_trace()
|
||||
|
||||
##libonlp.onlp_onie_show(byref(si.onie_info), byref(libonlp.aim_pvs_stdout))
|
||||
libonlp.onlp_platform_dump(libonlp.aim_pvs_stdout,
|
||||
(onlp.onlp.ONLP_OID_DUMP.RECURSE
|
||||
| onlp.onlp.ONLP_OID_DUMP.EVEN_IF_ABSENT))
|
||||
|
||||
sys.exit(0)
|
||||
@@ -0,0 +1,87 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for onlp.onlplib
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
|
||||
# properly belongs in AIM.aim_list
|
||||
|
||||
class list_links(ctypes.Structure):
|
||||
pass
|
||||
|
||||
list_links._fields_ = [("prev", ctypes.POINTER(list_links),),
|
||||
("next", ctypes.POINTER(list_links),),]
|
||||
|
||||
class ListIterator(object):
|
||||
|
||||
def __init__(self, links, castType=None):
|
||||
self.links = links
|
||||
self.castType = castType
|
||||
self.cur = self.links.links.next
|
||||
|
||||
def next(self):
|
||||
|
||||
# Hurr, pointer()/POINTER() types are not directly comparable
|
||||
p1 = ctypes.cast(self.cur, ctypes.c_void_p)
|
||||
p2 = ctypes.cast(self.links.links.prev, ctypes.c_void_p)
|
||||
if p1.value == p2.value:
|
||||
raise StopIteration
|
||||
|
||||
cur, self.cur = self.cur, self.cur.contents.next
|
||||
if self.castType is not None:
|
||||
cur = ctypes.cast(cur, ctypes.POINTER(self.castType))
|
||||
return cur.contents
|
||||
|
||||
class list_head(ctypes.Structure):
|
||||
_fields_ = [("links", list_links,),]
|
||||
|
||||
links_klass = list_links
|
||||
|
||||
def __iter__(self):
|
||||
if self.links_klass == list_links:
|
||||
return ListIterator(self)
|
||||
else:
|
||||
return ListIterator(self, castType=self.links_klass)
|
||||
|
||||
class onlp_onie_vx(list_links):
|
||||
# NOTE that Python inheritence merges the fields
|
||||
# with the base class (ctypes-ism)
|
||||
_fields_ = [("data", ctypes.c_ubyte * 256,),
|
||||
("size", ctypes.c_int,),]
|
||||
|
||||
class onlp_onie_vx_list_head(list_head):
|
||||
links_klass = onlp_onie_vx
|
||||
|
||||
class onlp_onie_info(ctypes.Structure):
|
||||
_fields_ = [("product_name", ctypes.c_char_p,),
|
||||
("part_number", ctypes.c_char_p,),
|
||||
("serial_number", ctypes.c_char_p,),
|
||||
("mac", ctypes.c_ubyte * 6,),
|
||||
("manufacture_date", ctypes.c_char_p,),
|
||||
("device_version", ctypes.c_ubyte,),
|
||||
("label_revision", ctypes.c_char_p,),
|
||||
("platform_name", ctypes.c_char_p,),
|
||||
("onie_version", ctypes.c_char_p,),
|
||||
("mac_range", ctypes.c_ushort,),
|
||||
("manufacturer", ctypes.c_char_p,),
|
||||
("country_code", ctypes.c_char_p,),
|
||||
("vendor", ctypes.c_char_p,),
|
||||
("diag_version", ctypes.c_char_p,),
|
||||
("service_tag", ctypes.c_char_p,),
|
||||
("crc", ctypes.c_uint,),
|
||||
|
||||
#
|
||||
# Vendor Extensions list, if available.
|
||||
#
|
||||
("vx_list", onlp_onie_vx_list_head,),
|
||||
|
||||
# Internal/debug
|
||||
("_hdr_id_string", ctypes.c_char_p,),
|
||||
("_hdr_version", ctypes.c_ubyte,),
|
||||
("_hdr_length", ctypes.c_ubyte,),
|
||||
("_hdr_valid_crc", ctypes.c_ubyte,),]
|
||||
|
||||
class onlp_platform_info(ctypes.Structure):
|
||||
_fields_ = [("cpld_versions", ctypes.c_char_p,),
|
||||
("other_versions", ctypes.c_char_p,),]
|
||||
@@ -4,6 +4,6 @@
|
||||
#
|
||||
###############################################################################
|
||||
sff_AUTO_DEFS := module/auto/sff.yml
|
||||
sff_AUTO_DIRS := module/inc/sff module/src
|
||||
sff_AUTO_DIRS := module/inc/sff module/src module/python/onlp/sff
|
||||
include $(BUILDER)/auto.mk
|
||||
|
||||
|
||||
@@ -156,6 +156,8 @@ definitions:
|
||||
sff_media_type:
|
||||
members: *sff_media_types
|
||||
|
||||
pyenum: *enums
|
||||
|
||||
xenum:
|
||||
SFF_ENUMERATION_ENTRY:
|
||||
members: *enums
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"""__init__.py
|
||||
|
||||
Module init for onlp/sff
|
||||
"""
|
||||
|
||||
from onlp.sff.enums import *
|
||||
|
||||
import ctypes
|
||||
|
||||
sff_media_type = ctypes.c_int
|
||||
sff_module_caps = ctypes.c_int
|
||||
sff_module_type = ctypes.c_int
|
||||
sff_sfp_type = ctypes.c_int
|
||||
|
||||
class sff_info(ctypes.Structure):
|
||||
_fields_ = [("vendor", ctypes.c_char * 17),
|
||||
("model", ctypes.c_char * 17),
|
||||
("serial", ctypes.c_char * 17),
|
||||
("sfp_type", sff_sfp_type),
|
||||
("sfp_type_name", ctypes.c_char_p),
|
||||
("module_type", sff_module_type),
|
||||
("module_type_name", ctypes.c_char_p),
|
||||
("media_type", sff_media_type),
|
||||
("media_type_name", ctypes.c_char_p),
|
||||
("caps", sff_module_caps),
|
||||
("length", ctypes.c_int),
|
||||
("desc", ctypes.c_char * 16),]
|
||||
|
||||
class sff_eeprom(ctypes.Structure):
|
||||
_fields_ = [("eeprom", ctypes.c_ubyte * 256),
|
||||
("cc_base", ctypes.c_ubyte),
|
||||
("cc_ext", ctypes.c_ubyte),
|
||||
("identified", ctypes.c_int),
|
||||
("info", sff_info),]
|
||||
@@ -0,0 +1,70 @@
|
||||
"""enums.py
|
||||
|
||||
Enumerations from the SFF auto.yml.
|
||||
"""
|
||||
|
||||
class Enumeration(object):
|
||||
@classmethod
|
||||
def name(klass, value):
|
||||
for (k, v) in klass.__dict__.iteritems():
|
||||
if v == value:
|
||||
return k
|
||||
return None
|
||||
|
||||
# <auto.start.pyenum(ALL).define>
|
||||
class SFF_MEDIA_TYPE(Enumeration):
|
||||
COPPER = 0
|
||||
FIBER = 1
|
||||
|
||||
|
||||
class SFF_MODULE_CAPS(Enumeration):
|
||||
F_100 = 1
|
||||
F_1G = 2
|
||||
F_10G = 4
|
||||
F_25G = 8
|
||||
F_40G = 16
|
||||
F_100G = 32
|
||||
|
||||
|
||||
class SFF_MODULE_TYPE(Enumeration):
|
||||
_100G_AOC = 0
|
||||
_100G_BASE_CR4 = 1
|
||||
_100G_BASE_SR4 = 2
|
||||
_100G_BASE_LR4 = 3
|
||||
_100G_CWDM4 = 4
|
||||
_100G_PSM4 = 5
|
||||
_40G_BASE_CR4 = 6
|
||||
_40G_BASE_SR4 = 7
|
||||
_40G_BASE_LR4 = 8
|
||||
_40G_BASE_LM4 = 9
|
||||
_40G_BASE_ACTIVE = 10
|
||||
_40G_BASE_CR = 11
|
||||
_40G_BASE_SR2 = 12
|
||||
_40G_BASE_SM4 = 13
|
||||
_40G_BASE_ER4 = 14
|
||||
_25G_BASE_CR = 15
|
||||
_10G_BASE_SR = 16
|
||||
_10G_BASE_LR = 17
|
||||
_10G_BASE_LRM = 18
|
||||
_10G_BASE_ER = 19
|
||||
_10G_BASE_CR = 20
|
||||
_10G_BASE_SX = 21
|
||||
_10G_BASE_LX = 22
|
||||
_10G_BASE_ZR = 23
|
||||
_10G_BASE_SRL = 24
|
||||
_1G_BASE_SX = 25
|
||||
_1G_BASE_LX = 26
|
||||
_1G_BASE_CX = 27
|
||||
_1G_BASE_T = 28
|
||||
_100_BASE_LX = 29
|
||||
_100_BASE_FX = 30
|
||||
_4X_MUX = 31
|
||||
|
||||
|
||||
class SFF_SFP_TYPE(Enumeration):
|
||||
SFP = 0
|
||||
QSFP = 1
|
||||
QSFP_PLUS = 2
|
||||
QSFP28 = 3
|
||||
|
||||
# <auto.end.pyenum(ALL).define>
|
||||
@@ -70,7 +70,7 @@ sff_config_lookup(const char* setting)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; sff_config_settings[i].name; i++) {
|
||||
if(strcmp(sff_config_settings[i].name, setting)) {
|
||||
if(!strcmp(sff_config_settings[i].name, setting)) {
|
||||
return sff_config_settings[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,9 +115,9 @@ aim_main(int argc, char* argv[])
|
||||
|
||||
/* Example Platform Dump */
|
||||
onlp_init();
|
||||
onlp_platform_dump(&aim_pvs_stdout, ONLP_OID_DUMP_F_RECURSE);
|
||||
onlp_platform_dump(&aim_pvs_stdout, ONLP_OID_DUMP_RECURSE);
|
||||
onlp_oid_iterate(0, 0, iter__, NULL);
|
||||
onlp_platform_show(&aim_pvs_stdout, ONLP_OID_SHOW_F_RECURSE|ONLP_OID_SHOW_F_EXTENDED);
|
||||
onlp_platform_show(&aim_pvs_stdout, ONLP_OID_SHOW_RECURSE|ONLP_OID_SHOW_EXTENDED);
|
||||
|
||||
if(argv[1] && !strcmp("manage", argv[1])) {
|
||||
onlp_sys_platform_manage_start();
|
||||
|
||||
Reference in New Issue
Block a user