[sonic-utilities] Update submodule; Build and install as a Python 3 wheel (#5926)

Submodule updates include the following commits:

* src/sonic-utilities 9dc58ea...f9eb739 (18):
  > Remove unnecessary calls to str.encode() now that the package is Python 3; Fix deprecation warning (#1260)
  > [generate_dump] Ignoring file/directory not found Errors (#1201)
  > Fixed porstat rate and util issues (#1140)
  > fix error: interface counters is mismatch after warm-reboot (#1099)
  > Remove unnecessary calls to str.decode() now that the package is Python 3 (#1255)
  > [acl-loader] Make list sorting compliant with Python 3 (#1257)
  > Replace hard-coded fast-reboot with variable. And some typo corrections (#1254)
  > [configlet][portconfig] Remove calls to dict.has_key() which is not available in Python 3 (#1247)
  > Remove unnecessary conversions to list() and calls to dict.keys() (#1243)
  > Clean up LGTM alerts (#1239)
  > Add 'requests' as install dependency in setup.py (#1240)
  > Convert to Python 3 (#1128)
  > Fix mock SonicV2Connector in python3: use decode_responses mode so caller code will be the same as python2 (#1238)
  > [tests] Do not trim from PATH if we did not append to it; Clean up/fix shebangs in scripts (#1233)
  > Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table (#1224)
  > [cli]: NAT show commands newline issue after migrated to Python3 (#1204)
  > [doc]: Update Command-Reference.md (#1231)
  > Added 'import sys' in feature.py file (#1232)

* src/sonic-py-swsssdk 9d9f0c6...1664be9 (2):
  > Fix: no need to decode() after redis client scan, so it will work for both python2 and python3 (#96)
  > FieldValueMap `contains`(`in`)  will also work when migrated to libswsscommon(C++ with SWIG wrapper) (#94)

- Also fix Python 3-related issues:
    - Use integer (floor) division in config_samples.py (sonic-config-engine)
    - Replace print statement with print function in eeprom.py plugin for x86_64-kvm_x86_64-r0 platform
    - Update all platform plugins to be compatible with both Python 2 and Python 3
    - Remove shebangs from plugins files which are not intended to be executable
    - Replace tabs with spaces in Python plugin files and fix alignment, because Python 3 is more strict
    - Remove trailing whitespace from plugins files
This commit is contained in:
Joe LeVeque 2020-11-25 10:28:36 -08:00 коммит произвёл GitHub
Родитель fad481edc1
Коммит 7f4ab8fbd8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
341 изменённых файлов: 6627 добавлений и 6717 удалений

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,11 +8,13 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -15,6 +15,7 @@ except ImportError as e:
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
@ -31,13 +32,13 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
49: [18],
50: [19],
51: [20],
52: [21],
53: [22],
54: [23],
}
49: [18],
50: [19],
51: [20],
52: [21],
53: [22],
54: [23],
}
@property
def port_start(self):
@ -49,7 +50,7 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -70,15 +71,15 @@ class SfpUtil(SfpUtilBase):
present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num)
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -108,7 +109,7 @@ class SfpUtil(SfpUtilBase):
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -123,7 +124,7 @@ class SfpUtil(SfpUtilBase):
try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
# 0x3:Low Power Mode, 0x1:High Power Mode
@ -138,7 +139,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -153,21 +154,22 @@ class SfpUtil(SfpUtilBase):
bits = []
for x in range(self.port_start, self.port_end+1):
bits.append(str(int(self.get_presence(x))))
bits.append(str(int(self.get_presence(x))))
rev = "".join(bits[::-1])
return int(rev,2)
return int(rev, 2)
data = {'present': 0}
data = {'present':0}
def get_transceiver_change_event(self, timeout=0):
port_dict = {}
if timeout == 0:
cd_ms = sys.maxint
cd_ms = sys.maxsize
else:
cd_ms = timeout
#poll per second
# poll per second
while cd_ms > 0:
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
@ -177,7 +179,7 @@ class SfpUtil(SfpUtilBase):
cd_ms = cd_ms - 1000
if changed_ports != 0:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - self.port_start))
if changed_ports & mask:
@ -192,4 +194,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -12,7 +12,7 @@ except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
@ -32,7 +32,7 @@ class SfpUtil(SfpUtilBase):
BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/"
I2C_BUS_ORDER = -1
#The sidebands of QSFP is different.
# The sidebands of QSFP is different.
qsfp_sb_map = [0, 2, 4, 1, 3, 5]
_port_to_is_present = {}
@ -40,61 +40,61 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
1: [1, 2],
2: [2, 3],
3: [3, 4],
4: [4, 5],
5: [5, 6],
6: [6, 7],
7: [7, 8],
8: [8, 9],
9: [9, 10],
10: [10, 11],
11: [11, 12],
12: [12, 13],
13: [13, 14],
14: [14, 15],
15: [15, 16],
16: [16, 17],
17: [17, 18],
18: [18, 19],
19: [19, 20],
20: [20, 21],
21: [21, 22],
22: [22, 23],
23: [23, 24],
24: [24, 25],
25: [25, 26],
26: [26, 27],
27: [27, 28],
28: [28, 29],
29: [29, 30],
30: [30, 31],
31: [31, 32],
32: [32, 33],
33: [33, 34],
34: [34, 35],
35: [35, 36],
36: [36, 37],
37: [37, 38],
38: [38, 39],
39: [39, 40],
40: [40, 41],
41: [41, 42],
42: [42, 43],
43: [43, 44],
44: [44, 45],
45: [45, 46],
46: [46, 47],
47: [47, 48],
48: [48, 49],
49: [49, 50],#QSFP49
50: [51, 52],
51: [53, 54],
52: [50, 51],
53: [52, 53],
54: [54, 55],#QSFP54
}
1: [1, 2],
2: [2, 3],
3: [3, 4],
4: [4, 5],
5: [5, 6],
6: [6, 7],
7: [7, 8],
8: [8, 9],
9: [9, 10],
10: [10, 11],
11: [11, 12],
12: [12, 13],
13: [13, 14],
14: [14, 15],
15: [15, 16],
16: [16, 17],
17: [17, 18],
18: [18, 19],
19: [19, 20],
20: [20, 21],
21: [21, 22],
22: [22, 23],
23: [23, 24],
24: [24, 25],
25: [25, 26],
26: [26, 27],
27: [27, 28],
28: [28, 29],
29: [29, 30],
30: [30, 31],
31: [31, 32],
32: [32, 33],
33: [33, 34],
34: [34, 35],
35: [35, 36],
36: [36, 37],
37: [37, 38],
38: [38, 39],
39: [39, 40],
40: [40, 41],
41: [41, 42],
42: [42, 43],
43: [43, 44],
44: [44, 45],
45: [45, 46],
46: [46, 47],
47: [47, 48],
48: [48, 49],
49: [49, 50], # QSFP49
50: [51, 52],
51: [53, 54],
52: [50, 51],
53: [52, 53],
54: [54, 55], # QSFP54
}
@property
def port_start(self):
@ -111,16 +111,16 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
def update_i2c_order(self):
if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
@ -129,7 +129,7 @@ class SfpUtil(SfpUtilBase):
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
return self.I2C_BUS_ORDER
return self.I2C_BUS_ORDER
def get_presence(self, port_num):
# Check for invalid port_num
@ -144,15 +144,15 @@ class SfpUtil(SfpUtilBase):
present_path = present_path + "module_present_" + str(port_num)
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -167,22 +167,22 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode_cpld(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
lp_mode_path = lp_mode_path + "module_lp_mode_"
lp_mode_path = lp_mode_path + "module_lp_mode_"
q = self.qsfp_sb_remap(port_num)
lp_mode_path = lp_mode_path + str(q)
content="0"
content = "0"
try:
val_file = open(lp_mode_path)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -191,7 +191,7 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return self.get_low_power_mode_cpld(port_num)
@ -202,15 +202,15 @@ class SfpUtil(SfpUtilBase):
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
return False # High Power Mode if "Power set" bit is 0
except IOError as err:
print "Error: unable to open file: %s" % str(err)
print("Error: unable to open file: %s" % str(err))
return False
finally:
if eeprom is not None:
@ -225,10 +225,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -238,7 +238,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as err:
print "Error: unable to open file: %s" % str(err)
print("Error: unable to open file: %s" % str(err))
return False
finally:
if eeprom is not None:
@ -248,19 +248,19 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
mod_rst_path = lp_mode_path + "module_reset_"
mod_rst_path = lp_mode_path + "module_reset_"
q = self.qsfp_sb_remap(port_num)
mod_rst_path = mod_rst_path + str(q)
try:
reg_file = open(mod_rst_path, 'r+', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('0')
time.sleep(1)
@ -271,31 +271,31 @@ class SfpUtil(SfpUtilBase):
@property
def _get_presence_bitmap(self):
nodes = []
nodes = []
order = self.update_i2c_order()
present_path = self.BASE_CPLD2_PATH.format(order)
nodes.append(present_path + "module_present_all")
present_path = self.BASE_CPLD3_PATH.format(order)
nodes.append(present_path + "module_present_all")
bitmap = ""
for node in nodes:
bitmap = ""
for node in nodes:
try:
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -303,8 +303,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -312,7 +311,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
fp_port = self._port_to_i2c_mapping[port][0]
mask = (1 << (fp_port - 1))
@ -323,7 +322,7 @@ class SfpUtil(SfpUtilBase):
else:
port_dict[port] = SFP_STATUS_INSERTED
# Update cache
# Update cache
self.data['present'] = reg_value
self.data['last'] = now
self.data['valid'] = 1
@ -333,17 +332,12 @@ class SfpUtil(SfpUtilBase):
return True, {}
return False, {}
def __init__(self):
eeprom_path = self.BASE_OOM_PATH + "eeprom"
for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][1]
)
)
SfpUtilBase.__init__(self)

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -10,7 +10,7 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
@ -29,9 +29,9 @@ class SfpUtil(SfpUtilBase):
BASE_CPLD_PATH = "/sys/bus/i2c/devices/{0}-0060/"
I2C_BUS_ORDER = -1
#The sidebands of QSFP is different.
#present is in-order.
#But lp_mode and reset are not.
# The sidebands of QSFP is different.
# present is in-order.
# But lp_mode and reset are not.
qsfp_sb_map = [0, 2, 4, 1, 3, 5]
_port_to_is_present = {}
@ -39,13 +39,13 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
49: [1,4],#QSFP_start
50: [2,6],
51: [3,3],
52: [4,5],
53: [5,7],
54: [6,2],
}
49: [1, 4], # QSFP_start
50: [2, 6],
51: [3, 3],
52: [4, 5],
53: [5, 7],
54: [6, 2],
}
@property
def port_start(self):
@ -62,10 +62,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -77,10 +77,10 @@ class SfpUtil(SfpUtilBase):
for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][1]
)
)
SfpUtilBase.__init__(self)
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
def update_i2c_order(self):
if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
@ -89,7 +89,7 @@ class SfpUtil(SfpUtilBase):
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
return self.I2C_BUS_ORDER
return self.I2C_BUS_ORDER
def get_presence(self, port_num):
# Check for invalid port_num
@ -98,18 +98,18 @@ class SfpUtil(SfpUtilBase):
order = self.update_i2c_order()
present_path = self.BASE_CPLD_PATH.format(order)
present_path = present_path + "module_present_" + str(port_num)
present_path = present_path + "module_present_" + str(port_num)
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -118,21 +118,21 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode_cpld(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD_PATH.format(order)
lp_mode_path = lp_mode_path + "module_lp_mode_"
lp_mode_path = lp_mode_path + "module_lp_mode_"
lp_mode_path = lp_mode_path + str(port_num)
content="0"
content = "0"
try:
val_file = open(lp_mode_path)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
if content == "1":
return True
@ -141,7 +141,7 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return self.get_low_power_mode_cpld(port_num)
@ -151,15 +151,15 @@ class SfpUtil(SfpUtilBase):
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
return False # High Power Mode if "Power set" bit is 0
except IOError as err:
print "Error: unable to open file: %s" % str(err)
print("Error: unable to open file: %s" % str(err))
return False
finally:
if eeprom is not None:
@ -174,10 +174,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -187,7 +187,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as err:
print "Error: unable to open file: %s" % str(err)
print("Error: unable to open file: %s" % str(err))
return False
finally:
if eeprom is not None:
@ -197,20 +197,20 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD_PATH.format(order)
mod_rst_path = lp_mode_path + "module_reset_"
mod_rst_path = lp_mode_path + "module_reset_"
mod_rst_path = mod_rst_path + str(port_num)
print(mod_rst_path)
try:
reg_file = open(mod_rst_path, 'r+', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
@ -221,39 +221,39 @@ class SfpUtil(SfpUtilBase):
@property
def _get_presence_bitmap(self):
nodes = []
nodes = []
order = self.update_i2c_order()
present_path = self.BASE_CPLD_PATH.format(order)
nodes.append(present_path + "module_present_all")
bitmap = ""
for node in nodes:
bitmap = ""
for node in nodes:
try:
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'present': 0}
data = {'present':0}
def get_transceiver_change_event(self, timeout=2000):
port_dict = {}
port = 0
if timeout == 0:
cd_ms = sys.maxint
cd_ms = sys.maxsize
else:
cd_ms = timeout
#poll per second
# poll per second
while cd_ms > 0:
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
@ -263,7 +263,7 @@ class SfpUtil(SfpUtilBase):
cd_ms = cd_ms - 1000
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
fp_port = self._port_to_i2c_mapping[port][0]
mask = (1 << (fp_port - 1))
@ -274,7 +274,7 @@ class SfpUtil(SfpUtilBase):
else:
port_dict[port] = SFP_STATUS_INSERTED
# Update cache
# Update cache
self.data['present'] = reg_value
return True, port_dict

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -10,7 +10,7 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
@ -30,9 +30,9 @@ class SfpUtil(SfpUtilBase):
BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/"
I2C_BUS_ORDER = -1
#The sidebands of QSFP is different.
#present is in-order.
#But lp_mode and reset are not.
# The sidebands of QSFP is different.
# present is in-order.
# But lp_mode and reset are not.
qsfp_sb_map = [0, 2, 4, 1, 3, 5]
_port_to_is_present = {}
@ -40,61 +40,61 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
1: [1, 2],
2: [2, 3],
3: [3, 4],
4: [4, 5],
5: [5, 6],
6: [6, 7],
7: [7, 8],
8: [8, 9],
9: [9, 10],
10: [10,11],
11: [11,12],
12: [12,13],
13: [13,14],
14: [14,15],
15: [15,16],
16: [16,17],
17: [17,18],
18: [18,19],
19: [19,20],
20: [20,21],
21: [21,22],
22: [22,23],
23: [23,24],
24: [24,25],
25: [25,26],
26: [26,27],
27: [27,28],
28: [28,29],
29: [29,30],
30: [30,31],
31: [31,32],
32: [32,33],
33: [33,34],
34: [34,35],
35: [35,36],
36: [36,37],
37: [37,38],
38: [38,39],
39: [39,40],
40: [40,41],
41: [41,42],
42: [42,43],
43: [43,44],
44: [44,45],
45: [45,46],
46: [46,47],
47: [47,48],
48: [48,49],
49: [49,50],#QSFP_start
50: [51,52],
51: [53,54],
52: [50,51],
53: [52,53],
54: [54,55],
}
1: [1, 2],
2: [2, 3],
3: [3, 4],
4: [4, 5],
5: [5, 6],
6: [6, 7],
7: [7, 8],
8: [8, 9],
9: [9, 10],
10: [10, 11],
11: [11, 12],
12: [12, 13],
13: [13, 14],
14: [14, 15],
15: [15, 16],
16: [16, 17],
17: [17, 18],
18: [18, 19],
19: [19, 20],
20: [20, 21],
21: [21, 22],
22: [22, 23],
23: [23, 24],
24: [24, 25],
25: [25, 26],
26: [26, 27],
27: [27, 28],
28: [28, 29],
29: [29, 30],
30: [30, 31],
31: [31, 32],
32: [32, 33],
33: [33, 34],
34: [34, 35],
35: [35, 36],
36: [36, 37],
37: [37, 38],
38: [38, 39],
39: [39, 40],
40: [40, 41],
41: [41, 42],
42: [42, 43],
43: [43, 44],
44: [44, 45],
45: [45, 46],
46: [46, 47],
47: [47, 48],
48: [48, 49],
49: [49, 50], # QSFP_start
50: [51, 52],
51: [53, 54],
52: [50, 51],
53: [52, 53],
54: [54, 55],
}
@property
def port_start(self):
@ -111,10 +111,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -126,10 +126,10 @@ class SfpUtil(SfpUtilBase):
for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][1]
)
)
SfpUtilBase.__init__(self)
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
def update_i2c_order(self):
if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
@ -138,7 +138,7 @@ class SfpUtil(SfpUtilBase):
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
return self.I2C_BUS_ORDER
return self.I2C_BUS_ORDER
def get_presence(self, port_num):
# Check for invalid port_num
@ -147,22 +147,22 @@ class SfpUtil(SfpUtilBase):
order = self.update_i2c_order()
if port_num <= 24:
present_path = self.BASE_CPLD2_PATH.format(order)
present_path = self.BASE_CPLD2_PATH.format(order)
else:
present_path = self.BASE_CPLD3_PATH.format(order)
present_path = present_path + "module_present_" + str(port_num)
present_path = present_path + "module_present_" + str(port_num)
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -177,22 +177,22 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode_cpld(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
lp_mode_path = lp_mode_path + "module_lp_mode_"
lp_mode_path = lp_mode_path + "module_lp_mode_"
q = self.qsfp_sb_remap(port_num)
lp_mode_path = lp_mode_path + str(q)
content = "0"
try:
val_file = open(lp_mode_path)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
if content == "1":
return True
@ -201,7 +201,7 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return self.get_low_power_mode_cpld(port_num)
@ -212,15 +212,15 @@ class SfpUtil(SfpUtilBase):
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
return False # High Power Mode if "Power set" bit is 0
except IOError as err:
print "Error: unable to open file: %s" % str(err)
print("Error: unable to open file: %s" % str(err))
return False
finally:
if eeprom is not None:
@ -235,10 +235,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -248,7 +248,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as err:
print "Error: unable to open file: %s" % str(err)
print("Error: unable to open file: %s" % str(err))
return False
finally:
if eeprom is not None:
@ -258,20 +258,20 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
mod_rst_path = lp_mode_path + "module_reset_"
mod_rst_path = lp_mode_path + "module_reset_"
q = self.qsfp_sb_remap(port_num)
mod_rst_path = mod_rst_path + str(q)
try:
reg_file = open(mod_rst_path, 'r+', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('0')
time.sleep(1)
@ -282,31 +282,31 @@ class SfpUtil(SfpUtilBase):
@property
def _get_presence_bitmap(self):
nodes = []
nodes = []
order = self.update_i2c_order()
present_path = self.BASE_CPLD2_PATH.format(order)
nodes.append(present_path + "module_present_all")
present_path = self.BASE_CPLD3_PATH.format(order)
nodes.append(present_path + "module_present_all")
bitmap = ""
for node in nodes:
bitmap = ""
for node in nodes:
try:
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -314,8 +314,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -323,7 +322,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
fp_port = self._port_to_i2c_mapping[port][0]
mask = (1 << (fp_port - 1))
@ -334,7 +333,7 @@ class SfpUtil(SfpUtilBase):
else:
port_dict[port] = SFP_STATUS_INSERTED
# Update cache
# Update cache
self.data['present'] = reg_value
self.data['last'] = now
self.data['valid'] = 1
@ -343,4 +342,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -14,6 +14,7 @@ except ImportError as e:
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
@ -23,31 +24,31 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
49: 28, #QSFP49
50: 28,
51: 28,
52: 28,
53: 29, #QSFP50
54: 29,
55: 29,
56: 29,
57: 26, #QSFP51
58: 26,
59: 26,
60: 26,
61: 30, #QSFP52
62: 30,
63: 30,
64: 30,
65: 31, #QSFP53
66: 31,
67: 31,
68: 31,
69: 27, #QSFP54
70: 27,
71: 27,
72: 27,
}
49: 28, # QSFP49
50: 28,
51: 28,
52: 28,
53: 29, # QSFP50
54: 29,
55: 29,
56: 29,
57: 26, # QSFP51
58: 26,
59: 26,
60: 26,
61: 30, # QSFP52
62: 30,
63: 30,
64: 30,
65: 31, # QSFP53
66: 31,
67: 31,
68: 31,
69: 27, # QSFP54
70: 27,
71: 27,
72: 27,
}
@property
def port_start(self):
@ -64,10 +65,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -81,9 +82,9 @@ class SfpUtil(SfpUtilBase):
SfpUtilBase.__init__(self)
# For port 49~54 are QSFP, here presumed they're all split to 4 lanes.
def get_cage_num(self, port_num):
def get_cage_num(self, port_num):
cage_num = port_num
if (port_num >= self.PORT_START):
cage_num = (port_num - self.PORT_START)/4
@ -95,51 +96,51 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
cage_num = self.get_cage_num(port_num)
path = "/sys/bus/i2c/devices/3-0062/module_present_{0}"
port_ps = path.format(cage_num)
content="0"
content = "0"
try:
val_file = open(port_ps)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
return False
def get_low_power_mode_cpld(self, port_num):
def get_low_power_mode_cpld(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cage_num = self.get_cage_num(port_num)
path = "/sys/bus/i2c/devices/3-0062/module_lpmode_{0}"
lp_mode_path = path.format(cage_num)
try:
val_file = open(lp_mode_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
content = val_file.readline().rstrip()
val_file.close()
if content == "1":
return True
return False
def get_low_power_mode(self, port_num):
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return False
@ -150,15 +151,15 @@ class SfpUtil(SfpUtilBase):
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
return False # High Power Mode if "Power set" bit is 0
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -167,16 +168,16 @@ class SfpUtil(SfpUtilBase):
def set_low_power_mode(self, port_num, lpmode):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
return False
try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -186,7 +187,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -196,24 +197,24 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cage_num = self.get_cage_num(port_num)
path = "/sys/bus/i2c/devices/3-0062/module_reset_{0}"
port_ps = path.format(cage_num)
try:
reg_file = open(port_ps, mode="w", buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('0')
time.sleep(1)
reg_file.seek(0)
reg_file.write('1')
reg_file.close()
return True
@property
@ -223,31 +224,32 @@ class SfpUtil(SfpUtilBase):
try:
reg_file = open("/sys/bus/i2c/devices/3-0062/module_present_all")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev.pop() # Remove the last useless character
rev.pop() # Remove the last useless character
# Save port 49-54 into buffer
tmp = rev.pop()
# Insert port 1-48
for i in range (0, 6):
for i in range(0, 6):
rev.append(hex(0)[2:])
rev[i] = rev[i].zfill(2)
# Expand port 49-54
for i in range (0, 6):
val = (int(tmp,16) >> i) & 0x1
for i in range(0, 6):
val = (int(tmp, 16) >> i) & 0x1
rev.append(hex(val)[2:])
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'present': 0}
data = {'valid':0, 'present':0}
def get_transceiver_change_event(self, timeout=0):
start_time = time.time()
@ -258,17 +260,17 @@ class SfpUtil(SfpUtilBase):
if timeout == 0:
blocking = True
elif timeout > 0:
timeout = timeout / float(1000) # Convert to secs
timeout = timeout / float(1000) # Convert to secs
else:
print "get_transceiver_change_event:Invalid timeout value", timeout
print("get_transceiver_change_event:Invalid timeout value", timeout)
return False, {}
end_time = start_time + timeout
if start_time > end_time:
print 'get_transceiver_change_event:' \
'time wrap / invalid timeout value', timeout
print('get_transceiver_change_event:'
'time wrap / invalid timeout value', timeout)
return False, {} # Time wrap or possibly incorrect timeout
return False, {} # Time wrap or possibly incorrect timeout
while timeout >= 0:
# Check for OIR events and return updated port_dict
@ -276,7 +278,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:
@ -286,7 +288,7 @@ class SfpUtil(SfpUtilBase):
else:
port_dict[port] = SFP_STATUS_INSERTED
# Update cache
# Update cache
self.data['present'] = reg_value
self.data['valid'] = 1
return True, port_dict
@ -296,10 +298,10 @@ class SfpUtil(SfpUtilBase):
else:
timeout = end_time - time.time()
if timeout >= 1:
time.sleep(1) # We poll at 1 second granularity
time.sleep(1) # We poll at 1 second granularity
else:
if timeout > 0:
time.sleep(timeout)
return True, {}
print "get_transceiver_change_event: Should not reach here."
print("get_transceiver_change_event: Should not reach here.")
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -14,6 +14,7 @@ except ImportError as e:
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
@ -30,84 +31,84 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_cpld_mapping = {
0: "3-0060",
1: "3-0061",
2: "3-0062",
}
0: "3-0060",
1: "3-0061",
2: "3-0062",
}
_port_to_i2c_mapping = {
1: 42,
2: 43,
3: 44,
4: 45,
5: 46,
6: 47,
7: 48,
8: 49,
9: 50,
10: 51,
11: 52,
12: 53,
13: 54,
14: 55,
15: 56,
16: 57,
17: 58,
18: 59,
19: 60,
20: 61,
21: 62,
22: 63,
23: 64,
24: 65,
25: 66,
26: 67,
27: 68,
28: 69,
29: 70,
30: 71,
31: 72,
32: 73,
33: 74,
34: 75,
35: 76,
36: 77,
37: 78,
38: 79,
39: 80,
40: 81,
41: 82,
42: 83,
43: 84,
44: 85,
45: 86,
46: 87,
47: 88,
48: 89,
49: 28, #QSFP49
50: 28,
51: 28,
52: 28,
53: 29, #QSFP50
54: 29,
55: 29,
56: 29,
57: 26, #QSFP51
58: 26,
59: 26,
60: 26,
61: 30, #QSFP52
62: 30,
63: 30,
64: 30,
65: 31, #QSFP53
66: 31,
67: 31,
68: 31,
69: 27, #QSFP54
70: 27,
71: 27,
72: 27,
}
1: 42,
2: 43,
3: 44,
4: 45,
5: 46,
6: 47,
7: 48,
8: 49,
9: 50,
10: 51,
11: 52,
12: 53,
13: 54,
14: 55,
15: 56,
16: 57,
17: 58,
18: 59,
19: 60,
20: 61,
21: 62,
22: 63,
23: 64,
24: 65,
25: 66,
26: 67,
27: 68,
28: 69,
29: 70,
30: 71,
31: 72,
32: 73,
33: 74,
34: 75,
35: 76,
36: 77,
37: 78,
38: 79,
39: 80,
40: 81,
41: 82,
42: 83,
43: 84,
44: 85,
45: 86,
46: 87,
47: 88,
48: 89,
49: 28, # QSFP49
50: 28,
51: 28,
52: 28,
53: 29, # QSFP50
54: 29,
55: 29,
56: 29,
57: 26, # QSFP51
58: 26,
59: 26,
60: 26,
61: 30, # QSFP52
62: 30,
63: 30,
64: 30,
65: 31, # QSFP53
66: 31,
67: 31,
68: 31,
69: 27, # QSFP54
70: 27,
71: 27,
72: 27,
}
@property
def port_start(self):
@ -124,10 +125,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -141,9 +142,9 @@ class SfpUtil(SfpUtilBase):
SfpUtilBase.__init__(self)
# For port 49~54 are QSFP, here presumed they're all split to 4 lanes.
def get_cage_num(self, port_num):
def get_cage_num(self, port_num):
cage_num = port_num
if (port_num >= self.QSFP_PORT_START):
cage_num = (port_num - self.QSFP_PORT_START)/4
@ -152,14 +153,14 @@ class SfpUtil(SfpUtilBase):
return cage_num
# For cage 1~38 are at cpld2, others are at cpld3.
def get_cpld_num(self, port_num):
def get_cpld_num(self, port_num):
return 1 if (port_num < 39) else 2
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
cage_num = self.get_cage_num(port_num)
cpld_i = self.get_cpld_num(port_num)
@ -173,15 +174,15 @@ class SfpUtil(SfpUtilBase):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
return False
def get_low_power_mode_cpld(self, port_num):
def get_low_power_mode_cpld(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
@ -191,25 +192,25 @@ class SfpUtil(SfpUtilBase):
cpld_ps = self._cpld_mapping[cpld_i]
path = "/sys/bus/i2c/devices/{0}/module_lpmode_{1}"
lp_mode_path = path.format(cpld_ps, cage_num)
try:
val_file = open(lp_mode_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
content = val_file.readline().rstrip()
val_file.close()
if content == "1":
return True
return False
def get_low_power_mode(self, port_num):
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return False
@ -220,15 +221,15 @@ class SfpUtil(SfpUtilBase):
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
return False # High Power Mode if "Power set" bit is 0
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -237,16 +238,16 @@ class SfpUtil(SfpUtilBase):
def set_low_power_mode(self, port_num, lpmode):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
return False
try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -256,7 +257,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -266,7 +267,7 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cage_num = self.get_cage_num(port_num)
cpld_i = self.get_cpld_num(port_num)
cpld_ps = self._cpld_mapping[cpld_i]
@ -275,17 +276,17 @@ class SfpUtil(SfpUtilBase):
try:
reg_file = open(port_ps, mode='w', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('0')
time.sleep(1)
reg_file.seek(0)
reg_file.write('1')
reg_file.close()
return True
@property
@ -295,36 +296,37 @@ class SfpUtil(SfpUtilBase):
nodes.append("/sys/bus/i2c/devices/3-0062/module_present_all")
bitmap = ""
for node in nodes:
for node in nodes:
try:
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev.pop() # Remove the last useless character
rev.pop() # Remove the last useless character
# Convert bitmap into continuously port order
rev[4] = hex((int(rev[4],16) | ((int(rev[5],16) & 0x3) << 6)))[2:] # Port 33-40
rev[5] = hex((int(rev[5],16) >> 2) | ((int(rev[6],16) & 0x3) << 6))[2:] # Port 41-48
rev[4] = hex((int(rev[4], 16) | ((int(rev[5], 16) & 0x3) << 6)))[2:] # Port 33-40
rev[5] = hex((int(rev[5], 16) >> 2) | ((int(rev[6], 16) & 0x3) << 6))[2:] # Port 41-48
# Expand port 49-54
tmp = rev.pop()
for i in range (2, 8):
val = (int(tmp,16) >> i) & 0x1
for i in range(2, 8):
val = (int(tmp, 16) >> i) & 0x1
rev.append(hex(val)[2:])
for i in range (0,6):
for i in range(0, 6):
rev[i] = rev[i].zfill(2)
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'present': 0}
data = {'valid':0, 'present':0}
def get_transceiver_change_event(self, timeout=0):
start_time = time.time()
@ -335,17 +337,17 @@ class SfpUtil(SfpUtilBase):
if timeout == 0:
blocking = True
elif timeout > 0:
timeout = timeout / float(1000) # Convert to secs
timeout = timeout / float(1000) # Convert to secs
else:
print "get_transceiver_change_event:Invalid timeout value", timeout
print("get_transceiver_change_event:Invalid timeout value", timeout)
return False, {}
end_time = start_time + timeout
if start_time > end_time:
print 'get_transceiver_change_event:' \
'time wrap / invalid timeout value', timeout
print('get_transceiver_change_event:'
'time wrap / invalid timeout value', timeout)
return False, {} # Time wrap or possibly incorrect timeout
return False, {} # Time wrap or possibly incorrect timeout
while timeout >= 0:
# Check for OIR events and return updated port_dict
@ -353,7 +355,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:
@ -363,7 +365,7 @@ class SfpUtil(SfpUtilBase):
else:
port_dict[port] = SFP_STATUS_INSERTED
# Update cache
# Update cache
self.data['present'] = reg_value
self.data['valid'] = 1
return True, port_dict
@ -373,12 +375,10 @@ class SfpUtil(SfpUtilBase):
else:
timeout = end_time - time.time()
if timeout >= 1:
time.sleep(1) # We poll at 1 second granularity
time.sleep(1) # We poll at 1 second granularity
else:
if timeout > 0:
time.sleep(timeout)
return True, {}
print "get_transceiver_change_event: Should not reach here."
print("get_transceiver_change_event: Should not reach here.")
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -10,15 +7,16 @@ try:
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -12,7 +12,7 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
@ -36,39 +36,39 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
1: [1, 2],
2: [2, 3],
3: [3, 4],
4: [4, 5],
5: [5, 6],
6: [6, 7],
7: [7, 8],
8: [8, 9],
9: [9, 10],
10: [10, 11],
11: [11, 12],
12: [12, 13],
13: [13, 14],
14: [14, 15],
15: [15, 16],
16: [16, 17],
17: [17, 18],
18: [18, 19],
19: [19, 20],
20: [20, 21],
21: [21, 22],
22: [22, 23],
23: [23, 24],
24: [24, 25],
25: [25, 26],
26: [26, 27],
27: [27, 28],
28: [28, 29],
29: [29, 30],
30: [30, 31],
31: [31, 32],
32: [32, 33],
}
1: [1, 2],
2: [2, 3],
3: [3, 4],
4: [4, 5],
5: [5, 6],
6: [6, 7],
7: [7, 8],
8: [8, 9],
9: [9, 10],
10: [10, 11],
11: [11, 12],
12: [12, 13],
13: [13, 14],
14: [14, 15],
15: [15, 16],
16: [16, 17],
17: [17, 18],
18: [18, 19],
19: [19, 20],
20: [20, 21],
21: [21, 22],
22: [22, 23],
23: [23, 24],
24: [24, 25],
25: [25, 26],
26: [26, 27],
27: [27, 28],
28: [28, 29],
29: [29, 30],
30: [30, 31],
31: [31, 32],
32: [32, 33],
}
@property
def port_start(self):
@ -85,10 +85,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -100,7 +100,7 @@ class SfpUtil(SfpUtilBase):
for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][1]
)
)
SfpUtilBase.__init__(self)
def get_cpld_dev_path(self, port_num):
@ -108,65 +108,64 @@ class SfpUtil(SfpUtilBase):
cpld_num = 0
else:
cpld_num = 1
#cpld can be at either bus 0 or bus 1.
# cpld can be at either bus 0 or bus 1.
cpld_path = self.I2C_DEV_PATH + str(0) + self.CPLD_ADDRESS[cpld_num]
if not os.path.exists(cpld_path):
if not os.path.exists(cpld_path):
cpld_path = self.I2C_DEV_PATH + str(1) + self.CPLD_ADDRESS[cpld_num]
return cpld_path
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
cpld_path = self.get_cpld_dev_path(port_num)
present_path = cpld_path + "/module_present_"
present_path = cpld_path + "/module_present_"
present_path += str(self._port_to_i2c_mapping[port_num][0])
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
return False
def get_low_power_mode_cpld(self, port_num):
def get_low_power_mode_cpld(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cpld_path = self.get_cpld_dev_path(port_num)
_path = cpld_path + "/module_lp_mode_"
_path = cpld_path + "/module_lp_mode_"
_path += str(self._port_to_i2c_mapping[port_num][0])
content="0"
content = "0"
try:
reg_file = open(_path)
content = reg_file.readline().rstrip()
reg_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
return False
def get_low_power_mode(self, port_num):
def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
if not self.get_presence(port_num):
return False
@ -177,15 +176,15 @@ class SfpUtil(SfpUtilBase):
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if not (lpmode & 0x1): # 'Power override' bit is 0
if not (lpmode & 0x1): # 'Power override' bit is 0
return self.get_low_power_mode_cpld(port_num)
else:
if ((lpmode & 0x2) == 0x2):
return True # Low Power Mode if "Power set" bit is 1
return True # Low Power Mode if "Power set" bit is 1
else:
return False # High Power Mode if "Power set" bit is 0
return False # High Power Mode if "Power set" bit is 0
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -194,16 +193,16 @@ class SfpUtil(SfpUtilBase):
def set_low_power_mode(self, port_num, lpmode):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
return False
try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -213,7 +212,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -223,15 +222,15 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cpld_path = self.get_cpld_dev_path(port_num)
_path = cpld_path + "/module_reset_"
_path = cpld_path + "/module_reset_"
_path += str(self._port_to_i2c_mapping[port_num][0])
try:
reg_file = open(_path, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_file.seek(0)
@ -240,7 +239,7 @@ class SfpUtil(SfpUtilBase):
reg_file.seek(0)
reg_file.write('0')
reg_file.close()
return True
@property
@ -258,17 +257,17 @@ class SfpUtil(SfpUtilBase):
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -276,8 +275,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -285,7 +283,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self.get_transceiver_status
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
fp_port = self._port_to_i2c_mapping[port][0]
mask = (1 << (fp_port - 1))
@ -305,5 +303,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,11 +8,13 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -20,12 +20,12 @@ class PsuUtil(PsuBase):
def __init__(self):
PsuBase.__init__(self)
# Get sysfs attribute
def get_attr_value(self, attr_path):
retval = 'ERR'
retval = 'ERR'
if (not os.path.isfile(attr_path)):
return retval
@ -55,16 +55,16 @@ class PsuUtil(PsuBase):
faulty
"""
status = 0
attr_file = 'psu_power_good'
attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file
attr_file = 'psu_power_good'
attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file
attr_value = self.get_attr_value(attr_path)
if (attr_value != 'ERR'):
attr_value = int(attr_value, 16)
# Check for PSU status
if (attr_value == 1):
status = 1
status = 1
return status
@ -77,16 +77,15 @@ class PsuUtil(PsuBase):
"""
status = 0
psu_absent = 0
attr_file ='psu_present'
attr_path = self.SYSFS_PSU_DIR[index-1] +'/' + attr_file
attr_file = 'psu_present'
attr_path = self.SYSFS_PSU_DIR[index-1] + '/' + attr_file
attr_value = self.get_attr_value(attr_path)
if (attr_value != 'ERR'):
attr_value = int(attr_value, 16)
# Check for PSU presence
if (attr_value == 1):
status = 1
status = 1
return status

Просмотреть файл

@ -1,14 +1,13 @@
#!/usr/bin/env python
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
class SfpUtil(SfpUtilBase):
"""Platform specific SfpUtill class"""
@ -19,63 +18,63 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
0 : 37,
1 : 38,
2 : 39,
3 : 40,
4 : 41,
5 : 42,
6 : 43,
7 : 44,
8 : 45,
9 : 46,
10 : 47,
11 : 48,
12 : 49,
13 : 50,
14 : 51,
15 : 52,
16 : 53,
17 : 54,
18 : 55,
19 : 56,
20 : 57,
21 : 58,
22 : 59,
23 : 60,
24 : 61,
25 : 62,
26 : 63,
27 : 64,
28 : 65,
29 : 66,
30 : 67,
31 : 68,
32 : 69,
33 : 70,
34 : 71,
35 : 72,
36 : 73,
37 : 74,
38 : 75,
39 : 76,
40 : 77,
41 : 78,
42 : 79,
43 : 80,
44 : 81,
45 : 82,
46 : 83,
47 : 84,
48 : 21,
49 : 22,
50 : 23,
51 : 24,
52 : 25,
53 : 26,
0: 37,
1: 38,
2: 39,
3: 40,
4: 41,
5: 42,
6: 43,
7: 44,
8: 45,
9: 46,
10: 47,
11: 48,
12: 49,
13: 50,
14: 51,
15: 52,
16: 53,
17: 54,
18: 55,
19: 56,
20: 57,
21: 58,
22: 59,
23: 60,
24: 61,
25: 62,
26: 63,
27: 64,
28: 65,
29: 66,
30: 67,
31: 68,
32: 69,
33: 70,
34: 71,
35: 72,
36: 73,
37: 74,
38: 75,
39: 76,
40: 77,
41: 78,
42: 79,
43: 80,
44: 81,
45: 82,
46: 83,
47: 84,
48: 21,
49: 22,
50: 23,
51: 24,
52: 25,
53: 26,
}
_qsfp_ports = range(_qsfp_port_start, _ports_in_block + 1)
_qsfp_ports = list(range(_qsfp_port_start, _ports_in_block + 1))
_present_status = dict()
@ -83,27 +82,27 @@ class SfpUtil(SfpUtilBase):
eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom'
for x in range(self._port_start, self._port_end + 1):
port_eeprom_path = eeprom_path.format(self._port_to_i2c_mapping[x])
self._port_to_eeprom_mapping[x] = port_eeprom_path
self._port_to_eeprom_mapping[x] = port_eeprom_path
self._present_status[x] = SFP_STATUS_REMOVED
SfpUtilBase.__init__(self)
def reset(self, port_num):
# Check for invalid port_num
if port_num < self._qsfp_port_start or port_num > self._port_end:
print "Error: port %d is not qsfp port" % port_num
print("Error: port %d is not qsfp port" % port_num)
return False
path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset"
port_ps = path.format(self._port_to_i2c_mapping[port_num])
try:
reg_file = open(port_ps, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
@ -132,14 +131,14 @@ class SfpUtil(SfpUtilBase):
reg_value = reg_file.readline().rstrip()
reg_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if reg_value == '1':
return True
return False
def get_transceiver_change_event(self, timeout=0):
raise NotImplementedError
@ -155,19 +154,18 @@ class SfpUtil(SfpUtilBase):
def qsfp_ports(self):
return self._qsfp_ports
@property
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
return self._port_to_eeprom_mapping
def get_transceiver_change_event(self, timeout=0):
ret_present = dict()
for phy_port in range(self._port_start, self._port_end + 1):
last_present_status = SFP_STATUS_INSERTED if self.get_presence(phy_port) else SFP_STATUS_REMOVED
if self._present_status[phy_port] != last_present_status:
ret_present[phy_port] = last_present_status
self._present_status[phy_port] = last_present_status
time.sleep(2)
return True, ret_present
ret_present[phy_port] = last_present_status
self._present_status[phy_port] = last_present_status
time.sleep(2)
return True, ret_present

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
#
# Module contains an implementation of SONiC Platform Base API and
@ -32,7 +30,7 @@ NUM_SFP = 54
SFP_PORT_START = 0
QSFP_PORT_START = 48
SFP_PORT_END = 47
QSFP_PORT_END=53
QSFP_PORT_END = 53
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/"
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
REBOOT_CAUSE_FILE = "reboot-cause.txt"

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Component contains an implementation of SONiC Platform Base API and
# provides the components firmware management function
@ -18,6 +16,7 @@ except ImportError as e:
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version"
class Component(DeviceBase):
"""Platform-specific Component class"""
@ -31,7 +30,7 @@ class Component(DeviceBase):
# Run bash command and print output to stdout
try:
process = subprocess.Popen(
shlex.split(command), stdout=subprocess.PIPE)
shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
@ -11,10 +9,14 @@ try:
import glob
import os
import sys
import imp
import re
from array import array
from cStringIO import StringIO
if sys.version_info.major == 3:
from io import StringIO
else:
from cStringIO import StringIO
from sonic_platform_base.sonic_eeprom import eeprom_dts
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
except ImportError as e:

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
#
# Module contains an implementation of SONiC Platform Base API and
@ -21,6 +19,7 @@ FANTRAY_NAME_LIST = ["FANTRAY-1", "FANTRAY-2",
"FANTRAY-3", "FANTRAY-4", "FANTRAY-5"]
FAN_NAME_LIST = ["front", "rear"]
class Fan(FanBase):
"""Platform-specific Fan class"""
@ -67,7 +66,7 @@ class Fan(FanBase):
"""
direction = self.FAN_DIRECTION_EXHAUST
fan_direction_file = (FAN_PATH +
self.fan_direction.format(self.fan_tray_index+1))
self.fan_direction.format(self.fan_tray_index+1))
raw = self.__read_txt_file(fan_direction_file).strip('\r\n')
direction = self.FAN_DIRECTION_INTAKE if str(
raw).upper() == "1" else self.FAN_DIRECTION_EXHAUST
@ -84,7 +83,7 @@ class Fan(FanBase):
speed = 0
if self.get_presence():
fan_speed_file = (FAN_PATH +
self.fan_speed_rpm.format(self.fan_tray_index+1,FAN_NAME_LIST[self.fan_index]))
self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index]))
speed = self.__read_txt_file(fan_speed_file).strip('\r\n')
return int(speed)
@ -98,9 +97,9 @@ class Fan(FanBase):
"""
target = 0
if self.get_presence():
fan_speed_file=(FAN_PATH +
self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index]))
target=self.__read_txt_file(fan_speed_file).strip('\r\n')
fan_speed_file = (FAN_PATH +
self.fan_speed_rpm.format(self.fan_tray_index+1, FAN_NAME_LIST[self.fan_index]))
target = self.__read_txt_file(fan_speed_file).strip('\r\n')
return target

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Module contains an implementation of SONiC Platform Base API and
# provides the platform information
@ -12,6 +10,7 @@ try:
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class Platform(PlatformBase):
"""Platform-specific Platform class"""

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# psuutil.py
# Platform-specific PSU status interface for SONiC
@ -17,6 +15,7 @@ except ImportError as e:
FAN_MAX_RPM = 9600
PSU_NAME_LIST = ["PSU-0", "PSU-1"]
class Psu(PsuBase):
"""Platform-specific Psu class"""
@ -27,7 +26,6 @@ class Psu(PsuBase):
self.index = psu_index
PsuBase.__init__(self)
def get_fan(self):
"""
Retrieves object representing the fan module contained in this PSU
@ -73,8 +71,8 @@ class Psu(PsuBase):
Returns:
bool: True if PSU is present, False if not
"""
attr_file ='psu_present'
attr_path = self.SYSFS_PSU_DIR[self.index-1] +'/' + attr_file
attr_file = 'psu_present'
attr_path = self.SYSFS_PSU_DIR[self.index-1] + '/' + attr_file
status = 0
try:
with open(attr_path, 'r') as psu_prs:
@ -91,11 +89,11 @@ class Psu(PsuBase):
A boolean value, True if device is operating properly, False if not
"""
attr_file = 'psu_power_good'
attr_path = self.SYSFS_PSU_DIR[self.index-1] +'/' + attr_file
attr_path = self.SYSFS_PSU_DIR[self.index-1] + '/' + attr_file
status = 0
try:
with open(attr_path, 'r') as power_status:
status = int(power_status.read())
with open(attr_path, 'r') as power_status:
status = int(power_status.read())
except IOError:
return False

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Sfp contains an implementation of SONiC Platform Base API and
# provides the sfp device status which are available in the platform
@ -105,6 +103,7 @@ qsfp_compliance_code_tup = ('10/40G Ethernet Compliance Code', 'SONET Compliance
'Fibre Channel link length/Transmitter Technology',
'Fibre Channel transmission media', 'Fibre Channel Speed')
class Sfp(SfpBase):
"""Platform-specific Sfp class"""
@ -168,7 +167,7 @@ class Sfp(SfpBase):
52: 25,
53: 26,
}
_sfp_port = range(48, PORT_END + 1)
_sfp_port = list(range(48, PORT_END + 1))
RESET_PATH = "/sys/bus/i2c/devices/{}-0050/sfp_port_reset"
PRS_PATH = "/sys/bus/i2c/devices/{}-0050/sfp_is_present"
@ -180,7 +179,7 @@ class Sfp(SfpBase):
HWSKU = "Accton-AS7116-54X-R0"
def __init__(self, sfp_index, sfp_type):
# Init index
# Init index
self.index = sfp_index
self.port_num = self.index + 1
self.sfp_type = sfp_type

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,10 +1,8 @@
#!/usr/bin/env python
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class sfputil(SfpUtilBase):
@ -16,41 +14,41 @@ class sfputil(SfpUtilBase):
port_to_eeprom_mapping = {}
port_to_i2c_mapping = {
9 : 18,
10 : 19,
11 : 20,
12 : 21,
1 : 22,
2 : 23,
3 : 24,
4 : 25,
6 : 26,
5 : 27,
8 : 28,
7 : 29,
13 : 30,
14 : 31,
15 : 32,
16 : 33,
17 : 34,
18 : 35,
19 : 36,
20 : 37,
25 : 38,
26 : 39,
27 : 40,
28 : 41,
29 : 42,
30 : 43,
31 : 44,
32 : 45,
21 : 46,
22 : 47,
23 : 48,
24 : 49,
9: 18,
10: 19,
11: 20,
12: 21,
1: 22,
2: 23,
3: 24,
4: 25,
6: 26,
5: 27,
8: 28,
7: 29,
13: 30,
14: 31,
15: 32,
16: 33,
17: 34,
18: 35,
19: 36,
20: 37,
25: 38,
26: 39,
27: 40,
28: 41,
29: 42,
30: 43,
31: 44,
32: 45,
21: 46,
22: 47,
23: 48,
24: 49,
}
_qsfp_ports = range(0, ports_in_block + 1)
_qsfp_ports = list(range(0, ports_in_block + 1))
def __init__(self):
# Override port_to_eeprom_mapping for class initialization
@ -67,14 +65,14 @@ class sfputil(SfpUtilBase):
path = "/sys/bus/i2c/devices/{0}-0050/sfp_port_reset"
port_ps = path.format(self.port_to_i2c_mapping[port_num+1])
try:
reg_file = open(port_ps, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
@ -88,7 +86,7 @@ class sfputil(SfpUtilBase):
def get_low_power_mode(self, port_num):
raise NotImplementedErro
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
@ -103,9 +101,9 @@ class sfputil(SfpUtilBase):
reg_value = reg_file.readline().rstrip()
reg_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if reg_value == '1':
return True
@ -118,14 +116,14 @@ class sfputil(SfpUtilBase):
@property
def port_end(self):
return self._port_end
@property
def qsfp_ports(self):
return range(0, self.ports_in_block + 1)
return list(range(0, self.ports_in_block + 1))
@property
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
return self._port_to_eeprom_mapping
def get_transceiver_change_event(self):
"""

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -28,66 +28,66 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_cpld_mapping = {
0: "4-0060",
1: "5-0062",
2: "6-0064",
}
0: "4-0060",
1: "5-0062",
2: "6-0064",
}
_port_to_i2c_mapping = {
1: 18,
2: 19,
3: 20,
4: 21,
5: 22,
6: 23,
7: 24,
8: 25,
9: 26,
10: 27,
11: 28,
12: 29,
13: 30,
14: 31,
15: 32,
16: 33,
17: 34,
18: 35,
19: 36,
20: 37,
21: 38,
22: 39,
23: 40,
24: 41,
25: 42,
26: 43,
27: 44,
28: 45,
29: 46,
30: 47,
31: 48,
32: 49,
33: 50,
34: 51,
35: 52,
36: 53,
37: 54,
38: 55,
39: 56,
40: 57,
41: 58,
42: 59,
43: 60,
44: 61,
45: 62,
46: 63,
47: 64,
48: 65,
49: 66, #QSFP49
50: 67,
51: 68,
52: 69,
53: 70,
54: 71, #QSFP54
}
1: 18,
2: 19,
3: 20,
4: 21,
5: 22,
6: 23,
7: 24,
8: 25,
9: 26,
10: 27,
11: 28,
12: 29,
13: 30,
14: 31,
15: 32,
16: 33,
17: 34,
18: 35,
19: 36,
20: 37,
21: 38,
22: 39,
23: 40,
24: 41,
25: 42,
26: 43,
27: 44,
28: 45,
29: 46,
30: 47,
31: 48,
32: 49,
33: 50,
34: 51,
35: 52,
36: 53,
37: 54,
38: 55,
39: 56,
40: 57,
41: 58,
42: 59,
43: 60,
44: 61,
45: 62,
46: 63,
47: 64,
48: 65,
49: 66, # QSFP49
50: 67,
51: 68,
52: 69,
53: 70,
54: 71, # QSFP54
}
@property
def port_start(self):
@ -104,10 +104,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -121,12 +121,12 @@ class SfpUtil(SfpUtilBase):
SfpUtilBase.__init__(self)
def get_cpld_num(self, port_num):
def get_cpld_num(self, port_num):
cpld_i = 1
if (port_num > 24 and port_num < self.qsfp_port_start):
cpld_i = 2
if (port_num > 52):
if (port_num > 52):
cpld_i = 2
return cpld_i
@ -135,7 +135,7 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
cpld_i = self.get_cpld_num(port_num)
cpld_ps = self._cpld_mapping[cpld_i]
@ -148,9 +148,9 @@ class SfpUtil(SfpUtilBase):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -172,20 +172,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
@ -194,10 +195,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -207,7 +208,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -217,7 +218,7 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cpld_i = self.get_cpld_num(port_num)
cpld_ps = self._cpld_mapping[cpld_i]
path = "/sys/bus/i2c/devices/{0}/module_reset_{1}"
@ -225,14 +226,14 @@ class SfpUtil(SfpUtilBase):
try:
reg_file = open(port_ps, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_value = '0'
reg_file.write(reg_value)
reg_file.close()
return True
def get_transceiver_change_event(self):

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -28,66 +28,66 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_cpld_mapping = {
0: "4-0060",
1: "5-0062",
2: "6-0064",
}
0: "4-0060",
1: "5-0062",
2: "6-0064",
}
_port_to_i2c_mapping = {
1: 18,
2: 19,
3: 20,
4: 21,
5: 22,
6: 23,
7: 24,
8: 25,
9: 26,
10: 27,
11: 28,
12: 29,
13: 30,
14: 31,
15: 32,
16: 33,
17: 34,
18: 35,
19: 36,
20: 37,
21: 38,
22: 39,
23: 40,
24: 41,
25: 42,
26: 43,
27: 44,
28: 45,
29: 46,
30: 47,
31: 48,
32: 49,
33: 50,
34: 51,
35: 52,
36: 53,
37: 54,
38: 55,
39: 56,
40: 57,
41: 58,
42: 59,
43: 60,
44: 61,
45: 62,
46: 63,
47: 64,
48: 65,
49: 66, #QSFP49
50: 67,
51: 68,
52: 69,
53: 70,
54: 71, #QSFP54
}
1: 18,
2: 19,
3: 20,
4: 21,
5: 22,
6: 23,
7: 24,
8: 25,
9: 26,
10: 27,
11: 28,
12: 29,
13: 30,
14: 31,
15: 32,
16: 33,
17: 34,
18: 35,
19: 36,
20: 37,
21: 38,
22: 39,
23: 40,
24: 41,
25: 42,
26: 43,
27: 44,
28: 45,
29: 46,
30: 47,
31: 48,
32: 49,
33: 50,
34: 51,
35: 52,
36: 53,
37: 54,
38: 55,
39: 56,
40: 57,
41: 58,
42: 59,
43: 60,
44: 61,
45: 62,
46: 63,
47: 64,
48: 65,
49: 66, # QSFP49
50: 67,
51: 68,
52: 69,
53: 70,
54: 71, # QSFP54
}
@property
def port_start(self):
@ -104,10 +104,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -121,12 +121,12 @@ class SfpUtil(SfpUtilBase):
SfpUtilBase.__init__(self)
def get_cpld_num(self, port_num):
def get_cpld_num(self, port_num):
cpld_i = 1
if (port_num > 24 and port_num < self.qsfp_port_start):
cpld_i = 2
if (port_num > 52):
if (port_num > 52):
cpld_i = 2
return cpld_i
@ -135,7 +135,7 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
cpld_i = self.get_cpld_num(port_num)
cpld_ps = self._cpld_mapping[cpld_i]
@ -148,7 +148,7 @@ class SfpUtil(SfpUtilBase):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
# content is a string, either "0" or "1"
@ -173,20 +173,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
@ -195,10 +196,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -208,7 +209,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -218,7 +219,7 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
cpld_i = self.get_cpld_num(port_num)
cpld_ps = self._cpld_mapping[cpld_i]
path = "/sys/bus/i2c/devices/{0}/module_reset_{1}"
@ -226,14 +227,14 @@ class SfpUtil(SfpUtilBase):
try:
reg_file = open(port_ps, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_value = '0'
reg_file.write(reg_value)
reg_file.close()
return True
def get_transceiver_change_event(self):

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,11 +8,13 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/4-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -12,10 +12,11 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_REMOVED = '0'
SFP_STATUS_INSERTED = '1'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
@ -31,37 +32,37 @@ class SfpUtil(SfpUtilBase):
_port_to_lp_mode = {}
_port_to_eeprom_mapping = {}
_cpld_mapping = [ "8-0063", "7-0064"]
_cpld_mapping = ["8-0063", "7-0064"]
_port_to_i2c_mapping = {
1: 26,
2: 27,
3: 28,
4: 29,
5: 30,
6: 31,
7: 32,
8: 33,
9: 34,
10: 35,
11: 36,
12: 37,
13: 38,
14: 39,
15: 40,
16: 41,
17: 42,
18: 43,
19: 44,
20: 45,
21: 46,
22: 47,
23: 48,
24: 49,
25: 21, #QSFP
26: 22,
27: 23,
}
1: 26,
2: 27,
3: 28,
4: 29,
5: 30,
6: 31,
7: 32,
8: 33,
9: 34,
10: 35,
11: 36,
12: 37,
13: 38,
14: 39,
15: 40,
16: 41,
17: 42,
18: 43,
19: 44,
20: 45,
21: 46,
22: 47,
23: 48,
24: 49,
25: 21, # QSFP
26: 22,
27: 23,
}
@property
def port_start(self):
@ -78,10 +79,10 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_port_end(self):
return self.QSFP_PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -96,7 +97,7 @@ class SfpUtil(SfpUtilBase):
self.get_transceiver_change_event()
SfpUtilBase.__init__(self)
def get_cpld_num(self, port_num):
def get_cpld_num(self, port_num):
cpld_i = 0
if (port_num >= self.qsfp_port_start):
cpld_i = 1
@ -107,11 +108,11 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
cpld_i = self.get_cpld_num(port_num)
cpld_ps = self._cpld_mapping[cpld_i]
path = "/sys/bus/i2c/devices/{0}/present_{1}"
index = ((port_num-1)%24) +1
index = ((port_num-1) % 24) + 1
port_ps = path.format(cpld_ps, index)
content = "0"
@ -120,9 +121,9 @@ class SfpUtil(SfpUtilBase):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -144,20 +145,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False
@ -166,10 +168,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -179,7 +181,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -187,14 +189,14 @@ class SfpUtil(SfpUtilBase):
time.sleep(0.01)
def reset(self, port_num):
raise NotImplementedError
raise NotImplementedError
@property
def _get_present_bitmap(self):
nodes = []
port_num = [24,3]
port_num = [24, 3]
path = "/sys/bus/i2c/devices/{0}/"
path = "/sys/bus/i2c/devices/{0}/"
cpld_path = path.format(self._cpld_mapping[0])
nodes.append((cpld_path + "module_present_all", port_num[0]))
cpld_path = path.format(self._cpld_mapping[1])
@ -206,16 +208,17 @@ class SfpUtil(SfpUtilBase):
reg_file = open(node[0])
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
cpld_bm = reg_file.readline().rstrip().zfill(node[1]/4)
bitmap.append(cpld_bm)
reg_file.close()
rev = "".join(bitmap[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -223,7 +226,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -231,7 +234,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_present_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:
@ -249,5 +252,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,11 +8,13 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -11,10 +11,11 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_REMOVED = '0'
SFP_STATUS_INSERTED = '1'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
@ -31,69 +32,69 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
_cpld_mapping = {
1: "12-0062",
2: "18-0060",
3: "19-0064",
}
1: "12-0062",
2: "18-0060",
3: "19-0064",
}
_port_to_i2c_mapping = {
1: 42,
2: 41,
3: 44,
4: 43,
5: 47,
6: 45,
7: 46,
8: 50,
9: 48,
10: 49,
11: 52,
12: 51,
13: 53,
14: 56,
15: 55,
16: 54,
17: 58,
18: 57,
19: 60,
20: 59,
21: 61,
22: 63,
23: 62,
24: 64,
25: 66,
26: 68,
27: 65,
28: 67,
29: 69,
30: 71,
31: 72,
32: 70,
33: 74,
34: 73,
35: 76,
36: 75,
37: 77,
38: 79,
39: 78,
40: 80,
41: 81,
42: 82,
43: 84,
44: 85,
45: 83,
46: 87,
47: 88,
48: 86,
49: 25,#QSFP49
50: 26,
51: 27,
52: 28,
53: 29,
54: 30,
55: 31,
56: 32,#QSFP56
}
1: 42,
2: 41,
3: 44,
4: 43,
5: 47,
6: 45,
7: 46,
8: 50,
9: 48,
10: 49,
11: 52,
12: 51,
13: 53,
14: 56,
15: 55,
16: 54,
17: 58,
18: 57,
19: 60,
20: 59,
21: 61,
22: 63,
23: 62,
24: 64,
25: 66,
26: 68,
27: 65,
28: 67,
29: 69,
30: 71,
31: 72,
32: 70,
33: 74,
34: 73,
35: 76,
36: 75,
37: 77,
38: 79,
39: 78,
40: 80,
41: 81,
42: 82,
43: 84,
44: 85,
45: 83,
46: 87,
47: 88,
48: 86,
49: 25, # QSFP49
50: 26,
51: 27,
52: 28,
53: 29,
54: 30,
55: 31,
56: 32, # QSFP56
}
@property
def port_start(self):
@ -113,7 +114,7 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -145,13 +146,13 @@ class SfpUtil(SfpUtilBase):
path = "/sys/bus/i2c/devices/{0}/module_present_{1}"
port_ps = path.format(cpld_ps, port_num)
content="0"
content = "0"
try:
val_file = open(port_ps)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
@ -175,14 +176,15 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -198,10 +200,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -211,7 +213,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -226,28 +228,29 @@ class SfpUtil(SfpUtilBase):
cpld_ps = self._cpld_mapping[cpld_i]
path = "/sys/bus/i2c/devices/{0}/module_reset_{1}"
port_ps = path.format(cpld_ps, port_num)
self.__port_to_mod_rst = port_ps
try:
reg_file = open(self.__port_to_mod_rst, 'r+', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
reg_file.seek(0)
reg_file.write('0')
reg_file.close()
return True
@property
def _get_present_bitmap(self):
nodes = []
rev = []
port_num = [30,26]
port_num = [30, 26]
path = "/sys/bus/i2c/devices/{0}/module_present_all"
cpld_i = self.get_cpld_num(self.port_start)
@ -262,7 +265,7 @@ class SfpUtil(SfpUtilBase):
try:
reg_file = open(node[0])
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap = reg_file.readline().rstrip()
bitmap = bin(int(bitmap, 16))[2:].zfill(node[1])
@ -273,7 +276,8 @@ class SfpUtil(SfpUtilBase):
bitmaps = hex(int(bitmaps, 2))
return int(bitmaps, 0)
data = {'valid':0, 'last':0, 'present':0}
data = {'valid': 0, 'last': 0, 'present': 0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -281,7 +285,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -289,7 +293,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_present_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Cavium
#
@ -10,7 +8,6 @@
#############################################################################
try:
import exceptions
import binascii
import time
import optparse
@ -20,8 +17,9 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):

Просмотреть файл

@ -5,8 +5,8 @@ try:
import string
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class SfpUtil(SfpUtilBase):
@ -16,11 +16,10 @@ class SfpUtil(SfpUtilBase):
_port_end = 31
ports_in_block = 32
_port_to_eeprom_mapping = {}
_qsfp_ports = range(0, ports_in_block + 1)
_qsfp_ports = list(range(0, ports_in_block + 1))
def __init__(self):
# Override port_to_eeprom_mapping for class initialization
eeprom_path = '/sys/bus/i2c/devices/{0}-0050/sfp_eeprom'
@ -45,9 +44,9 @@ class SfpUtil(SfpUtilBase):
reg_value = reg_file.readline().rstrip()
reg_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if reg_value == '1':
return True
@ -63,7 +62,7 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
return range(0, self.ports_in_block + 1)
return list(range(0, self.ports_in_block + 1))
@property
def port_to_eeprom_mapping(self):
@ -93,20 +92,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
return False
@ -115,10 +115,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -128,9 +128,9 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
time.sleep(0.01)

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -1,14 +1,12 @@
#!/usr/bin/env python
try:
import time
import string
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
@ -22,41 +20,41 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
port_to_i2c_mapping = {
9 : 18,
10 : 19,
11 : 20,
12 : 21,
1 : 22,
2 : 23,
3 : 24,
4 : 25,
6 : 26,
5 : 27,
8 : 28,
7 : 29,
13 : 30,
14 : 31,
15 : 32,
16 : 33,
17 : 34,
18 : 35,
19 : 36,
20 : 37,
25 : 38,
26 : 39,
27 : 40,
28 : 41,
29 : 42,
30 : 43,
31 : 44,
32 : 45,
21 : 46,
22 : 47,
23 : 48,
24 : 49,
9: 18,
10: 19,
11: 20,
12: 21,
1: 22,
2: 23,
3: 24,
4: 25,
6: 26,
5: 27,
8: 28,
7: 29,
13: 30,
14: 31,
15: 32,
16: 33,
17: 34,
18: 35,
19: 36,
20: 37,
25: 38,
26: 39,
27: 40,
28: 41,
29: 42,
30: 43,
31: 44,
32: 45,
21: 46,
22: 47,
23: 48,
24: 49,
}
_qsfp_ports = range(0, ports_in_block + 1)
_qsfp_ports = list(range(0, ports_in_block + 1))
def __init__(self):
eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom'
@ -72,14 +70,14 @@ class SfpUtil(SfpUtilBase):
path = "/sys/bus/i2c/devices/4-0060/module_reset_{0}"
port_ps = path.format(port_num)
try:
reg_file = open(port_ps, 'w', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
@ -87,7 +85,7 @@ class SfpUtil(SfpUtilBase):
reg_file.write('0')
reg_file.close()
return True
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
@ -102,9 +100,9 @@ class SfpUtil(SfpUtilBase):
reg_value = reg_file.readline().rstrip()
reg_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if reg_value == '1':
return True
@ -117,14 +115,14 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self._port_end
@property
def qsfp_ports(self):
return range(self.port_start, self.ports_in_block + 1)
return list(range(self.port_start, self.ports_in_block + 1))
@property
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
return self._port_to_eeprom_mapping
def get_low_power_mode(self, port_num):
# Check for invalid port_num
@ -142,20 +140,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
return False
@ -164,10 +163,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -177,7 +176,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -197,16 +196,17 @@ class SfpUtil(SfpUtilBase):
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -214,7 +214,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -222,7 +222,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_all_presence
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:
@ -239,4 +239,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -10,7 +10,7 @@ try:
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_REMOVED = '0'
SFP_STATUS_INSERTED = '1'
@ -21,48 +21,48 @@ class SfpUtil(SfpUtilBase):
PORT_START = 1
PORT_END = 32
PORTS_IN_BLOCK = 32
BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/"
_port_to_is_present = {}
_port_to_lp_mode = {}
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
1: 29,
2: 30,
3: 31,
4: 32,
5: 34,
6: 33,
7: 36,
8: 35,
9: 25,
10: 26,
11: 27,
12: 28,
13: 37,
14: 38,
15: 39,
16: 40,
17: 41,
18: 42,
19: 43,
20: 44,
21: 53,
22: 54,
23: 55,
24: 56,
25: 45,
26: 46,
27: 47,
28: 48,
29: 49,
30: 50,
31: 51,
32: 52,
}
1: 29,
2: 30,
3: 31,
4: 32,
5: 34,
6: 33,
7: 36,
8: 35,
9: 25,
10: 26,
11: 27,
12: 28,
13: 37,
14: 38,
15: 39,
16: 40,
17: 41,
18: 42,
19: 43,
20: 44,
21: 53,
22: 54,
23: 55,
24: 56,
25: 45,
26: 46,
27: 47,
28: 48,
29: 49,
30: 50,
31: 51,
32: 52,
}
@property
def port_start(self):
@ -71,10 +71,10 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -83,17 +83,17 @@ class SfpUtil(SfpUtilBase):
def __init__(self):
eeprom_path = self.BASE_OOM_PATH + "eeprom"
for x in range(self.port_start, self.port_end+1):
for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x]
)
)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num)
self.__port_to_is_present = present_path
@ -103,9 +103,9 @@ class SfpUtil(SfpUtilBase):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -127,20 +127,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
@ -149,10 +150,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -162,7 +163,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -172,20 +173,20 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False
mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num)
self.__port_to_mod_rst = mod_rst_path
try:
reg_file = open(self.__port_to_mod_rst, 'r+')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_value = '1'
reg_file.write(reg_value)
reg_file.close()
return True
@property
@ -199,16 +200,17 @@ class SfpUtil(SfpUtilBase):
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -216,7 +218,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -224,7 +226,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self._get_present_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:
@ -241,4 +243,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -6,8 +6,8 @@
try:
import time
import os
import sys, getopt
import commands
import sys
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
@ -19,49 +19,49 @@ class SfpUtil(SfpUtilBase):
PORT_START = 0
PORT_END = 31
PORTS_IN_BLOCK = 32
BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
BASE_CPLD_PATH = "/sys/bus/i2c/devices/0-0060/"
BASE_I2C_PATH = "/sys/bus/i2c/devices/"
_port_to_is_present = {}
_port_to_lp_mode = {}
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
0: [1, 29],
1: [2, 30],
2: [3, 31],
3: [4, 32],
4: [5, 34],
5: [6, 33],
6: [7, 36],
7: [8, 35],
8: [9, 25],
9: [10, 26],
10: [11, 27],
11: [12, 28],
12: [14, 37],
13: [15, 38],
14: [16, 39],
15: [17, 40],
16: [18, 41],
17: [19, 42],
18: [20, 43],
19: [21, 44],
20: [22, 53],
21: [23, 54],
22: [24, 55],
23: [25, 56],
24: [26, 45],
25: [27, 46],
26: [28, 47],
27: [29, 48],
28: [30, 49],
29: [31, 50],
30: [32, 51],
31: [33, 52],
}
0: [1, 29],
1: [2, 30],
2: [3, 31],
3: [4, 32],
4: [5, 34],
5: [6, 33],
6: [7, 36],
7: [8, 35],
8: [9, 25],
9: [10, 26],
10: [11, 27],
11: [12, 28],
12: [14, 37],
13: [15, 38],
14: [16, 39],
15: [17, 40],
16: [18, 41],
17: [19, 42],
18: [20, 43],
19: [21, 44],
20: [22, 53],
21: [23, 54],
22: [24, 55],
23: [25, 56],
24: [26, 45],
25: [27, 46],
26: [28, 47],
27: [29, 48],
28: [30, 49],
29: [31, 50],
30: [32, 51],
31: [33, 52],
}
@property
def port_start(self):
@ -70,20 +70,20 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
def get_presence(self, port_num):
# Check for invalid port_num
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num+1)
self.__port_to_is_present = present_path
@ -93,47 +93,45 @@ class SfpUtil(SfpUtilBase):
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
return False
def __init__(self):
eeprom_path = self.BASE_I2C_PATH
eeprom_path = self.BASE_I2C_PATH
for x in range(0, self.port_end+1):
for x in range(0, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][1]
)
if(x < 9):
if(self.get_presence(x)==1):
self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" +str(x+1) + "/eeprom"
)
if(x < 9):
if(self.get_presence(x) == 1):
self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-000" + str(x+1) + "/eeprom"
else:
if(self.get_presence(x)==1):
self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" +str(x+1)+ "/eeprom"
if(self.get_presence(x) == 1):
self.port_to_eeprom_mapping[x] = self.BASE_I2C_PATH + "0-00" + str(x+1) + "/eeprom"
SfpUtilBase.__init__(self)
def get_low_power_mode(self, port_num):
raise NotImplementedError
def get_low_power_mode(self, port_num):
raise NotImplementedError
def set_low_power_mode(self, port_num, lpmode):
raise NotImplementedError
def reset(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False
mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1"
(status, output) = commands.getstatusoutput (mod_rst_cmd)
mod_rst_cmd = "ipmitool raw 0x34 0x11 " + str(port_num+1) + " 0x11 0x1"
subprocess.check_output(mod_rst_cmd, universal_newlines=True)
return True
def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -11,61 +11,61 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 1
PORT_END = 32 #34 cages actually, but last 2 are not at port_config.ini.
PORT_END = 32 # 34 cages actually, but last 2 are not at port_config.ini.
PORTS_IN_BLOCK = 32
BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
BASE_CPLD_PATH = "/sys/bus/i2c/devices/11-0060/"
_port_to_is_present = {}
_port_to_lp_mode = {}
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
1: 21,
2: 22,
3: 23,
4: 24,
5: 26,
6: 25,
7: 28,
8: 27,
9: 17,
10: 18,
11: 19,
12: 20,
13: 29,
14: 30,
15: 31,
16: 32,
17: 33,
18: 34,
19: 35,
20: 36,
21: 45,
22: 46,
23: 47,
24: 48,
25: 37,
26: 38,
27: 39,
28: 40,
29: 41,
30: 42,
31: 43,
32: 44,
33: 15,
34: 16,
}
1: 21,
2: 22,
3: 23,
4: 24,
5: 26,
6: 25,
7: 28,
8: 27,
9: 17,
10: 18,
11: 19,
12: 20,
13: 29,
14: 30,
15: 31,
16: 32,
17: 33,
18: 34,
19: 35,
20: 36,
21: 45,
22: 46,
23: 47,
24: 48,
25: 37,
26: 38,
27: 39,
28: 40,
29: 41,
30: 42,
31: 43,
32: 44,
33: 15,
34: 16,
}
@property
def port_start(self):
@ -74,10 +74,10 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -85,11 +85,11 @@ class SfpUtil(SfpUtilBase):
def __init__(self):
eeprom_path = self.BASE_OOM_PATH + "eeprom"
for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x]
)
)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
@ -100,15 +100,15 @@ class SfpUtil(SfpUtilBase):
present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num)
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
return True
@ -130,20 +130,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
@ -152,10 +153,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -165,7 +166,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -175,24 +176,24 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False
mod_rst_path = self.BASE_CPLD_PATH + "module_reset_" + str(port_num)
self.__port_to_mod_rst = mod_rst_path
try:
reg_file = open(self.__port_to_mod_rst, 'r+', buffering=0)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#toggle reset
# toggle reset
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
reg_file.seek(0)
reg_file.write('0')
reg_file.close()
return True
@property
@ -208,16 +209,17 @@ class SfpUtil(SfpUtilBase):
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -225,8 +227,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -234,7 +235,7 @@ class SfpUtil(SfpUtilBase):
reg_value = self.get_transceiver_status
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
fp_port = port
mask = (1 << (fp_port - 1))
@ -253,4 +254,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,11 +8,13 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -1,17 +1,16 @@
#!/usr/bin/env python
try:
import time
import string
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
#from xcvrd
# from xcvrd
SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'
class SfpUtil(SfpUtilBase):
"""Platform specific SfpUtill class"""
@ -21,72 +20,72 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
port_to_i2c_mapping = {
61 : 25,
62 : 26,
63 : 27,
64 : 28,
55 : 29,
56 : 30,
53 : 31,
54 : 32,
9 : 33,
10 : 34,
11 : 35,
12 : 36,
1 : 37,
2 : 38,
3 : 39,
4 : 40,
6 : 41,
5 : 42,
8 : 43,
7 : 44,
13 : 45,
14 : 46,
15 : 47,
16 : 48,
17 : 49,
18 : 50,
19 : 51,
20 : 52,
25 : 53,
26 : 54,
27 : 55,
28 : 56,
29 : 57,
30 : 58,
31 : 59,
32 : 60,
21 : 61,
22 : 62,
23 : 63,
24 : 64,
41 : 65,
42 : 66,
43 : 67,
44 : 68,
33 : 69,
34 : 70,
35 : 71,
36 : 72,
45 : 73,
46 : 74,
47 : 75,
48 : 76,
37 : 77,
38 : 78,
39 : 79,
40 : 80,
57 : 81,
58 : 82,
59 : 83,
60 : 84,
49 : 85,
50 : 86,
51 : 87,
52 : 88,}
61: 25,
62: 26,
63: 27,
64: 28,
55: 29,
56: 30,
53: 31,
54: 32,
9: 33,
10: 34,
11: 35,
12: 36,
1: 37,
2: 38,
3: 39,
4: 40,
6: 41,
5: 42,
8: 43,
7: 44,
13: 45,
14: 46,
15: 47,
16: 48,
17: 49,
18: 50,
19: 51,
20: 52,
25: 53,
26: 54,
27: 55,
28: 56,
29: 57,
30: 58,
31: 59,
32: 60,
21: 61,
22: 62,
23: 63,
24: 64,
41: 65,
42: 66,
43: 67,
44: 68,
33: 69,
34: 70,
35: 71,
36: 72,
45: 73,
46: 74,
47: 75,
48: 76,
37: 77,
38: 78,
39: 79,
40: 80,
57: 81,
58: 82,
59: 83,
60: 84,
49: 85,
50: 86,
51: 87,
52: 88, }
_qsfp_ports = range(0, ports_in_block + 1)
_qsfp_ports = list(range(0, ports_in_block + 1))
def __init__(self):
eeprom_path = '/sys/bus/i2c/devices/{0}-0050/eeprom'
@ -99,21 +98,21 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}"
path = "/sys/bus/i2c/devices/19-0060/module_reset_{0}"
port_ps = path.format(port_num)
try:
reg_file = open(port_ps, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
#HW will clear reset after set.
# HW will clear reset after set.
reg_file.seek(0)
reg_file.write('1')
reg_file.close()
return True
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
@ -121,16 +120,16 @@ class SfpUtil(SfpUtilBase):
path = "/sys/bus/i2c/devices/19-0060/module_present_{0}"
port_ps = path.format(port_num)
reg_value = '0'
try:
reg_file = open(port_ps)
reg_value = reg_file.readline().rstrip()
reg_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if reg_value == '1':
return True
@ -143,14 +142,14 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self._port_end
@property
def qsfp_ports(self):
return range(0, self.ports_in_block + 1)
return list(range(0, self.ports_in_block + 1))
@property
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
return self._port_to_eeprom_mapping
def get_low_power_mode(self, port_num):
# Check for invalid port_num
@ -168,20 +167,21 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
return False
@ -190,10 +190,10 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -203,7 +203,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -223,17 +223,17 @@ class SfpUtil(SfpUtilBase):
reg_file = open(node)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
bitmap += reg_file.readline().rstrip() + " "
reg_file.close()
rev = bitmap.split(" ")
rev = "".join(rev[::-1])
return int(rev,16)
return int(rev, 16)
data = {'valid': 0, 'last': 0, 'present': 0}
data = {'valid':0, 'last':0, 'present':0}
def get_transceiver_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
@ -241,7 +241,7 @@ class SfpUtil(SfpUtilBase):
if timeout < 1000:
timeout = 1000
timeout = (timeout) / float(1000) # Convert to secs
timeout = (timeout) / float(1000) # Convert to secs
if now < (self.data['last'] + timeout) and self.data['valid']:
return True, {}
@ -250,7 +250,7 @@ class SfpUtil(SfpUtilBase):
reg_value = ~reg_value
changed_ports = self.data['present'] ^ reg_value
if changed_ports:
for port in range (self.port_start, self.port_end+1):
for port in range(self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - 1))
if changed_ports & mask:
@ -267,4 +267,3 @@ class SfpUtil(SfpUtilBase):
else:
return True, {}
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,24 +8,26 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
def eeprom_check():
filepath="/sys/bus/i2c/devices/0-0057/eeprom"
filepath = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.isfile(filepath):
return 1 #now board, 0x57
return 1 # now board, 0x57
else:
return 0 #now board, 0x56
return 0 # now board, 0x56
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
ret=eeprom_check()
if ret==1:
ret = eeprom_check()
if ret == 1:
self.eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
else:
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -6,7 +6,7 @@
try:
import time
import os
import sys, getopt
import sys
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
@ -15,55 +15,55 @@ except ImportError as e:
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 33
PORTS_IN_BLOCK = 34
BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
BASE_CPLD1_PATH = "/sys/bus/i2c/devices/20-0061/"
BASE_CPLD2_PATH = "/sys/bus/i2c/devices/21-0062/"
_port_to_is_present = {}
_port_to_lp_mode = {}
_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
0: [1, 25],
1: [2, 26],
2: [3, 27],
3: [4, 28],
4: [5, 29],
5: [6, 30],
6: [7, 31],
7: [8, 32],
8: [9, 33],
9: [10, 34],
10: [11, 35],
11: [12, 36],
12: [13, 37],
13: [14, 38],
14: [15, 39],
15: [16, 40],
16: [17, 41],
17: [18, 42],
18: [19, 43],
19: [20, 44],
20: [21, 45],
21: [22, 46],
22: [23, 47],
23: [24, 48],
24: [25, 49],
25: [26, 50],
26: [27, 51],
27: [28, 52],
28: [29, 53],
29: [30, 54],
30: [31, 55],
31: [32, 56],
32: [33, 57],
33: [34, 58],
}
0: [1, 25],
1: [2, 26],
2: [3, 27],
3: [4, 28],
4: [5, 29],
5: [6, 30],
6: [7, 31],
7: [8, 32],
8: [9, 33],
9: [10, 34],
10: [11, 35],
11: [12, 36],
12: [13, 37],
13: [14, 38],
14: [15, 39],
15: [16, 40],
16: [17, 41],
17: [18, 42],
18: [19, 43],
19: [20, 44],
20: [21, 45],
21: [22, 46],
22: [23, 47],
23: [24, 48],
24: [25, 49],
25: [26, 50],
26: [27, 51],
27: [28, 52],
28: [29, 53],
29: [30, 54],
30: [31, 55],
31: [32, 56],
32: [33, 57],
33: [34, 58],
}
@property
def port_start(self):
@ -72,10 +72,10 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
@ -83,11 +83,11 @@ class SfpUtil(SfpUtilBase):
def __init__(self):
eeprom_path = self.BASE_OOM_PATH + "eeprom"
for x in range(0, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][1]
)
)
SfpUtilBase.__init__(self)
@ -95,19 +95,19 @@ class SfpUtil(SfpUtilBase):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
if port_num < 16 :
if port_num < 16:
present_path = self.BASE_CPLD1_PATH + "module_present_" + str(port_num+1)
else:
present_path = self.BASE_CPLD2_PATH + "module_present_" + str(port_num+1)
self.__port_to_is_present = present_path
content="0"
content = "0"
try:
val_file = open(self.__port_to_is_present)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print "Error: unable to access file: %s" % str(e)
print("Error: unable to access file: %s" % str(e))
return False
if content == "1":
@ -115,7 +115,7 @@ class SfpUtil(SfpUtilBase):
return False
def get_low_power_mode(self, port_num):
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
@ -131,19 +131,20 @@ class SfpUtil(SfpUtilBase):
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
return False # High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
@ -153,13 +154,13 @@ class SfpUtil(SfpUtilBase):
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return False # Port is not present, unable to set the eeprom
# Fill in write buffer
# 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1
# 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1
regval = 0x3 if lpmode else 0x9
# 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1
# 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1
regval = 0x3 if lpmode else 0x9
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
@ -169,7 +170,7 @@ class SfpUtil(SfpUtilBase):
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
@ -179,111 +180,111 @@ class SfpUtil(SfpUtilBase):
def reset(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False
if port_num < 16 :
if port_num < 16:
mod_rst_path = self.BASE_CPLD1_PATH + "module_reset_" + str(port_num+1)
else:
mod_rst_path = self.BASE_CPLD2_PATH + "module_reset_" + str(port_num+1)
self.__port_to_mod_rst = mod_rst_path
try:
reg_file = open(self.__port_to_mod_rst, 'r+')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_value = '1'
reg_file.write(reg_value)
reg_file.close()
return True
def get_cpld_interrupt(self):
port_dict={}
for i in range(0,4):
if i==0 or i==1:
port_dict = {}
for i in range(0, 4):
if i == 0 or i == 1:
cpld_i2c_path = self.BASE_CPLD1_PATH + "cpld_intr_" + str(i+1)
else:
cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" +str(i+1)
start_i=(i*8)
end_i=(i*8+8)
cpld_i2c_path = self.BASE_CPLD2_PATH + "cpld_intr_" + str(i+1)
start_i = (i*8)
end_i = (i*8+8)
try:
val_file = open(cpld_i2c_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
for k in range (start_i, end_i):
port_dict[k]=0
print("Error: unable to open file: %s" % str(e))
for k in range(start_i, end_i):
port_dict[k] = 0
return port_dict
status = val_file.readline().rstrip()
val_file.close()
status=status.strip()
status= int(status, 16)
interrupt_status = ~(status & 0xff)
status = status.strip()
status = int(status, 16)
interrupt_status = ~(status & 0xff)
if interrupt_status:
port_shift=0
for k in range (start_i, end_i):
if interrupt_status & (0x1<<port_shift):
port_dict[k]=1
port_shift = 0
for k in range(start_i, end_i):
if interrupt_status & (0x1 << port_shift):
port_dict[k] = 1
else:
port_dict[k]=0
port_shift=port_shift+1
port_dict[k] = 0
port_shift = port_shift+1
return port_dict
def get_transceiver_change_event(self, timeout=0):
start_time = time.time()
port_dict = {}
ori_present ={}
ori_present = {}
forever = False
if timeout == 0:
forever = True
elif timeout > 0:
timeout = timeout / float(1000) # Convert to secs
timeout = timeout / float(1000) # Convert to secs
else:
print "get_transceiver_change_event:Invalid timeout value", timeout
print("get_transceiver_change_event:Invalid timeout value", timeout)
return False, {}
end_time = start_time + timeout
if start_time > end_time:
print 'get_transceiver_change_event:' \
'time wrap / invalid timeout value', timeout
print('get_transceiver_change_event:'
'time wrap / invalid timeout value', timeout)
return False, {} # Time wrap or possibly incorrect timeout
#for i in range(self.port_start, self.port_end+1):
return False, {} # Time wrap or possibly incorrect timeout
# for i in range(self.port_start, self.port_end+1):
# ori_present[i]=self.get_presence(i)
while timeout >= 0:
change_status=0
while timeout >= 0:
change_status = 0
port_dict = self.get_cpld_interrupt()
present=0
for key, value in port_dict.iteritems():
if value==1:
present=self.get_presence(key)
change_status=1
present = 0
for key, value in port_dict.items():
if value == 1:
present = self.get_presence(key)
change_status = 1
if present:
port_dict[key]='1'
port_dict[key] = '1'
else:
port_dict[key]='0'
if change_status:
port_dict[key] = '0'
if change_status:
return True, port_dict
if forever:
time.sleep(1)
else:
timeout = end_time - time.time()
if timeout >= 1:
time.sleep(1) # We poll at 1 second granularity
time.sleep(1) # We poll at 1 second granularity
else:
if timeout > 0:
time.sleep(timeout)
return True, {}
print "get_evt_change_event: Should not reach here."
return False, {}
print("get_evt_change_event: Should not reach here.")
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,11 +8,13 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
super(board, self).__init__(self.eeprom_path, 0x200, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# led_control.py
#
# Platform-specific LED control functionality for SONiC
@ -17,19 +15,18 @@ try:
from socket import *
from select import *
from minipack.pimutil import PimUtil
except ImportError, e:
except ImportError as e:
raise ImportError(str(e) + " - required module not found")
class LedControl(LedControlBase):
"""Platform specific LED control class"""
SONIC_PORT_NAME_PREFIX = "Ethernet"
def __init__(self):
pim=PimUtil()
pim = PimUtil()
pim.init_pim_fpga()
def _port_name_to_index(self, port_name):
# Strip "Ethernet" off port name
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
@ -37,23 +34,22 @@ class LedControl(LedControlBase):
port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
return port_idx
def _port_state_to_mode(self, port_idx, state):
if state == "up":
return 1, 4 #port linkup, led is green
return 1, 4 # port linkup, led is green
else:
return 0, 0 #port linkdown, led is off
return 0, 0 # port linkdown, led is off
def port_link_state_change(self, portname, state):
pim=PimUtil()
pim = PimUtil()
port_idx = self._port_name_to_index(portname)
new_control, led_mode = self._port_state_to_mode(port_idx, state)
color, control=pim.get_port_led(port_idx)
if color==led_mode:
if control==new_control:
return
pim.set_port_led(port_idx, led_mode, new_control)#port linkup, led is green
#port linkdown, led is off
color, control = pim.get_port_led(port_idx)
if color == led_mode:
if control == new_control:
return
pim.set_port_led(port_idx, led_mode, new_control) # port linkup, led is green
# port linkdown, led is off

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Accton
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -7,20 +7,20 @@ try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
import os
import sys, getopt
from minipack.pimutil import PimUtil
import sys
from minipack.pimutil import PimUtil
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 128
LOCAL_OOM_PATH = "/usr/local/bin/minipack_qsfp/port%d_eeprom"
_port_to_is_present = {}
_port_to_lp_mode = {}
@ -33,10 +33,10 @@ class SfpUtil(SfpUtilBase):
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORT_END + 1)
return list(range(self.PORT_START, self.PORT_END + 1))
@property
def port_to_eeprom_mapping(self):
@ -47,100 +47,99 @@ class SfpUtil(SfpUtilBase):
base = ((port-1)/8*8) + 10
index = (port - 1) % 8
index = 7 - index
if (index%2):
index = index -1
if (index % 2):
index = index - 1
else:
index = index +1
index = index + 1
bus = base + index
return bus
def __init__(self):
for x in range(0, self.port_end):
self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH %x
for x in range(0, self.port_end):
self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH % x
SfpUtilBase.__init__(self)
pim=PimUtil()
pim = PimUtil()
pim.init_pim_fpga()
def __del__(self):
self.value=0
self.value = 0
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
pim=PimUtil()
status=pim.get_qsfp_presence(port_num)
pim = PimUtil()
status = pim.get_qsfp_presence(port_num)
return status
def get_low_power_mode(self, port_num):
def get_low_power_mode(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False
pim=PimUtil()
pim = PimUtil()
return pim.get_low_power_mode(port_num)
def set_low_power_mode(self, port_num, lpmode):
if port_num < self.port_start or port_num > self.port_end:
return False
pim=PimUtil()
pim.set_low_power_mode(port_num, lpmode)
return True
pim = PimUtil()
pim.set_low_power_mode(port_num, lpmode)
return True
def reset(self, port_num):
if port_num < self.port_start or port_num > self.port_end:
return False
pim=PimUtil()
pim = PimUtil()
pim.reset(port_num)
return True
return True
def get_transceiver_change_event(self, timeout=0):
pim=PimUtil()
pim = PimUtil()
start_time = time.time()
port_dict = {}
forever = False
if timeout == 0:
forever = True
elif timeout > 0:
timeout = timeout / float(1000) # Convert to secs
timeout = timeout / float(1000) # Convert to secs
else:
print "get_transceiver_change_event:Invalid timeout value", timeout
print("get_transceiver_change_event:Invalid timeout value", timeout)
return False, {}
end_time = start_time + timeout
if start_time > end_time:
print 'get_transceiver_change_event:' \
'time wrap / invalid timeout value', timeout
print('get_transceiver_change_event:'
'time wrap / invalid timeout value', timeout)
return False, {} # Time wrap or possibly incorrect timeout
while timeout >= 0:
change_status=0
return False, {} # Time wrap or possibly incorrect timeout
while timeout >= 0:
change_status = 0
port_dict = pim.get_qsfp_interrupt()
present=0
for key, value in port_dict.iteritems():
if value==1:
present=self.get_presence(key)
change_status=1
present = 0
for key, value in port_dict.items():
if value == 1:
present = self.get_presence(key)
change_status = 1
if present:
port_dict[key]='1'
port_dict[key] = '1'
else:
port_dict[key]='0'
if change_status:
port_dict[key] = '0'
if change_status:
return True, port_dict
if forever:
time.sleep(1)
else:
timeout = end_time - time.time()
if timeout >= 1:
time.sleep(1) # We poll at 1 second granularity
time.sleep(1) # We poll at 1 second granularity
else:
if timeout > 0:
time.sleep(timeout)
return True, {}
print "get_evt_change_event: Should not reach here."
print("get_evt_change_event: Should not reach here.")
return False, {}

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,22 +1,19 @@
#!/usr/bin/env python
#
# led_control.py
#
# Platform-specific LED control functionality for SONiC
#
# try:
# from sonic_led.led_control_base import LedControlBase
# import swsssdk
# except ImportError, e:
# except ImportError as e:
# raise ImportError (str(e) + " - required module not found")
import time
class LedControlBase(object):
# __metaclass__ = abc.ABCMeta
# @abc.abstractmethod
class LedControlBase(object):
# __metaclass__ = abc.ABCMeta
# @abc.abstractmethod
def port_link_state_change(self, port, state):
"""
Called when port link state changes. Update port link state LED here.
@ -26,6 +23,7 @@ class LedControlBase(object):
"""
return
### Zion specified ###
read_fan_fault = 0
is_fan_all_OK = 0
@ -35,126 +33,128 @@ is_thermal_high = 0
is_reset_button_push = 0
##########################
def sysled_task():
while True:
system_led_check()
time.sleep(5)
### Zion specified ###
def system_led_check():
global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push
is_fan_all_OK = 1
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push
is_fan_all_OK = 1
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/1-005e/fan1_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan1_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan2_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan2_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan3_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan3_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan4_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan4_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan5_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan5_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/fan6_fault", "r") as f1:
read_fan_fault = f1.read()
with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f11:
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
f11.write("4")
else:
f11.write("1")
with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu1_power_good", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu1_present", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu2_power_good", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/1-005e/psu2_present", "r") as f1:
read_power_status = f1.read()
with open("/sys/bus/i2c/devices/9-005f/sys_pwr", "w") as f11:
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5:
is_reset_button_push = f5.read()
if str(is_reset_button_push) == "1\n":
is_reset_button_push = 1
else:
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/9-005f/swi_ctrl", "r") as f5:
is_reset_button_push = f5.read()
if str(is_reset_button_push) == "1\n":
is_reset_button_push = 1
else:
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3:
is_thermal_high = f3.read()
if int(is_thermal_high) >= 70000:
is_thermal_high = 1
else:
is_thermal_high = 0
with open("/sys/bus/i2c/devices/4-004d/hwmon/hwmon3/temp1_input", "r") as f3:
is_thermal_high = f3.read()
if int(is_thermal_high) >= 70000:
is_thermal_high = 1
else:
is_thermal_high = 0
with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2:
if is_reset_button_push == 1:
f2.write("3")
elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1:
f2.write("4")
else:
f2.write("1")
with open("/sys/bus/i2c/devices/9-005f/sys_status", "w") as f2:
if is_reset_button_push == 1:
f2.write("3")
elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1:
f2.write("4")
else:
f2.write("1")
return
return
##########
class LedControl(LedControlBase):
"""Platform specific LED control class"""
PORT_TABLE_PREFIX = "PORT_TABLE:"
@ -184,17 +184,18 @@ class LedControl(LedControlBase):
swss = swsssdk.SonicV2Connector()
swss.connect(swss.APPL_DB)
lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
lanes = swss.get(
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
# SONiC port nums are 0-based and increment by 4
# Arista QSFP indices are 1-based and increment by 1
return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(',')))
return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(',')))
# Concrete implementation of port_link_state_change() method
def port_link_state_change_bk(self, port, state):
qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port)
# Ignore invalid QSFP indices
if qsfp_index <= 0 or lanes <= 0 or lanes > 4:
return
@ -203,9 +204,11 @@ class LedControl(LedControlBase):
# whereas indices 25-32 are not breakout-capable, and only have one
if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
# assuming 40G, then we need to control four lanes
led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ]
led_sysfs_paths = [self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(
qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes)]
else:
led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ]
led_sysfs_paths = [
self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)]
for led_sysfs_path in led_sysfs_paths:
led_file = open(led_sysfs_path, "w")
@ -240,7 +243,7 @@ class LedControl(LedControlBase):
f.write("1")
with open("/sys/bus/i2c/devices/9-005f/fan6_led", "w") as f:
f.write("1")
sysled_task()
sysled_task()
# Initialize: Turn all front panel QSFP LEDs off
# # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1):

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Alphanetworks
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -1,10 +1,8 @@
#!/usr/bin/env python
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class SfpUtil(SfpUtilBase):
@ -16,17 +14,18 @@ class SfpUtil(SfpUtilBase):
port_to_eeprom = {}
port_to_i2cbus_mapping = {
1 : 14,
2 : 15,
3 : 16,
4 : 17,
1: 14,
2: 15,
3: 16,
4: 17,
}
eeprom_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_eeprom"
port_reset_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_port_reset"
present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present"
_qsfp_ports = range(first_port, port_num + 1)
_qsfp_ports = list(range(first_port, port_num + 1))
@property
def port_start(self):
return self.first_port
@ -37,11 +36,11 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
return range(self.first_port, self.port_num + 1)
return list(range(self.first_port, self.port_num + 1))
@property
@property
def port_to_eeprom_mapping(self):
return self.port_to_eeprom
return self.port_to_eeprom
def get_transceiver_change_event(self):
"""
@ -68,11 +67,11 @@ class SfpUtil(SfpUtilBase):
i2c_index = (port_num / 8) + 1
path = self.port_reset_path
port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1))
try:
reg_file = open(port_path, 'w')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
# reset
@ -90,7 +89,7 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode(self, port_num):
raise NotImplementedError
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.first_port or port_num > self.last_port:
@ -101,11 +100,10 @@ class SfpUtil(SfpUtilBase):
path = self.present_path
port_path = path.format(self.port_to_i2cbus_mapping[i2c_index], (index + 1))
try:
reg_file = open(port_path)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_value = reg_file.readline().rstrip()
@ -113,4 +111,3 @@ class SfpUtil(SfpUtilBase):
return True
return False

Просмотреть файл

@ -1,7 +1,4 @@
#!/usr/bin/env python
try:
import exceptions
import binascii
import time
import optparse
@ -11,14 +8,16 @@ try:
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/bus/i2c/devices/1-0056/eeprom"
#Two i2c buses might get flipped order, check them both.
# Two i2c buses might get flipped order, check them both.
if not os.path.exists(self.eeprom_path):
self.eeprom_path = "/sys/bus/i2c/devices/0-0056/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,22 +1,21 @@
#!/usr/bin/env python
#
# led_control.py
#
#
# Platform-specific LED control functionality for SONiC
#
# try:
# from sonic_led.led_control_base import LedControlBase
# import swsssdk
# except ImportError, e:
# except ImportError as e:
# raise ImportError (str(e) + " - required module not found")
import time
class LedControlBase(object):
# __metaclass__ = abc.ABCMeta
# @abc.abstractmethod
class LedControlBase(object):
# __metaclass__ = abc.ABCMeta
# @abc.abstractmethod
def port_link_state_change(self, port, state):
"""
Called when port link state changes. Update port link state LED here.
@ -26,6 +25,7 @@ class LedControlBase(object):
"""
return
### Goreme specified ###
read_fan_fault = 0
is_fan_all_OK = 0
@ -35,91 +35,93 @@ is_thermal_high = 0
is_reset_button_push = 0
##########################
def sysled_task():
while True:
system_led_check()
time.sleep(5)
########## Goreme System LED checking
# Goreme System LED checking
def system_led_check():
global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push
is_fan_all_OK = 1
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
global read_fan_fault, read_power_status, is_fan_all_OK, is_power_all_OK, is_thermal_high, is_reset_button_push
is_fan_all_OK = 1
is_power_all_OK = 0
is_thermal_high = 0
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/0-005e/fan1_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan2_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan3_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/0-005e/fan4_fault", "r") as f1:
read_fan_fault = f1.read()
if str(read_fan_fault) == str("1\n"):
is_fan_all_OK = 0
with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11:
if int(is_fan_all_OK) == 1:
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/8-005f/fan1_led", "w") as f11:
if int(is_fan_all_OK) == 1:
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) != str("1\n"):
is_power_all_OK = -10
with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) != str("1\n"):
is_power_all_OK = -10
with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
with open("/sys/bus/i2c/devices/0-005e/psu1_power_good", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) != str("1\n"):
is_power_all_OK = -10
with open("/sys/bus/i2c/devices/0-005e/psu1_present", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
with open("/sys/bus/i2c/devices/0-005e/psu2_power_good", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) != str("1\n"):
is_power_all_OK = -10
with open("/sys/bus/i2c/devices/0-005e/psu2_present", "r") as f1:
read_power_status = f1.read()
if str(read_power_status) == str("1\n"):
is_power_all_OK = is_power_all_OK + 1
with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11:
if int(is_power_all_OK) > 0:
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/8-005f/sys_pwr", "w") as f11:
if int(is_power_all_OK) > 0:
f11.write("1")
else:
f11.write("4")
with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5:
is_reset_button_push = f5.read()
if str(is_reset_button_push) == "1\n":
is_reset_button_push = 1
else:
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3:
is_thermal_high = f3.read()
if int(is_thermal_high) >= 70000:
is_thermal_high = 1
else:
is_thermal_high = 0
with open("/sys/bus/i2c/devices/8-005f/swi_ctrl", "r") as f5:
is_reset_button_push = f5.read()
if str(is_reset_button_push) == "1\n":
is_reset_button_push = 1
else:
is_reset_button_push = 0
with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2:
if is_reset_button_push == 1:
f2.write("3")
elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1:
f2.write("4")
else:
f2.write("1")
with open("/sys/bus/i2c/devices/3-004d/hwmon/hwmon2/temp1_input", "r") as f3:
is_thermal_high = f3.read()
if int(is_thermal_high) >= 70000:
is_thermal_high = 1
else:
is_thermal_high = 0
with open("/sys/bus/i2c/devices/8-005f/sys_status", "w") as f2:
if is_reset_button_push == 1:
f2.write("3")
elif is_fan_all_OK == 0 or is_power_all_OK == 0 or is_thermal_high == 1:
f2.write("4")
else:
f2.write("1")
return
return
##########
class LedControl(LedControlBase):
"""Platform specific LED control class"""
PORT_TABLE_PREFIX = "PORT_TABLE:"
@ -149,18 +151,18 @@ class LedControl(LedControlBase):
swss = swsssdk.SonicV2Connector()
swss.connect(swss.APPL_DB)
lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
lanes = swss.get(
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
# SONiC port nums are 0-based and increment by 4
# Arista QSFP indices are 1-based and increment by 1
return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(',')))
return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(',')))
# Concrete implementation of port_link_state_change() method
def port_link_state_change_bk(self, port, state):
qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port)
# Ignore invalid QSFP indices
if qsfp_index <= 0 or lanes <= 0 or lanes > 4:
return
@ -169,9 +171,11 @@ class LedControl(LedControlBase):
# whereas indices 25-32 are not breakout-capable, and only have one
if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
# assuming 40G, then we need to control four lanes
led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ]
led_sysfs_paths = [self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(
qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes)]
else:
led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ]
led_sysfs_paths = [
self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index)]
for led_sysfs_path in led_sysfs_paths:
led_file = open(led_sysfs_path, "w")
@ -202,7 +206,7 @@ class LedControl(LedControlBase):
f.write("1")
with open("/sys/bus/i2c/devices/8-005f/fan4_led", "w") as f:
f.write("1")
sysled_task()
sysled_task()
# Initialize: Turn all front panel QSFP LEDs off
# # for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1):

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Alphanetworks
#
@ -13,7 +11,8 @@ import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

Просмотреть файл

@ -1,10 +1,8 @@
#!/usr/bin/env python
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class SfpUtil(SfpUtilBase):
@ -16,11 +14,11 @@ class SfpUtil(SfpUtilBase):
port_to_eeprom = {}
port_to_i2cbus_mapping = {
1 : 13,
2 : 14,
3 : 15,
4 : 16,
5 : 23,
1: 13,
2: 14,
3: 15,
4: 16,
5: 23,
}
eeprom_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_eeprom"
@ -30,7 +28,7 @@ class SfpUtil(SfpUtilBase):
present_path_1 = "/sys/bus/i2c/devices/{0}-0020/sfp{1}_is_present"
present_path = "/sys/bus/i2c/devices/{0}-005f/sfp{1}_is_present"
_qsfp_ports = range(first_port, port_num)
_qsfp_ports = list(range(first_port, port_num))
@property
def port_start(self):
@ -42,11 +40,11 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
return range(self.first_port, self.port_num + 1)
return list(range(self.first_port, self.port_num + 1))
@property
@property
def port_to_eeprom_mapping(self):
return self.port_to_eeprom
return self.port_to_eeprom
def get_transceiver_change_event(self):
"""
@ -79,12 +77,12 @@ class SfpUtil(SfpUtilBase):
else:
path = self.port_reset_path
port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index)
try:
reg_file = open(port_path, 'w')
except IOError as e:
if cpld_index < 5:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
# reset
@ -102,7 +100,7 @@ class SfpUtil(SfpUtilBase):
def get_low_power_mode(self, port_num):
raise NotImplementedError
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.first_port or port_num > self.last_port:
@ -116,12 +114,11 @@ class SfpUtil(SfpUtilBase):
path = self.present_path
port_path = path.format(self.port_to_i2cbus_mapping[cpld_index], index)
try:
reg_file = open(port_path)
except IOError as e:
if cpld_index < 5:
print "Error: unable to open file: %s" % str(e)
print("Error: unable to open file: %s" % str(e))
return False
reg_value = reg_file.readline().rstrip()
@ -129,4 +126,3 @@ class SfpUtil(SfpUtilBase):
return True
return False

