From 34940a0a4c37f1c33a5bc5372032824e6157290d Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 27 Sep 2016 12:49:41 +0000 Subject: [PATCH] v0.4.9 allow URL for image path. Automatically download the image in the compute node Signed-off-by: tierno --- host_thread.py | 26 ++++++++++++++++++-------- openvimd.py | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/host_thread.py b/host_thread.py index cae8c60..e877505 100644 --- a/host_thread.py +++ b/host_thread.py @@ -757,9 +757,14 @@ class host_thread(threading.Thread): raise paramiko.ssh_exception.SSHException("Error deleting file: " + error_msg) def copy_file(self, source, destination, perserve_time=True): - command = 'cp --no-preserve=mode ' - if perserve_time: command += '--preserve=timestamps ' - command += source + ' ' + destination + if source[0:4]=="http": + command = "wget --no-verbose -O '{dst}' '{src}' 2>'{dst_result}' || cat '{dst_result}' >&2 && rm '{dst_result}'".format( + dst=destination, src=source, dst_result=destination + ".result" ) + else: + command = 'cp --no-preserve=mode' + if perserve_time: + command += ' --preserve=timestamps' + command += " '{}' '{}'".format(source, destination) print self.name, ': command:', command (_, _, stderr) = self.ssh_conn.exec_command(command) error_msg = stderr.read() @@ -783,24 +788,29 @@ class host_thread(threading.Thread): use_incremental_out = use_incremental new_backing_file = None local_file = None + file_from_local = True #in case incremental use is not decided, take the decision depending on the image #avoid the use of incremental if this image is already incremental - qemu_remote_info = self.qemu_get_info(remote_file) + if remote_file[0:4] == "http": + file_from_local = False + if file_from_local: + qemu_remote_info = self.qemu_get_info(remote_file) if use_incremental_out==None: - use_incremental_out = not 'backing file' in qemu_remote_info + use_incremental_out = not ( file_from_local and 'backing file' in qemu_remote_info) #copy recursivelly the backing files - if 'backing file' in qemu_remote_info: + if file_from_local and 'backing file' in qemu_remote_info: new_backing_file, _, _ = self.copy_remote_file(qemu_remote_info['backing file'], True) #check if remote file is present locally if use_incremental_out and remote_file in self.localinfo['files']: local_file = self.localinfo['files'][remote_file] local_file_info = self.get_file_info(local_file) - remote_file_info = self.get_file_info(remote_file) + if file_from_local: + remote_file_info = self.get_file_info(remote_file) if local_file_info == None: local_file = None - elif local_file_info[4]!=remote_file_info[4] or local_file_info[5]!=remote_file_info[5]: + elif file_from_local and (local_file_info[4]!=remote_file_info[4] or local_file_info[5]!=remote_file_info[5]): #local copy of file not valid because date or size are different. #TODO DELETE local file if this file is not used by any active virtual machine try: diff --git a/openvimd.py b/openvimd.py index 9176024..2e22121 100755 --- a/openvimd.py +++ b/openvimd.py @@ -30,7 +30,7 @@ and host controllers __author__="Alfonso Tierno" __date__ ="$10-jul-2014 12:07:15$" -__version__="0.4.8-r495" +__version__="0.4.9-r5002" version_date="Sep 2016" database_version="0.7" #expected database schema version -- 2.25.1