Standarized props names in ssh transports
Change-Id: I4533745364bfc75db36fb96b2a0b169a30f9a57f
This commit is contained in:
@@ -85,6 +85,12 @@ class SolarRunResult(object):
|
||||
return str(self.stdout)
|
||||
|
||||
|
||||
def find_named_transport(resource, req_name):
|
||||
transport = next(x for x in resource.transports()
|
||||
if x['name'] == req_name)
|
||||
return transport
|
||||
|
||||
|
||||
class SolarTransport(object):
|
||||
|
||||
_mode = None
|
||||
|
||||
@@ -29,7 +29,7 @@ class _SSHTransport(object):
|
||||
|
||||
_priority = 1
|
||||
|
||||
def _fabric_settings(self, resource):
|
||||
def settings(self, resource):
|
||||
transport = self.get_transport_data(resource)
|
||||
host = resource.ip()
|
||||
user = transport['user']
|
||||
@@ -37,6 +37,8 @@ class _SSHTransport(object):
|
||||
settings = {
|
||||
'host_string': "{}@{}:{}".format(user, host, port),
|
||||
}
|
||||
settings['port'] = port
|
||||
settings['host'] = host
|
||||
key = transport.get('key', None)
|
||||
password = transport.get('password', None)
|
||||
if not key and not password:
|
||||
@@ -90,7 +92,7 @@ class SSHSyncTransport(SyncTransport, _SSHTransport):
|
||||
def run_all(self):
|
||||
for executor in self.executors:
|
||||
resource = executor.resource
|
||||
with fabric_api.settings(**self._fabric_settings(resource)):
|
||||
with fabric_api.settings(**self.settings(resource)):
|
||||
executor.run(self)
|
||||
|
||||
|
||||
@@ -110,7 +112,7 @@ class SSHRunTransport(RunTransport, _SSHTransport):
|
||||
executor = fabric_api.sudo
|
||||
|
||||
managers = [
|
||||
fabric_api.settings(**self._fabric_settings(resource)),
|
||||
fabric_api.settings(**self.settings(resource)),
|
||||
]
|
||||
|
||||
cwd = kwargs.get('cwd')
|
||||
|
||||
@@ -31,20 +31,20 @@ class _RawSSHTransport(object):
|
||||
port = transport['port']
|
||||
key = transport.get('key')
|
||||
password = transport.get('password')
|
||||
return {'ssh_user': user,
|
||||
'ssh_key': key,
|
||||
'ssh_password': password,
|
||||
return {'user': user,
|
||||
'key': key,
|
||||
'password': password,
|
||||
'port': port,
|
||||
'ip': host}
|
||||
|
||||
def _ssh_command_host(self, settings):
|
||||
return '{}@{}'.format(settings['ssh_user'],
|
||||
return '{}@{}'.format(settings['user'],
|
||||
settings['ip'])
|
||||
|
||||
def _ssh_cmd(self, settings):
|
||||
if settings['ssh_key']:
|
||||
return ('ssh', '-i', settings['ssh_key'])
|
||||
elif settings['ssh_password']:
|
||||
if settings['key']:
|
||||
return ('ssh', '-i', settings['key'])
|
||||
elif settings['password']:
|
||||
return ('sshpass', '-e', 'ssh')
|
||||
else:
|
||||
raise Exception("No key and no password given")
|
||||
@@ -78,9 +78,9 @@ class RawSSHRunTransport(RunTransport, _RawSSHTransport):
|
||||
remote_cmd = '\"%s\"' % ' && '.join(commands)
|
||||
|
||||
settings = self.settings(resource)
|
||||
if settings.get('ssh_password'):
|
||||
if settings.get('password'):
|
||||
env = os.environ.copy()
|
||||
env['SSHPASS'] = settings['ssh_password']
|
||||
env['SSHPASS'] = settings['password']
|
||||
else:
|
||||
env = os.environ
|
||||
ssh_cmd = self._ssh_cmd(settings)
|
||||
|
||||
Reference in New Issue
Block a user