diff --git a/vtds_provider_gcp/api_objects.py b/vtds_provider_gcp/api_objects.py index 763a7a7..231d255 100644 --- a/vtds_provider_gcp/api_objects.py +++ b/vtds_provider_gcp/api_objects.py @@ -238,7 +238,7 @@ class BladeSSHConnection(BladeConnection, metaclass=ABCMeta): @abstractmethod def copy_to( self, source, destination, - recurse=False, blocking=True, logfiles=None, **kwargs + recurse=False, blocking=True, logname=None, **kwargs ): """Copy a file from a path on the local machine ('source') to a path on the virtual blade ('dest'). The SCP operation is run @@ -248,27 +248,28 @@ def copy_to( and passed to subprocess.Popen() or simply passed on to subprocess.Popen() as keyword arguments. - If the 'logfiles' argument is provided, it contains a two - element tuple telling run_command where to put standard output - and standard error logging for the copy respectively. - Normally, these are specified as pathnames to log - files. Either or both can also be a file object or None. If a - file object is used, the output is written to the file. If - None is used, the corresponding output is not redirected and - the default Popen() behavior is used. + If the 'recurse' argument is 'True' and the source is a + directory, the directory and all of its descendents will be + copied. Otherwise, the source should be a file and it alone + will be copied. - If the 'async' option is False (default), copy_to() will block + If the 'blocking' option is True (default), copy_to() will block waiting for the copy to complete (or fail) and raise a - ContextualError exception if it fails. If the 'async' option - is True, copy_to() will return immediately once the Popen() + ContextualError exception if it fails. If the 'blocking' option + is False, copy_to() will return immediately once the Popen() object is created and let the caller manage the sub-process. + If the 'logname' argument is provided and not None, use the + string found there to compose a pair of log files to capture + standard output and standard error. Otherwise a generic log + name is created. + """ @abstractmethod def copy_from( self, source, destination, - recurse=False, blocking=True, logfiles=None, **kwargs + recurse=False, blocking=True, logname=None, **kwargs ): """Copy a file from a path on the blade ('source') to a path on the local machine ('dest'). The SCP operation is run under @@ -278,18 +279,10 @@ def copy_from( passed to subprocess.Popen() or simply passed on to subprocess.Popen() as keyword arguments. - If the 'recurse' option is True and the local file is a - directory, the directory and all of its descendants will be - copied. - - If the 'logfiles' argument is provided, it contains a two - element tuple telling run_command where to put standard output - and standard error logging for the copy respectively. - Normally, these are specified as pathnames to log - files. Either or both can also be a file object or None. If a - file object is used, the output is written to the file. If - None is used, the corresponding output is not redirected and - the default Popen() behavior is used. + If the 'recurse' argument is 'True' and the source is a + directory, the directory and all of its descendents will be + copied. Otherwise, the source should be a file and it alone + will be copied. If the 'blocking' option is True (default), copy_from() will block waiting for the copy to complete (or fail) and raise a @@ -297,6 +290,11 @@ def copy_from( is False, copy_from() will return immediately once the Popen() object is created and let the caller manage the sub-process. + If the 'logname' argument is provided and not None, use the + string found there to compose a pair of log files to capture + standard output and standard error. Otherwise a generic log + name is created. + """ @abstractmethod diff --git a/vtds_provider_gcp/private/api_objects.py b/vtds_provider_gcp/private/api_objects.py index 1d56910..f58a8ab 100644 --- a/vtds_provider_gcp/private/api_objects.py +++ b/vtds_provider_gcp/private/api_objects.py @@ -643,7 +643,7 @@ def _render_cmd(self, cmd): def copy_to( self, source, destination, - recurse=False, blocking=True, logfiles=None, **kwargs + recurse=False, blocking=True, logname=None, **kwargs ): """Copy a file from a path on the local machine ('source') to a path on the virtual blade ('dest'). The SCP operation is run @@ -653,18 +653,10 @@ def copy_to( and passed to subprocess.Popen() or simply passed on to subprocess.Popen() as keyword arguments. - If the 'recurse' option is True and the local file is a - directory, the directory and all of its descendants will be - copied. - - If the 'logfiles' argument is provided, it contains a two - element tuple telling run_command where to put standard output - and standard error logging for the copy respectively. - Normally, these are specified as pathnames to log - files. Either or both can also be a file object or None. If a - file object is used, the output is written to the file. If - None is used, the corresponding output is not redirected and - the default Popen() behavior is used. + If the 'recurse' argument is 'True' and the source is a + directory, the directory and all of its descendents will be + copied. Otherwise, the source should be a file and it alone + will be copied. If the 'blocking' option is True (default), copy_to() will block waiting for the copy to complete (or fail) and raise a @@ -673,8 +665,20 @@ def copy_to( Popen() object is created and let the caller manage the sub-process. + If the 'logname' argument is provided and not None, use the + string found there to compose a pair of log files to capture + standard output and standard error. Otherwise a generic log + name is created. + """ - logfiles = logfiles if logfiles is not None else (None, None) + logname = ( + logname if logname is not None else + "copy-to-%s-%s" % (source, destination) + ) + logfiles = log_paths( + self.common.build_dir(), + "%s-%s" % (logname, self.blade_hostname()) + ) recurse_option = ['-r'] if recurse else [] cmd = [ 'scp', '-i', self.private_key_path, *recurse_option, *self.options, @@ -698,7 +702,7 @@ def copy_to( def copy_from( self, source, destination, - recurse=False, blocking=True, logfiles=None, **kwargs + recurse=False, blocking=True, logname=None, **kwargs ): """Copy a file from a path on the blade ('source') to a path on the local machine ('dest'). The SCP operation is run under @@ -708,18 +712,10 @@ def copy_from( passed to subprocess.Popen() or simply passed on to subprocess.Popen() as keyword arguments. - If the 'recurse' option is True and the remote file is a - directory, the directory and all of its descendants will be - copied. - - If the 'logfiles' argument is provided, it contains a two - element tuple telling run_command where to put standard output - and standard error logging for the copy respectively. - Normally, these are specified as pathnames to log - files. Either or both can also be a file object or None. If a - file object is used, the output is written to the file. If - None is used, the corresponding output is not redirected and - the default Popen() behavior is used. + If the 'recurse' argument is 'True' and the source is a + directory, the directory and all of its descendents will be + copied. Otherwise, the source should be a file and it alone + will be copied. If the 'blocking' option is True (default), copy_from() will block waiting for the copy to complete (or fail) and raise a @@ -728,8 +724,20 @@ def copy_from( Popen() object is created and let the caller manage the sub-process. + If the 'logname' argument is provided and not None, use the + string found there to compose a pair of log files to capture + standard output and standard error. Otherwise a generic log + name is created. + """ - logfiles = logfiles if logfiles is not None else (None, None) + logname = ( + logname if logname is not None else + "copy-from-%s-%s" % (source, destination) + ) + logfiles = log_paths( + self.common.build_dir(), + "%s-%s" % (logname, self.blade_hostname()) + ) recurse_option = ['-r'] if recurse else [] cmd = [ 'scp', '-i', self.private_key_path, *recurse_option, *self.options, @@ -856,11 +864,8 @@ def copy_to( wait_args_list = [ ( blade_connection.copy_to( - source, destination, recurse, False, - log_paths( - self.common.build_dir(), - "%s-%s" % (logname, blade_connection.blade_hostname()) - ) + source, destination, recurse=recurse, blocking=False, + logname=logname ), "scp %s to root@%s:%s" % ( source, diff --git a/vtds_provider_gcp/private/private_provider.py b/vtds_provider_gcp/private/private_provider.py index 33c8903..d5c30b7 100644 --- a/vtds_provider_gcp/private/private_provider.py +++ b/vtds_provider_gcp/private/private_provider.py @@ -125,7 +125,7 @@ def open_safe(path, flags): with open( pub_key, mode='w', opener=open_safe, encoding='UTF-8' ) as pub_key_file: - pub_key_file.write(keys['public']) + pub_key_file.write("%s\n" % keys['public']) with open( priv_key, mode='w', opener=open_safe, encoding='UTF-8' ) as priv_key_file: