Compare commits

..

No commits in common. "main" and "protoopts" have entirely different histories.

26 changed files with 99 additions and 242 deletions

View File

@ -5,108 +5,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.8.0] - 2025-04-23
### Added
- Have the oglive agent send /stopped on poweroff or restart
## [0.7.2] - 2025-04-21
### Fixed
- Have the partitioning functions return a meaningful rc
## [0.7.1] - 2025-04-15
### Fixed
- getConfiguration.py: don't fail if NTFS filesystems are mounted ro
## [0.7.0] - 2025-04-15
### Removed
- Removed references to ogGlobals.OGLOG in python code
## [0.6.1] - 2025-04-15
### Fixed
- Fixed capturing of partclone output and management of return value
## [0.6.0] - 2025-04-15
### Changed
- ogGetIpAddress() is no longer required in ogGlobals--move it back into NetLib
## [0.5.0] - 2025-04-15
### Changed
- Log to /var/log/clone-engine.log and clone-engine.json.log
## [0.4.1] - 2025-04-10
### Fixed
- restoreImage.py: return negated rc to the shell
## [0.4.0] - 2025-04-10
### Changed
- Make /opt/opengnsys writable in clients, just like it used to be
## [0.3.6] - 2025-04-09
### Fixed
- Fixed ogReduceFs
## [0.3.5] - 2025-04-09
### Fixed
- Fixed syntax
## [0.3.4] - 2025-04-09
### Fixed
- Fixed usage of ogEcho in FileSystemLib
## [0.3.3] - 2025-04-09
### Fixed
- Kill coproc'ed browser in all execution branches in Configurar.py
## [0.3.2] - 2025-04-07
### Fixed
- Handle invalid number of arguments pass to functions/ogCopyFile
## [0.3.1] - 2025-04-03
### Fixed
- Fixed invocation to ogCheckIpAddress in interfaceAdm/CrearImagen.py
## [0.3.0] - 2025-04-03
### Removed
- Removed burg and rsync 3.1
## [0.2.6] - 2025-03-31
### Fixed
- Restore qt4 browser
## [0.2.5] - 2025-03-31
### Fixed

View File

@ -48,18 +48,7 @@ pipeline {
}
}
}
stage('Generate Changelog (Nightly)'){
when {
branch 'main'
}
steps {
script {
def devName = params.DEV_NAME ? params.DEV_NAME : env.DEFAULT_DEV_NAME
def devEmail = params.DEV_EMAIL ? params.DEV_EMAIL : env.DEFAULT_DEV_EMAIL
generateDebianChangelog(env.BUILD_DIR, devName, devEmail,"nightly")
}
}
}
stage('Build') {
steps {
script {
@ -82,19 +71,6 @@ pipeline {
}
}
}
stage ('Publish to Debian Repository (Nightly)') {
when {
branch 'main'
}
agent { label 'debian-repo' }
steps {
script {
// Construir el patrón de versión esperado en el nombre del paquete
def versionPattern = "-${env.BUILD_NUMBER}~nightly"
publicarEnAptly('/var/tmp/opengnsys/debian-repo/ogclient', 'nightly', versionPattern)
}
}
}
}
post {
always {

View File

@ -1,7 +1,7 @@
[ogclient]
comment = OpenGnsys Client
browseable = no
writeable = yes
writeable = no
locking = no
path = /opt/opengnsys/ogclient
guest ok = no

Binary file not shown.

View File

@ -55,9 +55,6 @@ elif 6 == len (sys.argv):
args = parser.parse_args()
src = { 'container': args.src_container, 'file': args.src_file }
dst = { 'disk': args.dst_disk, 'par': args.dst_par, 'file': args.dst_file }
else:
ogHelp ('ogCopyFile', 'ogCopyFile [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target', ['ogCopyFile REPO newfile.txt 1 2 /tmp/newfile.txt'])
sys.exit (1)
ret = ogCopyFile (src, dst)
if ret is not None:

View File

@ -2,9 +2,6 @@
import os
import sys
import time
os.system ('pkill -f OGAgent')
time.sleep (3)
os.system ('poweroff')
sys.exit (0)

View File

@ -75,11 +75,8 @@ for item in tbprm:
elif 'tch' == k: tch = v
# Error si no se define el parámetro de disco (dis).
if dis is None:
coproc.kill()
sys.exit (ogGlobals.OG_ERR_FORMAT)
if tch is None:
tch = '0'
if dis is None: sys.exit (ogGlobals.OG_ERR_FORMAT)
if tch is None: tch = '0'
# Toma valores de distribución de particiones, separados por "%".
tbp = [] # Valores de configuración (parámetros para ogCreatePartitions)
@ -114,7 +111,6 @@ for item in tbprm:
if tam is None: missing_params.append ('tam')
if missing_params:
print (f'partition data ({item}) missing required parameters ({' '.join (missing_params)})')
coproc.kill()
sys.exit (1)
# Componer datos de particionado.
@ -154,7 +150,6 @@ if 'CACHE' in sparam:
rc = SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch)
if rc:
SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_CACHE, f'initCache failed')
coproc.kill()
sys.exit (1)
# Definir particionado.

