Using Parmiko trying to login to the remote machine and executing the cqlsh commands, but it is not working
I tried using paramiko to execute cqlsh command on remote machine , but not getting any result. I tried with dse.cluster also, but getting AuthenticationFailed with bad credentials. Credentials are correct only, all out lab machines are file-based authenticated.
import paramiko
hostname = '10.XX.XX.XX'
username = 'root'
gSSHkey = 'D:\\LoginKeys\\login-id_rsa-key.ppk'
#cmds = ["cqlsh -u casadmin -pmotive 10.XX.XX.XX 9042 -k casadmin", "select count(*) from dia_scs_config ;"]
sshcon = paramiko.SSHClient() # will create the object
sshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # no known_hosts error
sshcon.connect(hostname=hostname, username=username, key_filename=gSSHkey) # no passwd needed
for i in range(len(cmds)):
stdin, stdout, stderr = sshcon.exec_command(cmds[i])
output = stdout.readlines()
print(output)
for line in output:
print(line)
sshcon.close()
++++++++++++++++++++++++++++++++++++++++++++===
from dse.cluster import Cluster
from dse.auth import PlainTextAuthProvider
auth_provider = PlainTextAuthProvider(
username='casadmin', password='casadmin')
cluster = Cluster(contact_points=['10.XX.XX.XX'],
port=9042, auth_provider=auth_provider)
session = cluster.connect('casadmin')
print ("connected")
print (session.execute("select count(*) from dia_scs_config")[0])
trying to connect to Cassandra VM which is having key-based authentication is preset. Any sample working to connect to Cassandra vm which is having key-based authentication will be much helpfull.