Skip to content

Commit b323dd1

Browse files
Added ipaddr conversion for Thrift (#252)
Signed-off-by: yuliso <yurii.lisovskyi@plvision.eu>
1 parent ed0bc8e commit b323dd1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

common/sai_client/sai_thrift_client/sai_thrift_utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ def convert_value_from_thrift(value, attr_name, obj_type=None):
467467
raise NotImplementedError(f"{value_type}, {value}")
468468
elif value_type in [ 'aclfield' ]:
469469
raise NotImplementedError(f"{value_type}, {value}")
470+
elif value_type in [ 'ipaddr' ]:
471+
return ThriftConverter.from_sai_ip_address(value)
470472

471473
# TODO: Add more thrift->string convertes here
472474
raise NotImplementedError(f"{value_type}, {value}")
@@ -553,6 +555,16 @@ def from_sai_sysport_config_list(value_type, config, attr_name, obj_type):
553555
}
554556
)
555557
return json.dumps(result).replace(" ", "")
558+
559+
@staticmethod
560+
def from_sai_ip_address(value):
561+
"""
562+
sai_thrift_ip_address_t(addr_family=0, addr=sai_thrift_ip_addr_t(ip4='10.1.1.2', ip6='')) => "10.1.1.2"
563+
"""
564+
if value.addr_family == SAI_IP_ADDR_FAMILY_IPV6:
565+
return value.addr.ip6
566+
else:
567+
return value.addr.ip4
556568

557569
# AUXILARY
558570

0 commit comments

Comments
 (0)