View File

@ -66,7 +66,7 @@ repo = arg_repo
if not repo: repo = 'REPO'
if repo == ogGetIpAddress(): repo = 'CACHE'
# Si es una ip y es distinta a la del recurso samba cambiamos de REPO.
if 'REPO' == repo or ogCheckIpAddress (repo):
if 'REPO' == repo or StringLib.ogCheckIpAddress (repo):
# Si falla el cambio -> salimos con error repositorio no valido
if not ogChangeRepo (repo):
ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, repo)

View File

@ -2,9 +2,6 @@
import os
import sys
import time
os.system ('pkill -f OGAgent')
time.sleep (3)
os.system ('reboot')
sys.exit (0)

View File

@ -74,5 +74,4 @@ else:
# Borramos marcas de arranque de Windows
for f in glob.glob ('/mnt/*/ogboot.*') + glob.glob ('/mnt/*/*/ogboot.*'):
try: os.unlink (f)
except: pass
os.unlink (f)

View File

@ -179,7 +179,7 @@ def ogCreatePartitions (disk, parts):
p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache()
return not p.returncode
return True
#/**
@ -285,7 +285,7 @@ def ogCreateGptPartitions (disk, parts):
p = subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK], capture_output=True, text=True)
subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache()
return not p.returncode
return True
#/**

View File

