Skip to content

Commit

Permalink
Rsync threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed Oct 26, 2017
1 parent 811760b commit 5649457
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 231 deletions.
38 changes: 22 additions & 16 deletions api/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from api.exceptions import FileSynchronizationException
from pyactor.context import set_context, create_host
from swiftclient import client as swift_client

import threading
import errno
import hashlib
import calendar
Expand Down Expand Up @@ -154,22 +154,28 @@ def get_project_list():
def rsync_dir_with_nodes(directory):
# retrieve nodes
nodes = get_all_registered_nodes()
already_sync = list()
for node in nodes:
logger.info("Rsync - pushing to "+node['type']+":"+node['name'])
if not node.viewkeys() & {'ssh_username', 'ssh_password'}:
raise FileSynchronizationException("SSH credentials missing. Please, set the credentials for this "+node['type']+" node: "+node['name'])

# Directory is only synchronized if node status is UP
if calendar.timegm(time.gmtime()) - int(float(node['last_ping'])) <= NODE_STATUS_THRESHOLD:
# The basename of the path is not needed because it will be the same as source dir
dest_directory = os.path.dirname(directory)
data = {'directory': directory, 'dest_directory': dest_directory, 'node_ip': node['ip'],
'ssh_username': node['ssh_username'], 'ssh_password': node['ssh_password']}
rsync_command = 'sshpass -p {ssh_password} rsync --progress --delete -avrz -e ssh {directory} {ssh_username}@{node_ip}:{dest_directory}'.format(**data)

ret = os.system(rsync_command)
if ret != 0:
raise FileSynchronizationException("An error occurred copying files to Swift nodes. Please check the SSH credentials of this "+node['type']+" node: "+node['name'])
if node['ip'] not in already_sync:
already_sync.append(node['ip'])
to_json_bools(node, 'ssh_access')
if not node['ssh_access']:
raise FileSynchronizationException("SSH credentials missing. Please, set the credentials for this "+node['type']+" node: "+node['name'])

# Directory is only synchronized if node status is UP
if calendar.timegm(time.gmtime()) - int(float(node['last_ping'])) <= NODE_STATUS_THRESHOLD:
# The basename of the path is not needed because it will be the same as source dir
logger.info("Rsync - pushing to "+node['type']+":"+node['name'])
dest_directory = os.path.dirname(directory)
data = {'directory': directory, 'dest_directory': dest_directory, 'node_ip': node['ip'],
'ssh_username': node['ssh_username'], 'ssh_password': node['ssh_password']}

threading.Thread(target=rsync, args=(node, data)).start()


def rsync(node, data):
rsync_command = 'sshpass -p {ssh_password} rsync --progress --delete -avrz -e ssh {directory} {ssh_username}@{node_ip}:{dest_directory}'.format(**data)
os.system(rsync_command)


def get_all_registered_nodes():
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions api/swift/ansible/playbook/swift_cluster_nodes

This file was deleted.

This file was deleted.

86 changes: 0 additions & 86 deletions api/swift/storage_policies_utils.py

This file was deleted.

0 comments on commit 5649457

Please sign in to comment.