From bddbf6fa577541bc1982affd30d41b7abb9bd36d Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 12 Nov 2024 19:50:14 +0100 Subject: [PATCH] refs #1101 add ogMcastSendFile() --- client/lib/engine/bin/ProtocolLib.py | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/client/lib/engine/bin/ProtocolLib.py b/client/lib/engine/bin/ProtocolLib.py index 1d09bab..d14fc7c 100644 --- a/client/lib/engine/bin/ProtocolLib.py +++ b/client/lib/engine/bin/ProtocolLib.py @@ -11,6 +11,7 @@ import FileSystemLib import StringLib import NetLib import DiskLib +import FileLib #/** #@file ProtocolLib.py @@ -366,6 +367,54 @@ def ogMcastSyntax (op, sess, file=None, device=None, tool=None, level=None): #*/ ## # +#ogMcastSendFile [str_REPOSITORY] [int_ndisk int_npart] /Relative_path_file sesionMcast" \ +#ogMcastSendFile (disk=1, par=1, file='/aula1/winxp.img', sess='sesionMcast') +#ogMcastSendFile (from='REPO', file='/aula1/ubuntu.iso', sess='sesionMcast') +#ogMcastSendFile (from='CACHE', file='/aula1/winxp.img', sess='sesionMcast') +#ogMcastSendFile ( file='/opt/opengnsys/images/aula1/hd500.vmx', sess='sesionMcast') +def ogMcastSendFile (disk=None, par=None, take_from=None, file=None, sess=None): + if file is None: + raise TypeError ('missing required argument: "file"') + if sess is None: + raise TypeError ('missing required argument: "sess"') + + if take_from is not None: + if disk is None and par is None: + ## we were given take_from= + source = FileLib.ogGetPath (src=take_from, file=file) + dev_err = ' '.join ([take_from, file]) + print (f'ogGetPath (src=({take_from}), file=({file})) = source ({source})') + else: + raise TypeError ('argument "take_from" can be specified along neither "disk" nor "par"') + + else: + if disk is not None and par is not None: + ## we were given disk= par= + source = FileLib.ogGetPath (src=f'{disk} {par}', file=file) + dev_err = ' '.join ([disk, par, file]) + print (f'ogGetPath (src=({disk} {par}), file=({file})) = source ({source})') + elif disk is None and par is None: + ## we were given nothing + source = FileLib.ogGetPath (file=file) + dev_err = file + print (f'ogGetPath (file=({file})) = source ({source})') + else: + raise TypeError ('if one of "disk" and "par" are specified, then both must be') + + path2 = FileLib.ogGetPath (file=source) + print (f'path2 ({path2})') + if not path2: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found') + return + + cmd = ogMcastSyntax ('SENDFILE', sess, file=source) + if not cmd: return None + print (f'cmd ({cmd})') + try: + subprocess.run (cmd, shell=True, check=True) + except subprocess.CalledProcessError: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTSENDFILE, ' ') + return None