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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Anna Schumaker <Anna.Schumaker@xxxxxxxxxx>

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@xxxxxxxxxx>
---
v8: Only call socket.gethostbyname() once instead of for each xprt
---
 tools/rpcctl/rpcctl.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

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):
-- 
2.35.1




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux