From cd74135d62b4aa8e4cd3c5544faff0732b4f8bb8 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Tue, 31 Mar 2020 16:49:31 +0500 Subject: [PATCH] py3: Replace decode method to codecs on profiles. --- .../Alcatel/TIMOS/get_lldp_neighbors.py | 7 +++--- .../DCN/DCWL/get_interface_status_ex.py | 3 ++- sa/profiles/DCN/DCWL/get_interfaces.py | 3 ++- sa/profiles/DCN/DCWL/get_metrics.py | 3 ++- .../Eltex/WOP/get_interface_status_ex.py | 3 ++- sa/profiles/Eltex/WOP/get_interfaces.py | 3 ++- sa/profiles/Eltex/WOP/get_metrics.py | 3 ++- sa/profiles/MikroTik/SwOS/get_interfaces.py | 7 ++++-- sa/profiles/MikroTik/SwOS/get_inventory.py | 25 +++++++++++-------- sa/profiles/MikroTik/SwOS/get_version.py | 9 ++++--- 10 files changed, 41 insertions(+), 25 deletions(-) diff --git a/sa/profiles/Alcatel/TIMOS/get_lldp_neighbors.py b/sa/profiles/Alcatel/TIMOS/get_lldp_neighbors.py index 98dad3ceb2..1e6dee242a 100644 --- a/sa/profiles/Alcatel/TIMOS/get_lldp_neighbors.py +++ b/sa/profiles/Alcatel/TIMOS/get_lldp_neighbors.py @@ -8,6 +8,7 @@ # Python modules import re +import codecs # NOC modules from noc.core.script.base import BaseScript @@ -70,14 +71,14 @@ class Script(BaseScript): if port_type == "5" and "\n " in port: remote_port = port.replace("\n ", "") remote_port = remote_port.replace(":", "").replace("\n", "") - remote_port = remote_port.decode("hex") + remote_port = codecs.decode(remote_port, "hex") elif port_type == "5" and "\n" in port: remote_port = port.replace("\n", "") remote_port = remote_port.replace(":", "").replace("\n", "") - remote_port = remote_port.decode("hex") + remote_port = codecs.decode(remote_port, "hex") elif port_type == "5" and "\n " not in port: remote_port = remote_port.replace(":", "").replace("\n", "") - remote_port = remote_port.decode("hex") + remote_port = codecs.decode(remote_port, "hex") elif port_type == "7": return port.replace("\n", "") return remote_port diff --git a/sa/profiles/DCN/DCWL/get_interface_status_ex.py b/sa/profiles/DCN/DCWL/get_interface_status_ex.py index 705fccedcd..0a8f007cf2 100644 --- a/sa/profiles/DCN/DCWL/get_interface_status_ex.py +++ b/sa/profiles/DCN/DCWL/get_interface_status_ex.py @@ -8,6 +8,7 @@ # Third-party modules import six +import codecs # NOC modules from noc.core.script.base import BaseScript @@ -76,7 +77,7 @@ class Script(BaseScript): ssid = value["ssid"].replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string - ssid = ssid.decode("hex") + ssid = codecs.decode(ssid, "hex") bss = self.get_bss_status(value["bss"]) if not bss: continue diff --git a/sa/profiles/DCN/DCWL/get_interfaces.py b/sa/profiles/DCN/DCWL/get_interfaces.py index 12aec72317..2ec6776dff 100644 --- a/sa/profiles/DCN/DCWL/get_interfaces.py +++ b/sa/profiles/DCN/DCWL/get_interfaces.py @@ -8,6 +8,7 @@ # Third-party modules import six +import codecs # NOC modules from noc.core.script.base import BaseScript @@ -110,7 +111,7 @@ class Script(BaseScript): ssid = value["ssid"].replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string - ssid = ssid.decode("hex") + ssid = codecs.decode(ssid, "hex") r = self.get_bss_detail(value["bss"]) bss_ifname = "%s.%s" % (ifname, ssid) if r: diff --git a/sa/profiles/DCN/DCWL/get_metrics.py b/sa/profiles/DCN/DCWL/get_metrics.py index 57ad89f7d1..b2751eaebf 100644 --- a/sa/profiles/DCN/DCWL/get_metrics.py +++ b/sa/profiles/DCN/DCWL/get_metrics.py @@ -10,6 +10,7 @@ from __future__ import division import six from collections import defaultdict +import codecs # NOC modules from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript, metrics @@ -125,7 +126,7 @@ class Script(GetMetricsScript): ssid = data["ssid"].strip().replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string - ssid = ssid.decode("hex") + ssid = codecs.decode(ssid, "hex") iface = "%s.%s" % (data["name"], ssid) else: iface = data["name"] diff --git a/sa/profiles/Eltex/WOP/get_interface_status_ex.py b/sa/profiles/Eltex/WOP/get_interface_status_ex.py index da8aa9f47e..f6130bd0c2 100644 --- a/sa/profiles/Eltex/WOP/get_interface_status_ex.py +++ b/sa/profiles/Eltex/WOP/get_interface_status_ex.py @@ -8,6 +8,7 @@ # Third-party modules import six +import codecs # NOC modules from noc.core.script.base import BaseScript @@ -76,7 +77,7 @@ class Script(BaseScript): ssid = value["ssid"].replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string - ssid = ssid.decode("hex") + ssid = codecs.decode(ssid, "hex") bss = self.get_bss_status(value["bss"]) if not bss: continue diff --git a/sa/profiles/Eltex/WOP/get_interfaces.py b/sa/profiles/Eltex/WOP/get_interfaces.py index 697bacacb0..7fbab86aef 100644 --- a/sa/profiles/Eltex/WOP/get_interfaces.py +++ b/sa/profiles/Eltex/WOP/get_interfaces.py @@ -8,6 +8,7 @@ # Third-party modules import six +import codecs # NOC modules from noc.core.script.base import BaseScript @@ -113,7 +114,7 @@ class Script(BaseScript): ssid = value["ssid"].replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string - ssid = ssid.decode("hex") + ssid = codecs.decode(ssid, "hex") r = self.get_bss_detail(value["bss"]) bss_ifname = "%s.%s" % (ifname, ssid) if r: diff --git a/sa/profiles/Eltex/WOP/get_metrics.py b/sa/profiles/Eltex/WOP/get_metrics.py index f4cd0fb025..e1b625872a 100644 --- a/sa/profiles/Eltex/WOP/get_metrics.py +++ b/sa/profiles/Eltex/WOP/get_metrics.py @@ -9,6 +9,7 @@ # Python modules from __future__ import division from collections import defaultdict +import codecs # Third-party modules # import six @@ -132,7 +133,7 @@ class Script(GetMetricsScript): ssid = data["ssid"].strip().replace(" ", "").replace("Managed", "") if ssid.startswith("2a2d"): # 2a2d - hex string - ssid = ssid.decode("hex") + ssid = codecs.decode(ssid, "hex") iface = "%s.%s" % (data["name"], ssid) else: iface = data["name"] diff --git a/sa/profiles/MikroTik/SwOS/get_interfaces.py b/sa/profiles/MikroTik/SwOS/get_interfaces.py index a13c38e741..7dc3fbe59a 100644 --- a/sa/profiles/MikroTik/SwOS/get_interfaces.py +++ b/sa/profiles/MikroTik/SwOS/get_interfaces.py @@ -6,6 +6,9 @@ # See LICENSE for details # --------------------------------------------------------------------- +# Python modules +import codecs + # NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.igetinterfaces import IGetInterfaces @@ -57,9 +60,9 @@ class Script(BaseScript): else: ifname = "SFP" if links.get("nm"): - descr = links["nm"][port - 1].decode("hex") + descr = codecs.decode(links["nm"][port - 1], "hex") elif links.get("nm%d" % (port - 1)): - descr = links["nm%d" % (port - 1)].decode("hex") + descr = codecs.decode(links["nm%d" % (port - 1)], "hex") else: descr = None iface = { diff --git a/sa/profiles/MikroTik/SwOS/get_inventory.py b/sa/profiles/MikroTik/SwOS/get_inventory.py index ea58856af4..e4c3da4b43 100644 --- a/sa/profiles/MikroTik/SwOS/get_inventory.py +++ b/sa/profiles/MikroTik/SwOS/get_inventory.py @@ -6,6 +6,9 @@ # See LICENSE for details # --------------------------------------------------------------------- +# Python modules +import codecs + # NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.igetinventory import IGetInventory @@ -30,17 +33,17 @@ class Script(BaseScript): if sfps.get("vnd"): sfp_count = len(sfps["vnd"]) for i in range(0, sfp_count): - vendor = sfps["vnd"][i].decode("hex").strip() - part_no = sfps["pnr"][i].decode("hex").strip() - revision = sfps["rev"][i].decode("hex").strip() - serial = sfps["ser"][i].decode("hex").strip() - date = sfps["dat"][i].decode("hex").strip() + vendor = codecs.decode(sfps["vnd"][i], "hex").strip() + part_no = codecs.decode(sfps["pnr"][i], "hex").strip() + revision = codecs.decode(sfps["rev"][i], "hex").strip() + serial = codecs.decode(sfps["ser"][i], "hex").strip() + date = codecs.decode(sfps["dat"][i], "hex").strip() dt = date.split("-") year = "20" + dt[0] parts = [year, dt[1], dt[2]] mfd = "-".join(parts) - descr = sfps["typ"][i].decode("hex").strip() + descr = codecs.decode(sfps["typ"][i], "hex").strip() r += [ { "type": "XCVR", @@ -54,11 +57,11 @@ class Script(BaseScript): } ] elif sfps.get("vndr"): - vendor = sfps["vndr"].decode("hex").strip() - part_no = sfps["ptnr"].decode("hex").strip() - revision = sfps["rev"].decode("hex").strip() - serial = sfps["ser"].decode("hex").strip() - date = sfps["date"].decode("hex").strip() + vendor = codecs.decode(sfps["vndr"], "hex").strip() + part_no = codecs.decode(sfps["ptnr"], "hex").strip() + revision = codecs.decode(sfps["rev"], "hex").strip() + serial = codecs.decode(sfps["ser"], "hex").strip() + date = codecs.decode(sfps["date"], "hex").strip() dt = date.split("-") year = "20" + dt[0] parts = [year, dt[1], dt[2]] diff --git a/sa/profiles/MikroTik/SwOS/get_version.py b/sa/profiles/MikroTik/SwOS/get_version.py index 300adf50b3..f6332724c1 100644 --- a/sa/profiles/MikroTik/SwOS/get_version.py +++ b/sa/profiles/MikroTik/SwOS/get_version.py @@ -6,6 +6,9 @@ # See LICENSE for details # --------------------------------------------------------------------- +# Python modules +import codecs + # NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.igetversion import IGetVersion @@ -21,8 +24,8 @@ class Script(BaseScript): sys_info = self.profile.parseBrokenJson(self.http.get("/sys.b", cached=True, eof_mark="}")) r = { "vendor": "MikroTik", - "platform": sys_info["brd"].decode("hex"), - "version": sys_info["ver"].decode("hex"), - "attributes": {"Serial Number": sys_info["sid"].decode("hex")}, + "platform": codecs.decode(sys_info["brd"], "hex"), + "version": codecs.decode(sys_info["ver"], "hex"), + "attributes": {"Serial Number": codecs.decode(sys_info["sid"], "hex")}, } return r -- GitLab