Skip to content

Commit 62a6c16

Browse files
committed
c-any-nt command
1 parent 1c9873a commit 62a6c16

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install:
1414
install -m 755 c-ls $(BINDIR)
1515
install -m 755 c-foreach-nt $(BINDIR)
1616
install -m 755 c-cqlsh $(BINDIR)
17+
install -m 755 c-any-nt $(BINDIR)
1718
install -m 755 streams $(BINDIR)/cassandra-streams
1819
install -m 755 uyaml $(BINDIR)
1920
install -m 644 functions $(SHAREDIR)

c-any-nt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/python
2+
3+
4+
import random
5+
import sys
6+
7+
from cassandra.tools import get_instances
8+
9+
10+
def main():
11+
instance = random.choice(list(get_instances()))
12+
instance.nodetool.run(*sys.argv[1:])
13+
14+
15+
if __name__ == "__main__":
16+
main()

cassandra/tools/instances.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def __get(key):
4747
"""
4848
def restart(self):
4949
self.__log_info("Disabling client ports...")
50-
self.nodetool.disablebinary()
51-
self.nodetool.disablethrift()
50+
self.nodetool.run("disablebinary")
51+
self.nodetool.run("disablethrift")
5252
self.__log_info("Draining...")
53-
self.nodetool.drain()
53+
self.nodetool.run("drain")
5454
self.__log_info("Restarting service %s", self.service_name)
5555
call("systemctl", "restart", self.service_name)
5656
listening = False

cassandra/tools/nodetool.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
23
import logging
34

45
from .commands import call
@@ -9,19 +10,7 @@ def __init__(self, host, port):
910
self.host = host
1011
self.port = str(port)
1112

12-
def disablebinary(self):
13-
logging.debug("Disabling binary protocol (%s:%s)", self.host, self.port)
14-
self.__run("disablebinary")
15-
16-
def disablethrift(self):
17-
logging.debug("Disabling thrift (%s:%s)", self.host, self.port)
18-
self.__run("disablethrift")
19-
20-
def drain(self):
21-
logging.debug("Performing drain (%s:%s)", self.host, self.port)
22-
self.__run("drain")
23-
24-
def __run(self, *args):
13+
def run(self, *args):
2514
command = ["nodetool", "--host", self.host, "--port", self.port] + list(args)
2615
retcode = call(*command)
2716
if retcode != 0:

0 commit comments

Comments
 (0)