Add sftp support with password for freezer
Add ftp support for freezer. ref: https://storyboard.openstack.org/#!/story/2004332 Change-Id: I21bc8e9d2398a7ed87bcc5d08954933b0dd123b0 Story: #2004332 Task: #27917
This commit is contained in:
parent
fa423a58cc
commit
b876cbc11b
|
@ -79,7 +79,8 @@ DEFAULT_PARAMS = {
|
|||
'mode': 'fs', 'action': 'backup', 'shadow': '', 'shadow_path': '',
|
||||
'windows_volume': '', 'command': None, 'metadata_out': None,
|
||||
'storage': 'swift', 'ssh_key': os.path.join(home, '.ssh/id_rsa'),
|
||||
'ssh_username': '', 'ssh_host': '', 'ssh_port': DEFAULT_SSH_PORT,
|
||||
'ssh_username': '', 'ssh_password': '', 'ssh_host': '',
|
||||
'ssh_port': DEFAULT_SSH_PORT,
|
||||
'access_key': '', 'secret_key': '', 'endpoint': '',
|
||||
'compression': 'gzip', 'overwrite': False,
|
||||
'incremental': None, 'consistency_check': False,
|
||||
|
@ -459,22 +460,28 @@ _COMMON = [
|
|||
cfg.StrOpt('ssh-key',
|
||||
dest='ssh_key',
|
||||
default=DEFAULT_PARAMS['ssh_key'],
|
||||
help="Path to ssh-key for ssh storage only"
|
||||
help="Path to ssh-key for ssh(sftp) storage only"
|
||||
),
|
||||
cfg.StrOpt('ssh-password',
|
||||
dest='ssh_password',
|
||||
default=DEFAULT_PARAMS['ssh_password'],
|
||||
help="Remote password for ssh(sftp) storage"
|
||||
),
|
||||
cfg.StrOpt('ssh-username',
|
||||
dest='ssh_username',
|
||||
default=DEFAULT_PARAMS['ssh_username'],
|
||||
help="Remote username for ssh storage only"
|
||||
help="Remote username for ssh(sftp) storage only"
|
||||
),
|
||||
cfg.StrOpt('ssh-host',
|
||||
dest='ssh_host',
|
||||
default=DEFAULT_PARAMS['ssh_host'],
|
||||
help="Remote host for ssh storage only"
|
||||
help="Remote host for ssh(sftp) storage only"
|
||||
),
|
||||
cfg.IntOpt('ssh-port',
|
||||
dest='ssh_port',
|
||||
default=DEFAULT_PARAMS['ssh_port'],
|
||||
help="Remote port for ssh storage only (default 22)"
|
||||
help="Remote port for ssh(sftp) storage"
|
||||
" only (default 22)"
|
||||
),
|
||||
cfg.StrOpt('config',
|
||||
dest='config',
|
||||
|
|
|
@ -213,12 +213,22 @@ def storage_from_dict(backup_args, max_segment_size):
|
|||
storage_path=container,
|
||||
max_segment_size=max_segment_size)
|
||||
elif storage_name == "ssh":
|
||||
storage = ssh.SshStorage(
|
||||
container,
|
||||
backup_args['ssh_key'], backup_args['ssh_username'],
|
||||
backup_args['ssh_host'],
|
||||
int(backup_args['ssh_port']),
|
||||
max_segment_size=max_segment_size)
|
||||
if backup_args['ssh_password']:
|
||||
storage = ssh.SshStorage(
|
||||
container,
|
||||
backup_args['ssh_username'],
|
||||
backup_args['ssh_host'],
|
||||
int(backup_args['ssh_port']),
|
||||
max_segment_size=max_segment_size,
|
||||
remote_pwd=backup_args['ssh_password'])
|
||||
else:
|
||||
storage = ssh.SshStorage(
|
||||
container,
|
||||
backup_args['ssh_username'],
|
||||
backup_args['ssh_host'],
|
||||
int(backup_args['ssh_port']),
|
||||
max_segment_size=max_segment_size,
|
||||
ssh_key_path=backup_args['ssh_key'])
|
||||
else:
|
||||
raise Exception("No storage found for name {0}".format(
|
||||
backup_args['storage']))
|
||||
|
|
|
@ -31,14 +31,15 @@ class SshStorage(fslike.FsLikeStorage):
|
|||
"""
|
||||
_type = 'ssh'
|
||||
|
||||
def __init__(self, storage_path, ssh_key_path,
|
||||
remote_username, remote_ip, port, max_segment_size):
|
||||
def __init__(self, storage_path, remote_username, remote_ip, port,
|
||||
max_segment_size, ssh_key_path=None, remote_pwd=None):
|
||||
"""
|
||||
:param storage_path: directory of storage
|
||||
:type storage_path: str
|
||||
:return:
|
||||
"""
|
||||
self.ssh_key_path = ssh_key_path
|
||||
self.remote_pwd = remote_pwd
|
||||
self.remote_username = remote_username
|
||||
self.remote_ip = remote_ip
|
||||
self.port = port
|
||||
|
@ -59,13 +60,19 @@ class SshStorage(fslike.FsLikeStorage):
|
|||
raise ValueError('Please provide --ssh-host value.')
|
||||
elif not self.remote_username:
|
||||
raise ValueError('Please provide --ssh-username value.')
|
||||
elif self.remote_pwd:
|
||||
return True
|
||||
elif not self.ssh_key_path:
|
||||
raise ValueError('Please provide path to ssh key using '
|
||||
'--ssh-key argument.')
|
||||
'--ssh-key argument')
|
||||
elif not os.path.exists(self.ssh_key_path):
|
||||
raise ValueError('The {0} is required, please ensure it '
|
||||
'exists and ensure backup node can login '
|
||||
'to {1} as user {2} without password '
|
||||
raise ValueError('1.The {0} is required, please ensure '
|
||||
'it exists and ensure backup node can '
|
||||
'login to {1} as user {2} '
|
||||
'without password.\n'
|
||||
'2. --ssh-password argument is required and'
|
||||
'ensure backup node can login to {1} '
|
||||
'as user {2} with password.'
|
||||
.format(self.ssh_key_path, self.remote_ip,
|
||||
self.remote_username))
|
||||
return True
|
||||
|
@ -74,8 +81,12 @@ class SshStorage(fslike.FsLikeStorage):
|
|||
ssh = paramiko.SSHClient()
|
||||
ssh.load_system_host_keys()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect(self.remote_ip, username=self.remote_username,
|
||||
key_filename=self.ssh_key_path, port=self.port)
|
||||
if self.remote_pwd:
|
||||
ssh.connect(self.remote_ip, username=self.remote_username,
|
||||
password=self.remote_pwd, port=self.port)
|
||||
else:
|
||||
ssh.connect(self.remote_ip, username=self.remote_username,
|
||||
key_filename=self.ssh_key_path, port=self.port)
|
||||
|
||||
# we should keep link to ssh to prevent garbage collection
|
||||
self.ssh = ssh
|
||||
|
|
Loading…
Reference in New Issue