cas-admin | 28 ++++++++++++++--------------
lib/cas/network.py | 25 -------------------------
2 files changed, 14 insertions(+), 39 deletions(-)
New commits:
commit a7bfb11cc06a4e97e599b8aa3cbda3ac5fa5d745
Author: adam stokes <uzr(a)jak.rebo>
Date: Mon Oct 12 12:00:56 2009 -0400
- update paramiko transaction
diff --git a/cas-admin b/cas-admin
index ab9aac8..628ce89 100755
--- a/cas-admin
+++ b/cas-admin
@@ -21,6 +21,7 @@ import sys
import urlparse
import datetime
import calendar
+import paramiko
from cas.core import CoreBase
from cas.util import UtilBase, Logging
@@ -28,8 +29,6 @@ from cas.rpmutils import RPMBase
from cas.db import CasStorage, CasStorageException
from cas.cas_subprocess import Popen, PIPE
from cas.cas_shutil import rmtree
-from cas.network import Executor
-from paramiko import SSHClient
if sys.version_info[:2] < (2,3):
raise SystemExit("Python >= 2.3 required")
@@ -113,7 +112,8 @@ class CasServerHandler(object):
host = None
port = 22
hostname_count = 0
- ssh_obj = SSHClient()
+ ssh_obj = paramiko.SSHClient()
+ ssh_obj.load_host_keys(os.path.expanduser("~/.ssh/known_hosts"))
for server in ssh_obj.get_host_keys().keys():
server = server.strip()
# here we test for ports and apply accordingly
@@ -121,11 +121,15 @@ class CasServerHandler(object):
server, port = server.split(':')
# ssh keys place [host] when defining servers with ports
server = server[1:-1]
- results, err = Executor(server, port, settings["CASUSER"],
"/bin/uname -m").run()
- if err:
- self.casLog.debug(err)
+ try:
+ ssh_obj.connect(server, port=port,
username=settings["CASUSER"])
+ except paramiko.AuthenticationException, e:
+ self.casLog.debug("Failed to connect to %s: %s" % (server,e))
+ stdin, stdout, stderr = ssh_obj.exec_command("/bin/uname -m")
+ if stderr:
+ self.casLog.debug(stderr)
# clean up arch string
- for i in results:
+ for i in stdout.readlines():
arch = i.strip()
self.db.addServer(server, arch)
hostname_count = hostname_count + 1
@@ -173,8 +177,6 @@ class CasAdminApplication(object):
parser.add_option("-s","--server",
dest="server_init",
help="Build SERVER DB",
action="store_true",
default=False)
- parser.add_option("-f", "--hostkeys",
dest="ssh_hosts",
- help="Read in line delimeted server list for cas to
propagate")
parser.add_option("-p","--purge",
dest="purgeData",
help="Purge files default 90 days, customize with
-d",
action="store_true", default=False)
@@ -183,7 +185,6 @@ class CasAdminApplication(object):
(self.opts, args) = parser.parse_args()
self.buildDB = self.opts.buildDB
self.server_init = self.opts.server_init
- self.ssh_hosts = self.opts.ssh_hosts
self.purgeData = self.opts.purgeData
self.purgeDataDays = self.opts.purgeDataDays
@@ -220,10 +221,9 @@ class CasAdminApplication(object):
dbHandler = CasDatabaseHandler(self.casLog).run()
elif self.server_init:
self.casLog.info("Building CAS Server DB instance.")
- if not self.ssh_hosts:
- self.ssh_hosts = os.path.expanduser("~/.ssh/known_hosts")
- if not os.path.isfile(self.ssh_hosts):
- raise SystemExit(self.casLog.info("Unable to read ssh hosts keys,
please provide a proper keys file"))
+ if not os.path.isfile(os.path.expanduser("~/.ssh/known_hosts")):
+ raise SystemExit(self.casLog.info("Unable to read ssh hosts keys,
" \
+ "please make sure ssh client is configured properly"))
else:
serverHandler = CasServerHandler(self.casLog).run()
else:
diff --git a/lib/cas/network.py b/lib/cas/network.py
index 4cf5c15..1371730 100644
--- a/lib/cas/network.py
+++ b/lib/cas/network.py
@@ -66,28 +66,3 @@ class Download(object):
url.close()
return self.output
-class Executor(object):
- """ using paramiko to perform common tasks over
- ssh
- return : tuple of results, err
- """
- def __init__(self, remote_host, user, cmd):
- self.user = user
- self.host = remote_host
- self.cmd = cmd
- self.client = paramiko.SSHClient()
- self.client.load_system_host_keys()
-
- def go(self):
- try:
- self.client.connect(self.host, username=self.user)
- except paramiko.AuthenticationException:
- return False
-
- def run(self):
- if not self.go():
- return (None, 'Unable to authenticate to server' % (self.host,))
- stdin, stdout, stderr = self.client.exec_command(self.cmd)
- results = stdout.readlines()
- err = stderr.readlines()
- return (results, err)