refs #1144 rebuild ogChangeRepo
parent
c03455a32f
commit
ea5114a897
|
@ -16,63 +16,58 @@ import SystemLib
|
||||||
#@param 2 Abreviatura Unidad Organizativa
|
#@param 2 Abreviatura Unidad Organizativa
|
||||||
#@return Cambio recurso remoto en OGIMG.
|
#@return Cambio recurso remoto en OGIMG.
|
||||||
#*/
|
#*/
|
||||||
def ogChangeRepo():
|
def ogChangeRepo(ip_repo, og_unit=None):
|
||||||
SRCIMG = ""
|
ogprotocol = "cifs"
|
||||||
NEWREPO = ""
|
|
||||||
REPO = ""
|
|
||||||
OGUNIT = ""
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
try:
|
||||||
print("Usage: ogChangeRepo IPREPO [ OgUnit ]")
|
rw_option = ",rw" if "rw" in subprocess.getoutput("mount | grep 'ogimages'") else ",ro"
|
||||||
print("Example: ogChangeRepo 10.1.120.3")
|
|
||||||
print("Example: ogChangeRepo 10.1.120.3 cdc")
|
|
||||||
return
|
|
||||||
|
|
||||||
if sys.argv[1] == "help":
|
current_repo = ogGetRepoIp()
|
||||||
print("Usage: ogChangeRepo IPREPO [ OgUnit ]")
|
current_og_unit = subprocess.getoutput(
|
||||||
print("Example: ogChangeRepo 10.1.120.3")
|
"df | awk -F ' ' '/ogimages/ {sub(\"//.*/ogimages\",\"\",$1); sub(\"/\",\"\",$1); print $1}'"
|
||||||
print("Example: ogChangeRepo 10.1.120.3 cdc")
|
).strip()
|
||||||
return
|
|
||||||
|
|
||||||
if len(sys.argv) >= 2:
|
new_repo = current_repo if ip_repo.upper() == "REPO" else ip_repo
|
||||||
NEWREPO = sys.argv[1]
|
|
||||||
|
|
||||||
# Opciones de montaje: lectura o escritura
|
if new_repo == current_repo and og_unit == current_og_unit:
|
||||||
subprocess.run(["mount", "|", "grep", "ogimages.*rw,"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
return 0
|
||||||
RW = ",rw" if subprocess.returncode == 0 else ",ro"
|
|
||||||
|
|
||||||
# Si REPO tomamos el repositorio y la unidad organizativa actual
|
subprocess.run(["umount", ogGlobals.OGIMG], check=True)
|
||||||
REPO = ogRepoIp()
|
|
||||||
OGUNIT = subprocess.run(["df", "|", "awk", "-F", " ", "'/ogimages/ {sub(\"//.*/ogimages\",\"\",$1); sub(\"/\",\"\",$1); print $1}'"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().strip()
|
|
||||||
|
|
||||||
# Parametros de entrada. Si $1 = "REPO" dejo el repositorio actual
|
src_img = "ogimages" if not og_unit else f"ogimages/{og_unit}"
|
||||||
if sys.argv[1].upper() == "REPO":
|
|
||||||
NEWREPO = REPO
|
result = subprocess.run(
|
||||||
|
["ogConnect", new_repo, ogprotocol, src_img, ogGlobals.OGIMG, rw_option],
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
subprocess.run(
|
||||||
|
["ogConnect", current_repo, ogprotocol, src_img, ogGlobals.OGIMG, rw_option],
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
SystemLib.ogRaiseError(
|
||||||
|
"session",
|
||||||
|
ogGlobals.OG_ERR_REPO,
|
||||||
|
f"Error connecting to the new repository: {new_repo}",
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
SystemLib.ogEcho(
|
||||||
|
"session",
|
||||||
|
"log",
|
||||||
|
f"Repository successfully changed to {new_repo} {og_unit or ''}".strip(),
|
||||||
|
)
|
||||||
|
|
||||||
# Si $1 y $2 son el repositorio y la OU actual me salgo
|
|
||||||
if NEWREPO == REPO and sys.argv[2] == OGUNIT:
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
subprocess.run(["source", "/scripts/functions"], shell=True)
|
except Exception as e:
|
||||||
subprocess.run(["source", "/scripts/ogfunctions"], shell=True)
|
SystemLib.ogRaiseError(
|
||||||
subprocess.run(["umount", OGIMG])
|
"session",
|
||||||
|
ogGlobals.OG_ERR_FORMAT,
|
||||||
if sys.argv[2] == "":
|
f"Error executing ogChangeRepo: {e}",
|
||||||
SRCIMG = "ogimages"
|
)
|
||||||
else:
|
return 1
|
||||||
SRCIMG = "ogimages/" + sys.argv[2]
|
|
||||||
|
|
||||||
subprocess.run(["eval", "$(grep \"OPTIONS=\" /scripts/ogfunctions)"])
|
|
||||||
|
|
||||||
SystemLib.ogEcho("session", "log", MSG_HELP_ogChangeRepo + " " + NEWREPO + " " + sys.argv[2].rstrip())
|
|
||||||
ogConnect(NEWREPO, ogprotocol, SRCIMG, OGIMG, RW)
|
|
||||||
|
|
||||||
# Si da error volvemos a montar el inicial
|
|
||||||
if subprocess.returncode != 0:
|
|
||||||
ogConnect(REPO, ogprotocol, SRCIMG, OGIMG, RW)
|
|
||||||
SystemLib.ogRaiseError("session", OG_ERR_REPO, NEWREPO)
|
|
||||||
return subprocess.returncode
|
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
# ogGetGroupDir [ str_repo ]
|
# ogGetGroupDir [ str_repo ]
|
||||||
|
|
Loading…
Reference in New Issue