@ -286,7 +286,11 @@ def ogGetFsSize (disk, par, unit='KB'):
elif unit.upper() == "TB":
factor = 1024 * 1024 * 1024
elif unit.upper() != "KB":
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f"{unit} != {{ KB, MB, GB, TB }}")
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_FORMAT,
f"{unit} != {{ KB, MB, GB, TB }}"
)
return
# Obtener el tamaño del sistema de archivo (si no está formateado; tamaño = 0).
@ -327,7 +331,11 @@ def ogGetFsType(disk, part):
try:
subprocess.run(["zfs", "mount", PART])
except FileNotFoundError:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTEXEC, 'zfs')
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_NOTEXEC,
'zfs'
)
return
out = subprocess.run(["mount"], capture_output=True, text=True).stdout.splitlines()
for line in out:
@ -336,7 +344,11 @@ def ogGetFsType(disk, part):
break
if not TYPE:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{disk} {part}')
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_NOTFOUND,
f'{disk} {part}'
)
return
# Componer valores correctos.
@ -580,7 +592,11 @@ def ogMountFs (disk, par):
try:
rc = subprocess.run(['mount', dev, mntdir, '-o', 'force,remove_hiberfile'], check=True).returncode
except subprocess.CalledProcessError:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f"{disk}, {par}")
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_PARTITION,
f"{disk}, {par}"
)
return
if 0 == rc:
@ -589,18 +605,26 @@ def ogMountFs (disk, par):
try:
subprocess.run (['ntfsfix', '-d', par], check=True)
except subprocess.CalledProcessError:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f"{disk, par}")
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_PARTITION,
f"{disk, par}"
)
#return
else:
try:
subprocess.run (['mount', par, mntdir, '-o', 'ro'], check=True)
except subprocess.CalledProcessError:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f"{disk, par}")
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_PARTITION,
f"{disk, par}"
)
#return
# Aviso de montaje de solo lectura.
if ogIsReadonly(disk, par):
SystemLib.ogEcho ([], "warning", f'ogMountFs: {ogGlobals.lang.MSG_MOUNTREADONLY}: "{disk}, {par}"')
SystemLib.ogEcho("warning", f'ogMountFs: {ogGlobals.lang.MSG_MOUNTREADONLY}: "{disk}, {par}"')
else:
# Montar sistema de archivos ZFS (un ZPOOL no comienza por "/").
subprocess.run(['zfs', 'mount', dev])
@ -692,8 +716,7 @@ def ogReduceFs (disk, par):
break
elif type == 'NTFS':
ogUnmount (disk, par)
ntfsresize_out = subprocess.run (['ntfsresize', '-fi', PART], capture_output=True, text=True).stdout
nr_lines = ntfsresize_out.splitlines()
nr_lines = subprocess.run (['ntfsresize', '-fi', PART], capture_output=True, text=True).stdout.splitlines()
maxsize = None
size = None
for l in nr_lines:
@ -703,10 +726,12 @@ def ogReduceFs (disk, par):
size = l.split()[4]
size = int ((int (size) * 1.1 / 1024 + 1) * 1024)
if not maxsize or not size:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk},{par} ({ntfsresize_out})')
if not maxsize and not size:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, f'{disk},{par}')
return None
import time
extrasize = 0
retval = 1
while retval != 0 and size+extrasize < maxsize:
@ -784,14 +809,18 @@ def ogUnmountFs(disk, par):
if MNTDIR:
# Error si la particion está bloqueada.
if ogIsLocked (disk, par):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_LOCKED, f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}")
SystemLib.ogRaiseError (
[],
ogGlobals.OG_ERR_LOCKED,
f"{ogGlobals.lang.MSG_PARTITION}, {disk} {par}"
)
return
# Desmontar y borrar punto de montaje.
try:
subprocess.run(["umount", PART], check=True)
except subprocess.CalledProcessError:
SystemLib.ogEcho ([], "warning", f'ogUnmountFs: {ogGlobals.lang.MSG_DONTUNMOUNT}: "{disk}, {par}"')
SystemLib.ogEcho("warning", f'ogUnmountFs: {ogGlobals.lang.MSG_DONTUNMOUNT}: "{disk}, {par}"')
try:
os.rmdir(MNTDIR)
except:

View File

@ -512,8 +512,6 @@ def ogRestoreImage (repo, imgpath, disk, par):
rc = None
try:
p = subprocess.run (program, shell=True, capture_output=True, text=True)
print (p.stdout)
print (p.stderr)
rc = p.returncode
if not rc:
SystemLib.ogRaiseError ([], ogGlobalsOG_ERR_IMAGE, f'{imgfile}, {disk}, {par}')

View File

@ -142,29 +142,7 @@ def ogGetHostname():
#@note Usa las variables utilizadas por el initrd "/etc/net-ethX.conf
#*/ ##
def ogGetIpAddress():
if "IPV4ADDR" in os.environ:
ip = os.environ["IPV4ADDR"]
if '/' in ip: ip = ip.split ('/')[0]
return ip
extra_args = []
if "DEVICE" in os.environ:
extra_args = [ "dev", os.environ["DEVICE"] ]
ipas = subprocess.run (['ip', '-json', 'address', 'show', 'up'] + extra_args, capture_output=True, text=True).stdout
ipasj = json.loads (ipas)
addresses = []
for e in ipasj:
if 'lo' == e['ifname']: continue
if 'addr_info' not in e: continue
addrs = e['addr_info']
for a in addrs:
if 'inet' != a['family']: continue
addresses.append ({ 'local': a['local'], 'prefixlen': a['prefixlen'] })
if 1 != len (addresses):
raise Exception ('more than one local IP address found')
return addresses[0]
return ogGlobals.ogGetIpAddress()
#/**

View File

