diff mbox series

[v8,6/9] rpcctl: Add a command for changing xprt switch dstaddrs

Message ID 20220215192150.53811-7-Anna.Schumaker@Netapp.com (mailing list archive)
State New, archived
Headers show
Series Add a tool for using the new sysfs files | expand

Commit Message

Schumaker, Anna Feb. 15, 2022, 7:21 p.m. UTC
From: Anna Schumaker <Anna.Schumaker@Netapp.com>

This is basically the same as for xprts, but it iterates through all
xprts attached to the switch to apply the new address.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
v8: Only call socket.gethostbyname() once instead of for each xprt
---
 tools/rpcctl/rpcctl.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/rpcctl/rpcctl.py b/tools/rpcctl/rpcctl.py
index 98e1f680ed72..0fbce99fff5b 100755
--- a/tools/rpcctl/rpcctl.py
+++ b/tools/rpcctl/rpcctl.py
@@ -82,7 +82,6 @@  class Xprt:
         return f"{self.name}: {self.type}, {self.dstaddr}{main}"
 
     def set_dstaddr(self, newaddr):
-        resolved = socket.gethostbyname(newaddr)
         self.dstaddr = write_addr_file(self.path / "dstaddr", newaddr)
 
     def add_command(subparser):
@@ -152,6 +151,15 @@  class XprtSwitch:
                           help="Name of a specific switch to show")
         show.set_defaults(func=XprtSwitch.show)
 
+        set = subparser.add_parser("set", help="Change an xprt switch property")
+        set.add_argument("switch", metavar="SWITCH", nargs=1,
+                         help="Name of a specific xprt switch to modify")
+        subparser = set.add_subparsers(required=True)
+        dstaddr = subparser.add_parser("dstaddr", help="Change an xprt switch's dstaddr")
+        dstaddr.add_argument("newaddr", metavar="NEWADDR", nargs=1,
+                             help="The new address for the xprt switch")
+        dstaddr.set_defaults(func=XprtSwitch.set_property, property="dstaddr")
+
     def get_by_name(name):
         xprt_switches = sunrpc / "xprt-switches"
         if name:
@@ -162,6 +170,13 @@  class XprtSwitch:
         for switch in XprtSwitch.get_by_name(args.switch):
             print(switch)
 
+    def set_property(args):
+        for switch in XprtSwitch.get_by_name(args.switch[0]):
+            resolved = socket.gethostbyname(args.newaddr[0])
+            for xprt in switch.xprts:
+                xprt.set_dstaddr(resolved)
+        print(switch)
+
 
 class RpcClient:
     def __init__(self, path):