paramiko.util.log_to_file("/var/log/paramiko.log")
-class setup:
+class SetUp:
def __init__(self, *args):
self.args = args
def keystonepass(self):
com = self.args[0]
client = paramiko.SSHClient()
+ privatekeyfile = os.path.expanduser('/root/.ssh/id_rsa')
+ selectedkey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
- client.connect(INSTALLER_IP, port=22, username='stack')
+ client.connect(INSTALLER_IP, port=22, username='stack',
+ pkey=selectedkey)
except paramiko.SSHException:
logger.error("Password is invalid for "
"undercloud host: {0}".format(INSTALLER_IP))
return stdout.read()
client.close()
- def getOCKey(self):
+ def getockey(self):
remotekey = self.args[0]
localkey = self.args[1]
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ privatekeyfile = os.path.expanduser('/root/.ssh/id_rsa')
+ selectedkey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
+ transport = paramiko.Transport((INSTALLER_IP, 22))
+ transport.connect(username='stack', pkey=selectedkey)
try:
- client.connect(INSTALLER_IP, port=22, username='stack')
- sftp = client.open_sftp()
- sftp.get(remotekey, localkey)
+ sftp = paramiko.SFTPClient.from_transport(transport)
except paramiko.SSHException:
logger.error("Authentication failed for "
- "host: {0}".format(self.host))
+ "host: {0}".format(INSTALLER_IP))
except paramiko.AuthenticationException:
logger.error("Authentication failed for "
- "host: {0}".format(self.host))
+ "host: {0}".format(INSTALLER_IP))
except socket.error:
logger.error("Socker Connection failed for "
- "undercloud host: {0}".format(self.host))
- client.close()
+ "undercloud host: {0}".format(INSTALLER_IP))
+ sftp.get(remotekey, localkey)
+ sftp.close()
+ transport.close()
-class connectionManager:
+class ConnectionManager:
def __init__(self, host, port, user, localkey, *args):
self.host = host
self.port = port
com = self.args[2]
client = paramiko.SSHClient()
+ privatekeyfile = os.path.expanduser('/root/.ssh/id_rsa')
+ selectedkey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connection to undercloud
try:
- client.connect(INSTALLER_IP, port=22, username='stack')
+ client.connect(INSTALLER_IP, port=22, username='stack',
+ pkey=selectedkey)
except paramiko.SSHException:
logger.error("Authentication failed for "
"host: {0}".format(self.host))
com = self.args[0]
client = paramiko.SSHClient()
+ privatekeyfile = os.path.expanduser('/root/.ssh/id_rsa')
+ selectedkey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connection to undercloud
try:
- client.connect(INSTALLER_IP, port=22, username='stack')
+ client.connect(INSTALLER_IP, port=22, username='stack',
+ pkey=selectedkey)
except paramiko.SSHException:
logger.error("Authentication failed for "
"host: {0}".format(self.host))
chan = remote_client.get_transport().open_session()
chan.get_pty()
- f = chan.makefile()
+ feed = chan.makefile()
chan.exec_command(com)
- print f.read()
+ print feed.read()
remote_client.close()
client.close()
reportname = self.args[2]
resultsname = self.args[3]
client = paramiko.SSHClient()
+ privatekeyfile = os.path.expanduser('/root/.ssh/id_rsa')
+ selectedkey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connection to overcloud
try:
- client.connect(INSTALLER_IP, port=22, username='stack')
+ client.connect(INSTALLER_IP, port=22, username='stack',
+ pkey=selectedkey)
except paramiko.SSHException:
logger.error("Authentication failed for "
"host: {0}".format(self.host))
# Grab Undercloud key
remotekey = cfgparse.get('undercloud', 'remotekey')
localkey = cfgparse.get('undercloud', 'localkey')
-setup = connect.setup(remotekey, localkey)
-setup.getOCKey()
+setup = connect.SetUp(remotekey, localkey)
+setup.getockey()
# Configure Nova Credentials
com = 'sudo hiera admin_password'
-setup = connect.setup(com)
+setup = connect.SetUp(com)
keypass = setup.keystonepass()
auth = v2.Password(auth_url='http://{0}:5000/v2.0'.format(INSTALLER_IP),
username='admin',
localpath = os.getcwd() + '/scripts/createfiles.py'
remotepath = '/tmp/createfiles.py'
com = 'python /tmp/createfiles.py'
- connect = connect.connectionManager(host, port, user, localkey,
+ connect = connect.ConnectionManager(host, port, user, localkey,
localpath, remotepath, com)
tmpdir = connect.remotescript()
def install_pkg(host, port, user, localkey):
import connect
com = 'sudo yum -y install openscap-scanner scap-security-guide'
- connect = connect.connectionManager(host, port, user, localkey, com)
+ connect = connect.ConnectionManager(host, port, user, localkey, com)
connect.remotecmd()
report,
cpe,
secpolicy)
- connect = connect.connectionManager(host, port, user, localkey, com)
+ connect = connect.ConnectionManager(host, port, user, localkey, com)
connect.remotecmd()
elif scantype == 'oval':
com = '{0} oval eval --results {1}/{2} '
'--report {1}/{3} {4}'.format(oscapbin, tmpdir.rstrip(),
results, report, secpolicy)
- connect = connect.connectionManager(host, port, user, localkey, com)
+ connect = connect.ConnectionManager(host, port, user, localkey, com)
connect.remotecmd()
else:
com = '{0} oval-collect '.format(oscapbin)
- connect = connect.connectionManager(host, port, user, localkey, com)
+ connect = connect.ConnectionManager(host, port, user, localkey, com)
connect.remotecmd()
report = cfgparse.get(nodetype, 'report')
results = cfgparse.get(nodetype, 'results')
reportfile = '{0}/{1}'.format(tmpdir.rstrip(), report)
- connect = connect.connectionManager(host, port, user, localkey, dl_folder,
+ connect = connect.ConnectionManager(host, port, user, localkey, dl_folder,
reportfile, report, results)
connect.download_reports()
def removepkg(host, port, user, localkey, nodetype):
import connect
com = 'sudo yum -y remove openscap-scanner scap-security-guide'
- connect = connect.connectionManager(host, port, user, localkey, com)
+ connect = connect.ConnectionManager(host, port, user, localkey, com)
connect.remotecmd()
def cleandir(host, port, user, localkey, nodetype):
import connect
com = 'sudo rm -r {0}'.format(tmpdir.rstrip())
- connect = connect.connectionManager(host, port, user, localkey, com)
+ connect = connect.ConnectionManager(host, port, user, localkey, com)
connect.remotecmd()