Configurable SSH port and user
Change-Id: Iafb81b2bfdc742bb52a72bb07ee58622f81d3c84
This commit is contained in:
parent
080e782b3d
commit
7f58f90750
|
@ -50,6 +50,9 @@ class DockerMixin(object):
|
|||
def get_container_directory(self):
|
||||
iid = self.get_docker_id()
|
||||
|
||||
if not iid:
|
||||
raise exc.DockerError('Docker ID could not be fetched')
|
||||
|
||||
paths = self.ssh_command(
|
||||
'ls %s | grep %s' % (DOCKER_DEVICEMAPPER_PATH, iid)
|
||||
).decode('utf-8')
|
||||
|
@ -266,7 +269,7 @@ class ShellCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
|||
if not command:
|
||||
command = '/bin/bash'
|
||||
|
||||
return self.ssh_command_interactive(self.container_command(command))
|
||||
return self.ssh_command_interactive(*self.container_command(command))
|
||||
|
||||
|
||||
class StartCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
|
|
|
@ -37,10 +37,10 @@ class Info(command.BaseCommand):
|
|||
|
||||
six.print_('URLS:')
|
||||
for name, port, info in urls:
|
||||
six.print_('{name:{fill}{align}{width}}http://{IP}:{port:{fill}'
|
||||
six.print_('{name:{fill}{align}{width}}http://{ip}:{port:{fill}'
|
||||
'{align}{width}}{info}'.format(
|
||||
name=name,
|
||||
IP=self.app_args.IP,
|
||||
ip=self.app_args.ip,
|
||||
port=port,
|
||||
info=info,
|
||||
fill=' ',
|
||||
|
|
|
@ -32,10 +32,12 @@ from fuel_dev_tools.docker import nailgun
|
|||
from fuel_dev_tools.docker import nginx
|
||||
from fuel_dev_tools import exc
|
||||
from fuel_dev_tools import info
|
||||
from fuel_dev_tools import ssh
|
||||
|
||||
|
||||
COMMANDS = {
|
||||
'info': info.Info,
|
||||
'ssh': ssh.SSH,
|
||||
|
||||
'astute-id': astute.Id,
|
||||
'astute-config': astute.Config,
|
||||
|
@ -94,10 +96,20 @@ class ToolsApp(app.App):
|
|||
description, version)
|
||||
|
||||
parser.add_argument(
|
||||
'--IP',
|
||||
'--ip',
|
||||
default='10.20.0.2',
|
||||
help='Fuel master node IP address'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p', '--port',
|
||||
default='22',
|
||||
help='Fuel master node SSH port'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-U', '--user',
|
||||
default='root',
|
||||
help='Fuel master node SSH user'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-I', '--identity-file',
|
||||
default=os.path.join(
|
||||
|
|
|
@ -18,7 +18,8 @@ import subprocess
|
|||
import fabric
|
||||
from fabric import api as fabric_api
|
||||
|
||||
import exc
|
||||
from fuel_dev_tools import command
|
||||
from fuel_dev_tools import exc
|
||||
|
||||
|
||||
SSH_PASSWORD_CHECKED = False
|
||||
|
@ -31,8 +32,8 @@ class SSHMixin(object):
|
|||
super(SSHMixin, self).__init__(*args, **kwargs)
|
||||
|
||||
if self.app_args:
|
||||
fabric_api.env.host_string = self.app_args.IP
|
||||
fabric_api.env.user = 'root'
|
||||
fabric_api.env.host_string = '{0}:{1}'.format(self.app_args.ip, self.app_args.port)
|
||||
fabric_api.env.user = self.app_args.user
|
||||
|
||||
if not self.app_args.debug:
|
||||
for key in fabric.state.output:
|
||||
|
@ -54,8 +55,8 @@ class SSHMixin(object):
|
|||
# points to some non-existing domain (with misconfigured reverse-DNS
|
||||
# lookups each SSH connection can be quite slow)
|
||||
result = fabric_api.run(
|
||||
"sed -i 's/^%(IP)s.*/%(IP)s localhost/' /etc/hosts" % {
|
||||
'IP': self.app_args.IP
|
||||
"sed -i 's/^%(ip)s.*/%(ip)s localhost/' /etc/hosts" % {
|
||||
'ip': self.app_args.ip
|
||||
}
|
||||
)
|
||||
self.print_debug(result)
|
||||
|
@ -77,9 +78,11 @@ class SSHMixin(object):
|
|||
try:
|
||||
subprocess.check_output([
|
||||
'ssh',
|
||||
'-p',
|
||||
self.app_args.port,
|
||||
'-o',
|
||||
'PasswordAuthentication=no',
|
||||
'root@%s' % self.app_args.IP,
|
||||
'%s@%s' % (self.app_args.user, self.app_args.ip),
|
||||
'echo 1'
|
||||
], stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError as e:
|
||||
|
@ -101,6 +104,11 @@ class SSHMixin(object):
|
|||
if args:
|
||||
command = ' '.join(args)
|
||||
|
||||
self.print_debug('interactive', command)
|
||||
self.print_debug('interactive %s' % command)
|
||||
|
||||
fabric_api.open_shell(command=command)
|
||||
|
||||
|
||||
class SSH(SSHMixin, command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.ssh_command_interactive('')
|
||||
|
|
Loading…
Reference in New Issue