@ -3,7 +3,6 @@ import datetime
from zoneinfo import ZoneInfo
import sys
import os
import json
import shutil
import inspect
import glob
@ -21,7 +20,6 @@ import StringLib
def _logtype2logfile (t):
if 'log' == t.lower(): return ogGlobals.OGLOGFILE
if 'jsonlog' == t.lower(): return ogGlobals.OGJSONLOGFILE
elif 'command' == t.lower(): return ogGlobals.OGLOGCOMMAND
elif 'session' == t.lower(): return ogGlobals.OGLOGSESSION
else: raise Exception (f'unknown log type ({t})')
@ -37,40 +35,24 @@ def ogEcho (logtypes, loglevel, msg):
logfiles = ['/dev/stdout']
if type (logtypes) is list:
for l in logtypes:
if 'log' == l:
logfiles.append (_logtype2logfile ('log'))
logfiles.append (_logtype2logfile ('jsonlog'))
else:
logfiles.append (_logtype2logfile (l))
logfiles.append (_logtype2logfile (l))
else: ## string
if 'log' == logtypes:
logfiles.append (_logtype2logfile ('log'))
logfiles.append (_logtype2logfile ('jsonlog'))
else:
logfiles.append (_logtype2logfile (logtypes))
logfiles.append (_logtype2logfile (logtypes))
if loglevel is None or 'help' == loglevel:
if ogGlobals.DEBUG.lower() != "no":
logfiles.append (ogGlobals.OGLOGFILE)
logfiles.append (ogGlobals.OGJSONLOGFILE)
for f in logfiles:
with open (f, 'a') as fd:
if ogGlobals.OGJSONLOGFILE == f:
fd.write (json.dumps ({'message':msg}) + '\n')
else:
fd.write (msg + '\n')
fd.write (msg + '\n')
return
if 'info' == loglevel or 'warning' == loglevel or 'error' == loglevel:
DATETIME = datetime.datetime.now (ZoneInfo (ogGlobals.TZ)).strftime ('%F %T %Z')
DATETIME_json = datetime.datetime.now (ZoneInfo (ogGlobals.TZ)).strftime ('%Y-%m-%d %H:%M:%S')
DATETIME = datetime.datetime.now(ZoneInfo(ogGlobals.TZ)).strftime("%F %T %Z")
for f in logfiles:
with open (f, 'a') as fd:
if ogGlobals.OGJSONLOGFILE == f:
fd.write (json.dumps ({'timestamp':DATETIME_json, 'severity':loglevel, 'message':msg}) + '\n')
else:
fd.write (f"OpenGnsys {loglevel} {DATETIME} {msg}\n")
fd.write (f"OpenGnsys {loglevel} {DATETIME} {msg}\n")
else:
raise Exception (f'unknown loglevel ({loglevel})')
@ -93,18 +75,10 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
if type (logtypes) is list:
for l in logtypes:
logtypes = list (map (lambda x: x.lower(), logtypes))
if 'log' == l:
logfiles.append (_logtype2logfile ('log'))
logfiles.append (_logtype2logfile ('jsonlog'))
else:
logfiles.append (_logtype2logfile (l))
logfiles.append (_logtype2logfile (l))
else: ## string
logtypes = logtypes.lower()
if 'log' == logtypes:
logfiles.append (_logtype2logfile ('log'))
logfiles.append (_logtype2logfile ('jsonlog'))
else:
logfiles.append (_logtype2logfile (logtypes))
logfiles.append (_logtype2logfile (logtypes))
if not fun:
ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, 'no function provided')
@ -129,6 +103,7 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
# ## redirect stdout only
# eval $COMMAND | tee -a $FILES
import time
sout = serr = ''
if 'command' in logtypes:
os.unlink (ogGlobals.OGLOGCOMMAND)
@ -146,19 +121,14 @@ def ogExecAndLog (logtypes, fun, *args, **kwargs):
if sout or serr or ('True' != rc_str and 'False' != rc_str and 'None' != rc_str):
for f in logfiles:
with open (f, 'a') as fd:
if ogGlobals.OGJSONLOGFILE == f:
if sout: fd.write (json.dumps ({'message':sout}) + '\n')
if serr: fd.write (json.dumps ({'message':serr}) + '\n')
if rc_str: fd.write (json.dumps ({'message':rc_str}) + '\n')
else:
if sout: fd.write (f'{sout}\n')
if serr: fd.write (f'{serr}\n')
if rc_str: fd.write (f'{rc_str}\n')
#fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n")
#if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n")
#if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n")
if sout: fd.write (f'{sout}\n')
if serr: fd.write (f'{serr}\n')
if rc_str: fd.write (f'{rc_str}\n')
#fd.write (f"ogExecAndLog: {fun.__name__} rc:\n{rc_str}\n")
#if sout: fd.write (f"ogExecAndLog: {fun.__name__} stdout:\n{sout}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stdout: (none)\n")
#if serr: fd.write (f"ogExecAndLog: {fun.__name__} stderr:\n{serr}\n")
#else: fd.write (f"ogExecAndLog: {fun.__name__} stderr: (none)\n")
return rc

