From 54ce6d02112f267733402735b1dbb3635dfa8055 Mon Sep 17 00:00:00 2001 From: Sagi Grimberg Date: Thu, 12 Apr 2018 16:32:33 +0300 Subject: [PATCH] nvmetcli: expose nvmet port status and state The status attribute reflects if any subsystems are bound and can accept existing connections. The state attribute reflects the physical state of the port. Also colorize UI if port state is down. Signed-off-by: Sagi Grimberg Signed-off-by: Christoph Hellwig --- nvmet/nvme.py | 13 +++++++++++++ nvmetcli | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nvmet/nvme.py b/nvmet/nvme.py index c245a42..f5d0555 100644 --- a/nvmet/nvme.py +++ b/nvmet/nvme.py @@ -618,6 +618,19 @@ class Port(CFSNode): portid = property(_get_portid, doc="Get the Port ID as an int.") + def _get_state(self): + self._check_self() + _state = None + path = "%s/trstate" % self.path + if not os.path.isfile(path): + return None + + with open(path, 'r') as file_fd: + _state = file_fd.read().strip() + return _state + + state = property(_get_state, doc="Get the Port state.") + def _list_subsystems(self): return [os.path.basename(name) for name in os.listdir("%s/subsystems/" % self._path)] diff --git a/nvmetcli b/nvmetcli index 6b102a2..5d5aabc 100755 --- a/nvmetcli +++ b/nvmetcli @@ -388,7 +388,14 @@ class UIPortNode(UINode): if trsvcid != "none": info.append("trsvcid=%s" % trsvcid) enabled = not (not self.cfnode.subsystems and not list(self.cfnode.referrals)) - return (", ".join(info), True if enabled else 0) + info.append("status=" + ("enabled" if enabled else "disabled")) + if not enabled: + ret = 0 + else: + trstate = self.cfnode.state + info.append("state=" + trstate) + ret = True if trstate == "up" else False + return (", ".join(info), ret) class UIPortSubsystemsNode(UINode): def __init__(self, parent): -- 2.50.1