Skip to content

Commit

Permalink
Changed rsync method
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed Nov 16, 2017
1 parent c207b33 commit b2e0735
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions api/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_project_list():
return project_list


def rsync_dir_with_nodes(directory):
def rsync_dir_with_nodes(src, dest):
# retrieve nodes
nodes = get_all_registered_nodes()
already_sync = list()
Expand All @@ -162,15 +162,15 @@ def rsync_dir_with_nodes(directory):

# 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'],
data = {'directory': src+'/', 'dest_directory': dest+'/', 'node_ip': node['ip'],
'ssh_username': node['ssh_username'], 'ssh_password': node['ssh_password']}

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


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


Expand Down
2 changes: 1 addition & 1 deletion api/filters/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def put(self, request, filter_id, format=None):
if filter_type == 'native':
# synchronize metrics directory with all nodes
try:
rsync_dir_with_nodes(filter_dir)
rsync_dir_with_nodes(filter_dir, filter_dir)
except FileSynchronizationException as e:
return JSONResponse(e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

Expand Down
4 changes: 2 additions & 2 deletions api/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def put(self, request, metric_module_id):

# synchronize metrics directory with all nodes
try:
rsync_dir_with_nodes(settings.WORKLOAD_METRICS_DIR)
rsync_dir_with_nodes(settings.WORKLOAD_METRICS_DIR, settings.WORKLOAD_METRICS_DIR)
except FileSynchronizationException as e:
# print "FileSynchronizationException", e # TODO remove
return JSONResponse(e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Expand Down Expand Up @@ -247,7 +247,7 @@ def post(self, request):

# synchronize metrics directory with all nodes
try:
rsync_dir_with_nodes(settings.WORKLOAD_METRICS_DIR)
rsync_dir_with_nodes(settings.WORKLOAD_METRICS_DIR, settings.WORKLOAD_METRICS_DIR)
except FileSynchronizationException as e:
# print "FileSynchronizationException", e # TODO remove
return JSONResponse(e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Expand Down
11 changes: 8 additions & 3 deletions api/swift_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import requests
import paramiko
from socket import inet_aton
from api.common import JSONResponse, get_redis_connection, to_json_bools, get_token_connection
from api.common import JSONResponse, get_redis_connection, to_json_bools, get_token_connection,\
rsync_dir_with_nodes
from api.exceptions import FileSynchronizationException


Expand Down Expand Up @@ -169,6 +170,8 @@ def storage_policy_detail(request, storage_policy_id):

r.delete(key)

rsync_dir_with_nodes(settings.SWIFT_CFG_DEPLOY_DIR, '/etc/swift')

if not r.keys('storage-policy:*'):
r.delete('storage-policies:id')

Expand Down Expand Up @@ -310,10 +313,12 @@ def deploy_storage_policy(request, storage_policy_id):
ring.save(tmp_policy_file)

data = r.hgetall(key)
update_sp_files(settings.SWIFT_CFG_DEPLOY_DIR, storage_policy_id, {'name': data['name'], 'deprecated': data['deprecated'],
'default': data['default'], 'deployed': 'True'})
update_sp_files(settings.SWIFT_CFG_DEPLOY_DIR, storage_policy_id, {'name': data['name'],
'deprecated': data['deprecated'],
'default': data['default']})

copyfile(tmp_policy_file, deploy_policy_file)
rsync_dir_with_nodes(settings.SWIFT_CFG_DEPLOY_DIR, '/etc/swift')

r.hset(key, 'deployed', 'True')

Expand Down

0 comments on commit b2e0735

Please sign in to comment.