View File

@ -6,6 +6,33 @@ import os.path
import locale
import importlib.util
## required for defining OGLOGFILE
def ogGetIpAddress():
if "IPV4ADDR" in os.environ:
ip = os.environ["IPV4ADDR"]
if '/' in ip: ip = ip.split ('/')[0]
return ip
extra_args = []
if "DEVICE" in os.environ:
extra_args = [ "dev", os.environ["DEVICE"] ]
ipas = subprocess.run (['ip', '-json', 'address', 'show', 'up'] + extra_args, capture_output=True, text=True).stdout
ipasj = json.loads (ipas)
addresses = []
for e in ipasj:
if 'lo' == e['ifname']: continue
if 'addr_info' not in e: continue
addrs = e['addr_info']
for a in addrs:
if 'inet' != a['family']: continue
addresses.append ({ 'local': a['local'], 'prefixlen': a['prefixlen'] })
if 1 != len (addresses):
raise Exception ('more than one local IP address found')
return addresses[0]
ip = ogGetIpAddress()
def load_lang (name):
global lang
if name in sys.modules:
@ -61,8 +88,8 @@ OGPYFUNCS = os.path.join (OPENGNSYS, 'functions')
OGSCRIPTS = os.path.join (OPENGNSYS, 'scripts')
OGIMG = os.path.join (OPENGNSYS, 'images')
OGCAC = os.path.join (OPENGNSYS, 'cache')
OGLOGFILE = '/var/log/clone-engine.log'
OGJSONLOGFILE = '/var/log/clone-engine.json.log'
OGLOG = os.path.join (OPENGNSYS, 'log')
OGLOGFILE = f'{OGLOG}/{ip}.log'
DEBUG = 'yes'
_path = os.environ['PATH'] + ':/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:/opt/oglive/rootfs/opt/drbl/sbin'
os.environ['PATH'] = ':'.join ([OGSCRIPTS, _path, OGAPI, OGBIN])

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -145,10 +145,6 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''):
SystemLib.ogEcho (['log', 'session'], None, f'[55] {ogGlobals.lang.MSG_HELP_ogRestoreImage}: restoreImage {params}')
retval = subprocess.run (['restoreImage.py'] + params).returncode
## turn shell's success into python success (without ending up with True or False)
if retval: retval = 0
else: retval = 1
# Mostrar resultados.
resumerestoreimage = subprocess.run (['grep', '--max-count', '1', 'Total Time:', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout
SystemLib.ogEcho (['log', 'session'], None, f' [ ] {resumerestoreimage} ')

View File

@ -21,7 +21,7 @@ if len (sys.argv) > 1:
#SERVERLOGDIR = unused
# Fichero de listado: hard-IP
HARDFILE = f'/tmp/hard-{ogGetIpAddress()}'
HARDFILE = f'{ogGlobals.OGLOG}/hard-{ogGetIpAddress()}'
out = ogListHardwareInfo()
with open (HARDFILE, 'w') as fd:
fd.write (out)

View File

@ -18,7 +18,7 @@ prog = os.path.basename (sys.argv[0])
def main (disk, par, reduced):
ip = NetLib.ogGetIpAddress()
softfile = f'/tmp/soft-{ip}-{disk}-{par}'
softfile = f'{ogGlobals.OGLOG}/soft-{ip}-{disk}-{par}'
software_list = InventoryLib.ogListSoftware (disk, par)
if reduced:

View File

@ -114,5 +114,5 @@ t = time.time() - t0
SystemLib.ogEcho (['log', 'session'], None, f'[100] Duracion de la operacion {int (t/60)}m {int (t%60)}s')
# Código de salida del comando prinicpal de restauración.
sys.exit (not retval) ## negated for the shell
sys.exit (retval)