Просмотреть файл

@ -1,11 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import arista.platforms
from arista.utils.sonic_reboot import reboot
def main():
# reboot the system
reboot()
# reboot the system
reboot()
if __name__ == "__main__":
main()
main()

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# Arista eeprom processing for SONiC
# Uses the arista driver library to obtain the TlvInfoDecoder

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# Arista LED controls for SONiC
#

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# Arista PSU interface for SONiC
#

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#
# Arista SFP transceiver interface for SONiC
#

Просмотреть файл

@ -1,6 +1,3 @@
#!/usr/bin/python
try:
import importlib
import time
@ -23,52 +20,63 @@ try:
from thrift.protocol import TMultiplexedProtocol
from argparse import ArgumentParser
from cStringIO import StringIO
if sys.version_info.major == 3:
from io import StringIO
else:
from cStringIO import StringIO
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
if sys.version_info.major == 3:
STRING_TYPE = str
else:
STRING_TYPE = basestring
eeprom_default_dict = {
"prod_name" : ("Product Name", "0x21", 12),
"odm_pcba_part_num" : ("Part Number", "0x22", 13),
"prod_ser_num" : ("Serial Number", "0x23", 12),
"ext_mac_addr" : ("Extended MAC Address Base", "0x24", 12),
"sys_mfg_date" : ("System Manufacturing Date", "0x25", 4),
"prod_ver" : ("Product Version", "0x26", 1),
"ext_mac_addr_size" : ("Extende MAC Address Size", "0x2A", 2),
"sys_mfger" : ("Manufacturer", "0x2B", 8)
"prod_name": ("Product Name", "0x21", 12),
"odm_pcba_part_num": ("Part Number", "0x22", 13),
"prod_ser_num": ("Serial Number", "0x23", 12),
"ext_mac_addr": ("Extended MAC Address Base", "0x24", 12),
"sys_mfg_date": ("System Manufacturing Date", "0x25", 4),
"prod_ver": ("Product Version", "0x26", 1),
"ext_mac_addr_size": ("Extende MAC Address Size", "0x2A", 2),
"sys_mfger": ("Manufacturer", "0x2B", 8)
}
eeprom_dict = { "version" : ("Version", None, 0),
"pcb_mfger" : ("PCB Manufacturer", "0x01", 8),
"prod_ser_num" : ("Serial Number", "0x23", 12),
"bfn_pcba_part_num" : ("Switch PCBA Part Number", "0x02", 12),
"odm_pcba_part_num" : ("Part Number", "0x22", 13),
"bfn_pcbb_part_num" : ("Switch PCBB Part Number", "0x04", 12),
"sys_asm_part_num" : ("System Assembly Part Number", "0x05", 12),
"prod_state" : ("Product Production State", "0x06", 1),
"location" : ("EEPROM Location of Fabric", "0x07", 8),
"ext_mac_addr_size" : ("Extende MAC Address Size", "0x08", 2),
"sys_mfg_date" : ("System Manufacturing Date", "0x25", 4),
"prod_name" : ("Product Name", "0x21", 12),
"prod_ver" : ("Product Version", "0x26", 1),
"prod_part_num" : ("Product Part Number", "0x09", 8),
"sys_mfger" : ("Manufacturer", "0x2B", 8),
"assembled_at" : ("Assembled at", "0x08", 8),
"prod_ast_tag" : ("Product Asset Tag", "0x09", 12),
"loc_mac_addr" : ("Local MAC address", "0x0A", 12),
"odm_pcba_ser_num" : ("ODM PBCA Serial Number", "0x0B", 12),
"ext_mac_addr" : ("Extended MAC Address Base", "0x0C", 12),
"prod_sub_ver" : ("Product Sub Version", "0x0D", 1)
}
product_dict = { "Montara" : "Wedge100BF-32X-O-AC-F-BF",
"Lower MAV" : "Wedge100BF-65X-O-AC-F-BF",
"Upper MAV" : "Wedge100BF-65X-O-AC-F-BF"
eeprom_dict = {"version": ("Version", None, 0),
"pcb_mfger": ("PCB Manufacturer", "0x01", 8),
"prod_ser_num": ("Serial Number", "0x23", 12),
"bfn_pcba_part_num": ("Switch PCBA Part Number", "0x02", 12),
"odm_pcba_part_num": ("Part Number", "0x22", 13),
"bfn_pcbb_part_num": ("Switch PCBB Part Number", "0x04", 12),
"sys_asm_part_num": ("System Assembly Part Number", "0x05", 12),
"prod_state": ("Product Production State", "0x06", 1),
"location": ("EEPROM Location of Fabric", "0x07", 8),
"ext_mac_addr_size": ("Extende MAC Address Size", "0x08", 2),
"sys_mfg_date": ("System Manufacturing Date", "0x25", 4),
"prod_name": ("Product Name", "0x21", 12),
"prod_ver": ("Product Version", "0x26", 1),
"prod_part_num": ("Product Part Number", "0x09", 8),
"sys_mfger": ("Manufacturer", "0x2B", 8),
"assembled_at": ("Assembled at", "0x08", 8),
"prod_ast_tag": ("Product Asset Tag", "0x09", 12),
"loc_mac_addr": ("Local MAC address", "0x0A", 12),
"odm_pcba_ser_num": ("ODM PBCA Serial Number", "0x0B", 12),
"ext_mac_addr": ("Extended MAC Address Base", "0x0C", 12),
"prod_sub_ver": ("Product Sub Version", "0x0D", 1)
}
product_dict = {"Montara": "Wedge100BF-32X-O-AC-F-BF",
"Lower MAV": "Wedge100BF-65X-O-AC-F-BF",
"Upper MAV": "Wedge100BF-65X-O-AC-F-BF"
}
thrift_server = 'localhost'
transport = None
pltfm_mgr = None
@ -76,6 +84,7 @@ pltfm_mgr = None
EEPROM_SYMLINK = "/var/run/platform/eeprom/syseeprom"
EEPROM_STATUS = "/var/run/platform/eeprom/status"
class board(eeprom_tlvinfo.TlvInfoDecoder):
RETRIES = 35
@ -114,8 +123,10 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
transport = TTransport.TBufferedTransport(transport)
bprotocol = TBinaryProtocol.TBinaryProtocol(transport)
pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"]))
pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc")
pltfm_mgr_client_module = importlib.import_module(
".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"]))
pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
bprotocol, "pltfm_mgr_rpc")
pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol)
transport.open()
@ -139,7 +150,7 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
f.close()
eeprom_params = ""
for attr, val in eeprom.__dict__.iteritems():
for attr, val in eeprom.__dict__.items():
if val is None:
continue
@ -147,13 +158,14 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
if elem is None:
continue
if isinstance(val, basestring):
if isinstance(val, STRING_TYPE):
value = val.replace('\0', '')
else:
value = str(val)
if attr == "sys_mfg_date":
value = datetime.datetime.strptime(value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00')
value = datetime.datetime.strptime(
value, '%m-%d-%y').strftime('%m/%d/%Y 00:00:00')
product = product_dict.get(value)
if product is not None:
@ -164,9 +176,9 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
orig_stdout = sys.stdout
sys.stdout = StringIO()
new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(self, "", [eeprom_params])
new_e = eeprom_tlvinfo.TlvInfoDecoder.set_eeprom(
self, "", [eeprom_params])
sys.stdout = orig_stdout
eeprom_base.EepromDecoder.write_eeprom(self, new_e)
return True

Просмотреть файл

@ -177,7 +177,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sys_tmp_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_sys_tmp_get failed: unknown result")
def pltfm_mgr_sys_eeprom_get(self):
self.send_pltfm_mgr_sys_eeprom_get()
@ -205,7 +206,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sys_eeprom_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_sys_eeprom_get failed: unknown result")
def pltfm_mgr_pwr_supply_present_get(self, ps_num):
"""
@ -238,7 +240,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_supply_present_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_pwr_supply_present_get failed: unknown result")
def pltfm_mgr_pwr_supply_info_get(self, ps_num):
"""
@ -271,7 +274,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_supply_info_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_pwr_supply_info_get failed: unknown result")
def pltfm_mgr_pwr_rail_info_get(self, ps_num):
"""
@ -304,7 +308,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_pwr_rail_info_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_pwr_rail_info_get failed: unknown result")
def pltfm_mgr_fan_speed_set(self, fan_num, percent):
"""
@ -339,7 +344,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_fan_speed_set failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_fan_speed_set failed: unknown result")
def pltfm_mgr_fan_info_get(self, fan_num):
"""
@ -372,7 +378,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_fan_info_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_fan_info_get failed: unknown result")
def pltfm_mgr_qsfp_presence_get(self, port_num):
"""
@ -405,7 +412,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_presence_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_qsfp_presence_get failed: unknown result")
def pltfm_mgr_qsfp_info_get(self, port_num):
"""
@ -438,7 +446,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_info_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_qsfp_info_get failed: unknown result")
def pltfm_mgr_qsfp_get_max_port(self):
self.send_pltfm_mgr_qsfp_get_max_port()
@ -466,7 +475,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_get_max_port failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_qsfp_get_max_port failed: unknown result")
def pltfm_mgr_qsfp_reset(self, port_num, reset):
"""
@ -534,7 +544,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_lpmode_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_qsfp_lpmode_get failed: unknown result")
def pltfm_mgr_qsfp_lpmode_set(self, port_num, lpmode):
"""
@ -569,7 +580,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_qsfp_lpmode_set failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_qsfp_lpmode_set failed: unknown result")
def pltfm_mgr_sensor_info_get(self, options):
"""
@ -602,7 +614,8 @@ class Client(Iface):
return result.success
if result.ouch is not None:
raise result.ouch
raise TApplicationException(TApplicationException.MISSING_RESULT, "pltfm_mgr_sensor_info_get failed: unknown result")
raise TApplicationException(TApplicationException.MISSING_RESULT,
"pltfm_mgr_sensor_info_get failed: unknown result")
class Processor(Iface, TProcessor):
@ -1020,7 +1033,7 @@ class pltfm_mgr_dummy_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1079,7 +1092,7 @@ class pltfm_mgr_dummy_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1121,7 +1134,7 @@ class pltfm_mgr_sys_tmp_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1194,7 +1207,7 @@ class pltfm_mgr_sys_tmp_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1236,7 +1249,7 @@ class pltfm_mgr_sys_eeprom_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1309,7 +1322,7 @@ class pltfm_mgr_sys_eeprom_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1369,7 +1382,7 @@ class pltfm_mgr_pwr_supply_present_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1441,7 +1454,7 @@ class pltfm_mgr_pwr_supply_present_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1501,7 +1514,7 @@ class pltfm_mgr_pwr_supply_info_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1574,7 +1587,7 @@ class pltfm_mgr_pwr_supply_info_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1634,7 +1647,7 @@ class pltfm_mgr_pwr_rail_info_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1707,7 +1720,7 @@ class pltfm_mgr_pwr_rail_info_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1779,7 +1792,7 @@ class pltfm_mgr_fan_speed_set_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1851,7 +1864,7 @@ class pltfm_mgr_fan_speed_set_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1911,7 +1924,7 @@ class pltfm_mgr_fan_info_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1984,7 +1997,7 @@ class pltfm_mgr_fan_info_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2044,7 +2057,7 @@ class pltfm_mgr_qsfp_presence_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2116,7 +2129,7 @@ class pltfm_mgr_qsfp_presence_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2176,7 +2189,7 @@ class pltfm_mgr_qsfp_info_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2213,7 +2226,8 @@ class pltfm_mgr_qsfp_info_get_result(object):
break
if fid == 0:
if ftype == TType.STRING:
self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.success = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 1:
@ -2248,7 +2262,7 @@ class pltfm_mgr_qsfp_info_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2290,7 +2304,7 @@ class pltfm_mgr_qsfp_get_max_port_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2362,7 +2376,7 @@ class pltfm_mgr_qsfp_get_max_port_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2434,7 +2448,7 @@ class pltfm_mgr_qsfp_reset_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2506,7 +2520,7 @@ class pltfm_mgr_qsfp_reset_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2566,7 +2580,7 @@ class pltfm_mgr_qsfp_lpmode_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2638,7 +2652,7 @@ class pltfm_mgr_qsfp_lpmode_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2710,7 +2724,7 @@ class pltfm_mgr_qsfp_lpmode_set_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2782,7 +2796,7 @@ class pltfm_mgr_qsfp_lpmode_set_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2817,7 +2831,8 @@ class pltfm_mgr_sensor_info_get_args(object):
break
if fid == 1:
if ftype == TType.STRING:
self.options = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.options = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
else:
@ -2842,7 +2857,7 @@ class pltfm_mgr_sensor_info_get_args(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -2879,7 +2894,8 @@ class pltfm_mgr_sensor_info_get_result(object):
break
if fid == 0:
if ftype == TType.STRING:
self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.success = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 1:
@ -2914,7 +2930,7 @@ class pltfm_mgr_sensor_info_get_result(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):

Просмотреть файл

@ -171,7 +171,7 @@ class pltfm_mgr_sys_tmp_t(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -274,37 +274,44 @@ class pltfm_mgr_eeprom_t(object):
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.STRING:
self.prod_name = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_name = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 3:
if ftype == TType.STRING:
self.prod_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_part_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 4:
if ftype == TType.STRING:
self.sys_asm_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.sys_asm_part_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 5:
if ftype == TType.STRING:
self.bfn_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.bfn_pcba_part_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 6:
if ftype == TType.STRING:
self.bfn_pcbb_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.bfn_pcbb_part_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 7:
if ftype == TType.STRING:
self.odm_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.odm_pcba_part_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 8:
if ftype == TType.STRING:
self.odm_pcba_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.odm_pcba_ser_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 9:
@ -324,42 +331,50 @@ class pltfm_mgr_eeprom_t(object):
iprot.skip(ftype)
elif fid == 12:
if ftype == TType.STRING:
self.prod_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_ser_num = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 13:
if ftype == TType.STRING:
self.prod_ast_tag = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_ast_tag = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 14:
if ftype == TType.STRING:
self.sys_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.sys_mfger = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 15:
if ftype == TType.STRING:
self.sys_mfg_date = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.sys_mfg_date = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 16:
if ftype == TType.STRING:
self.pcb_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.pcb_mfger = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 17:
if ftype == TType.STRING:
self.assembled_at = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.assembled_at = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 18:
if ftype == TType.STRING:
self.loc_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.loc_mac_addr = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 19:
if ftype == TType.STRING:
self.ext_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.ext_mac_addr = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 20:
@ -369,7 +384,8 @@ class pltfm_mgr_eeprom_t(object):
iprot.skip(ftype)
elif fid == 21:
if ftype == TType.STRING:
self.location = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.location = iprot.readString().decode(
'utf-8') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 22:
@ -401,23 +417,28 @@ class pltfm_mgr_eeprom_t(object):
oprot.writeFieldEnd()
if self.sys_asm_part_num is not None:
oprot.writeFieldBegin('sys_asm_part_num', TType.STRING, 4)
oprot.writeString(self.sys_asm_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.sys_asm_part_num)
oprot.writeString(self.sys_asm_part_num.encode('utf-8')
if sys.version_info[0] == 2 else self.sys_asm_part_num)
oprot.writeFieldEnd()
if self.bfn_pcba_part_num is not None:
oprot.writeFieldBegin('bfn_pcba_part_num', TType.STRING, 5)
oprot.writeString(self.bfn_pcba_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.bfn_pcba_part_num)
oprot.writeString(self.bfn_pcba_part_num.encode('utf-8')
if sys.version_info[0] == 2 else self.bfn_pcba_part_num)
oprot.writeFieldEnd()
if self.bfn_pcbb_part_num is not None:
oprot.writeFieldBegin('bfn_pcbb_part_num', TType.STRING, 6)
oprot.writeString(self.bfn_pcbb_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.bfn_pcbb_part_num)
oprot.writeString(self.bfn_pcbb_part_num.encode('utf-8')
if sys.version_info[0] == 2 else self.bfn_pcbb_part_num)
oprot.writeFieldEnd()
if self.odm_pcba_part_num is not None:
oprot.writeFieldBegin('odm_pcba_part_num', TType.STRING, 7)
oprot.writeString(self.odm_pcba_part_num.encode('utf-8') if sys.version_info[0] == 2 else self.odm_pcba_part_num)
oprot.writeString(self.odm_pcba_part_num.encode('utf-8')
if sys.version_info[0] == 2 else self.odm_pcba_part_num)
oprot.writeFieldEnd()
if self.odm_pcba_ser_num is not None:
oprot.writeFieldBegin('odm_pcba_ser_num', TType.STRING, 8)
oprot.writeString(self.odm_pcba_ser_num.encode('utf-8') if sys.version_info[0] == 2 else self.odm_pcba_ser_num)
oprot.writeString(self.odm_pcba_ser_num.encode('utf-8')
if sys.version_info[0] == 2 else self.odm_pcba_ser_num)
oprot.writeFieldEnd()
if self.prod_state is not None:
oprot.writeFieldBegin('prod_state', TType.I16, 9)
@ -483,7 +504,7 @@ class pltfm_mgr_eeprom_t(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -651,7 +672,7 @@ class pltfm_mgr_pwr_supply_info_t(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -891,7 +912,7 @@ class pltfm_mgr_pwr_rail_info_t(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -987,7 +1008,7 @@ class pltfm_mgr_fan_info_t(object):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):
@ -1050,7 +1071,7 @@ class InvalidPltfmMgrOperation(TException):
def __repr__(self):
L = ['%s=%r' % (key, value)
for key, value in self.__dict__.items()]
for key, value in list(self.__dict__.items())]
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
def __eq__(self, other):

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
try:
import os
import sys
@ -16,12 +14,13 @@ try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
thrift_server = 'localhost'
transport = None
pltfm_mgr = None
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""
@ -35,8 +34,10 @@ class PsuUtil(PsuBase):
transport = TTransport.TBufferedTransport(transport)
bprotocol = TBinaryProtocol.TBinaryProtocol(transport)
pltfm_mgr_client_module = importlib.import_module(".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"]))
pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(bprotocol, "pltfm_mgr_rpc")
pltfm_mgr_client_module = importlib.import_module(
".".join(["pltfm_mgr_rpc", "pltfm_mgr_rpc"]))
pltfm_mgr_protocol = TMultiplexedProtocol.TMultiplexedProtocol(
bprotocol, "pltfm_mgr_rpc")
pltfm_mgr = pltfm_mgr_client_module.Client(pltfm_mgr_protocol)
transport.open()
@ -65,9 +66,9 @@ class PsuUtil(PsuBase):
global pltfm_mgr
try:
self.thrift_setup()
psu_info = pltfm_mgr.pltfm_mgr_pwr_supply_info_get(index)
self.thrift_teardown()
self.thrift_setup()
psu_info = pltfm_mgr.pltfm_mgr_pwr_supply_info_get(index)
self.thrift_teardown()
except:
return False
@ -86,11 +87,10 @@ class PsuUtil(PsuBase):
global pltfm_mgr
try:
self.thrift_setup()
status = pltfm_mgr.pltfm_mgr_pwr_supply_present_get(index)
self.thrift_teardown()
self.thrift_setup()
status = pltfm_mgr.pltfm_mgr_pwr_supply_present_get(index)
self.thrift_teardown()
except:
return False
return status

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
try:
import os
import sys
@ -17,7 +15,7 @@ try:
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
raise ImportError(str(e) + "- required module not found")
thrift_server = 'localhost'
transport = None
@ -25,6 +23,7 @@ pltfm_mgr = None
SFP_EEPROM_CACHE = "/var/run/platform/sfp/cache"
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
@ -51,12 +50,12 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
self.update_port_info()
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
return list(range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1))
@property
def port_to_eeprom_mapping(self):
print "dependency on sysfs has been removed"
raise Exception()
print("dependency on sysfs has been removed")
raise Exception()
def __init__(self):
self.ready = False
@ -80,7 +79,7 @@ class SfpUtil(SfpUtilBase):
if self.QSFP_PORT_END == 0:
self.thrift_setup()
self.QSFP_PORT_END = pltfm_mgr.pltfm_mgr_qsfp_get_max_port();
self.QSFP_PORT_END = pltfm_mgr.pltfm_mgr_qsfp_get_max_port()
self.PORT_END = self.QSFP_PORT_END
self.PORTS_IN_BLOCK = self.QSFP_PORT_END
self.thrift_teardown()
@ -127,8 +126,8 @@ class SfpUtil(SfpUtilBase):
presence = pltfm_mgr.pltfm_mgr_qsfp_presence_get(port_num)
self.thrift_teardown()
except Exception as e:
print e.__doc__
print e.message
print(e.__doc__)
print(e.message)
return presence
@ -198,9 +197,9 @@ class SfpUtil(SfpUtilBase):
if timeout == 0:
forever = True
elif timeout > 0:
timeout = timeout / float(1000) # Convert to secs
timeout = timeout / float(1000) # Convert to secs
else:
print "get_transceiver_change_event:Invalid timeout value", timeout
print("get_transceiver_change_event:Invalid timeout value", timeout)
return False, {}
while forever or timeout > 0:
@ -249,4 +248,3 @@ class SfpUtil(SfpUtilBase):
self.thrift_teardown()
return eeprom_path

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Broadcom XLR/GTS 'eeprom' support
#
@ -16,8 +14,8 @@ import os
try:
from sonic_eeprom import eeprom_tlvinfo
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
@ -25,7 +23,7 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/usr/share/sonic/platform/sys_eeprom.bin"
if os.path.isfile(self.eeprom_path) is False:
self.eeprom_path = "/usr/share/sonic/device/x86_64-bcm_xlr-r0/sys_eeprom.bin"
self.eeprom_path = "/usr/share/sonic/device/x86_64-bcm_xlr-r0/sys_eeprom.bin"
super(board, self).__init__(self.eeprom_path, 0, '', False, True)
def serial_number_str(self, e):

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
import os.path
try:

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
try:
import time
import os

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica Haliburton
#
@ -11,8 +9,8 @@
try:
from sonic_eeprom import eeprom_tlvinfo
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
@ -20,4 +18,3 @@ class board(eeprom_tlvinfo.TlvInfoDecoder):
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0050/eeprom"
super(board, self).__init__(self.eeprom_path, 0, '', True)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
import os.path
try:

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
try:
import time
import os
@ -15,15 +13,15 @@ class SfpUtil(SfpUtilBase):
PORT_START = 1
PORT_END = 52
port_to_i2c_mapping = {
1: None,
2: None,
3: None,
4: None,
5: None,
6: None,
7: None,
8: None,
9: None,
1: None,
2: None,
3: None,
4: None,
5: None,
6: None,
7: None,
8: None,
9: None,
10: None,
11: None,
12: None,
@ -69,7 +67,7 @@ class SfpUtil(SfpUtilBase):
52: 16
}
_port_to_eeprom_mapping = {}
_sfp_port = range(49, PORT_END + 1)
_sfp_port = list(range(49, PORT_END + 1))
@property
def port_start(self):
@ -95,7 +93,6 @@ class SfpUtil(SfpUtilBase):
self.port_to_eeprom_mapping[x] = port_eeprom_path
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
sfp_modabs_path = '/sys/devices/platform/e1031.smc/SFP/sfp_modabs'
@ -129,7 +126,7 @@ class SfpUtil(SfpUtilBase):
try:
# We get notified when there is an SCI interrupt from GPIO SUS7
fd = open("/sys/devices/platform/hlx-ich.0/sci_int_gpio_sus7", "r")
fd.read()
fd.read()
epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET)
events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1)
@ -139,18 +136,18 @@ class SfpUtil(SfpUtilBase):
with open(modabs_interrupt_path, 'r') as port_changes:
changes = int(port_changes.read(), 16)
for port_num in self._sfp_port:
change = (changes >> ( port_num - 49)) & 1
change = (changes >> (port_num - 49)) & 1
if change == 1:
port_dict[str(port_num)] = str(int(self.get_presence(port_num)))
found_flag = 1
if not found_flag:
return False, {}
return True, port_dict
finally:
fd.close()
epoll.close()
return False, {}
return False, {}

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#
@ -43,7 +41,7 @@ class Component(ComponentBase):
# Run bash command and print output to stdout
try:
process = subprocess.Popen(
shlex.split(command), stdout=subprocess.PIPE)
shlex.split(command), universal_newlines=True, stdout=subprocess.PIPE)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
@ -68,7 +66,7 @@ class Component(ComponentBase):
# Retrieves the cpld register value
cmd = "echo {1} > {0}; cat {0}".format(GETREG_PATH, register)
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err is not '':
return None

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica Haliburton
#
@ -13,13 +11,17 @@ try:
import glob
import os
import sys
import imp
import re
from array import array
from cStringIO import StringIO
if sys.version_info.major == 3:
from io import StringIO
else:
from cStringIO import StringIO
from sonic_platform_base.sonic_eeprom import eeprom_dts
from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo
except ImportError, e:
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
CACHE_ROOT = '/var/cache/sonic/decode-syseeprom'

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#
@ -84,7 +82,7 @@ class Psu(PsuBase):
if vout_label_path:
dir_name = os.path.dirname(vout_label_path)
basename = os.path.basename(vout_label_path)
in_num = filter(str.isdigit, basename)
in_num = list(filter(str.isdigit, basename))
vout_path = os.path.join(
dir_name, voltage_name.format(in_num))
vout_val = self.__read_txt_file(vout_path)
@ -107,7 +105,7 @@ class Psu(PsuBase):
if curr_label_path:
dir_name = os.path.dirname(curr_label_path)
basename = os.path.basename(curr_label_path)
cur_num = filter(str.isdigit, basename)
cur_num = list(filter(str.isdigit, basename))
cur_path = os.path.join(
dir_name, current_name.format(cur_num))
cur_val = self.__read_txt_file(cur_path)
@ -130,7 +128,7 @@ class Psu(PsuBase):
if pw_label_path:
dir_name = os.path.dirname(pw_label_path)
basename = os.path.basename(pw_label_path)
pw_num = filter(str.isdigit, basename)
pw_num = list(filter(str.isdigit, basename))
pw_path = os.path.join(
dir_name, current_name.format(pw_num))
pw_val = self.__read_txt_file(pw_path)

Просмотреть файл

@ -1,5 +1,3 @@
#!/usr/bin/env python
#############################################################################
# Celestica
#
@ -81,7 +79,7 @@ class Sfp(SfpBase):
51: 17,
52: 16
}
_sfp_port = range(49, PORT_END + 1)
_sfp_port = list(range(49, PORT_END + 1))
PRS_PATH = "/sys/devices/platform/e1031.smc/SFP/sfp_modabs"
PLATFORM_ROOT_PATH = '/usr/share/sonic/device'
PMON_HWSKU_PATH = '/usr/share/sonic/hwsku'

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше