Skip to content

Commit

Permalink
Supporting fixes for SSH key distribution in the cluster layer
Browse files Browse the repository at this point in the history
  • Loading branch information
erl-hpe committed Jun 11, 2024
1 parent 65d4667 commit b6757b7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
48 changes: 23 additions & 25 deletions vtds_provider_gcp/api_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -278,25 +279,22 @@ 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
ContextualError exception if it fails. If the 'blocking' option
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
Expand Down
71 changes: 38 additions & 33 deletions vtds_provider_gcp/private/api_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion vtds_provider_gcp/private/private_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b6757b7

Please sign in to comment.