Compare commits
24 Commits
jenkins_up
...
main
Author | SHA1 | Date |
---|---|---|
|
c23b4ddddb | |
|
2507c035ae | |
|
d0149f40f8 | |
|
fba880c477 | |
|
29f653a527 | |
|
b9d3f5c4c7 | |
|
5406e67b95 | |
|
15769dde0f | |
|
f8cb868a2a | |
|
4316217faa | |
|
b77aa1fc4d | |
|
d7869c35b7 | |
|
8af857c9ef | |
|
48d10b7cd9 | |
|
90fd5b274f | |
|
311ecc7f3a | |
|
6ba0788bc0 | |
|
826625f66a | |
|
d585e992e6 | |
|
bf0f138bcd | |
|
7906c3e6aa | |
|
0762178aa4 | |
|
5c57137c4d | |
|
ee91db10df |
129
CHANGELOG.md
129
CHANGELOG.md
|
@ -1,162 +1,209 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [0.8.1] - 2025-04-01
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Add sudo to cancel transfers endpoints (#1796)
|
||||||
|
|
||||||
|
## [0.8.0] - 2025-03-25
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Rename Image functionality (#1733)
|
||||||
|
|
||||||
|
## [0.7.3] - 2025-03-19
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Fix permissions problem and authorized_keys file in debian package
|
||||||
|
|
||||||
|
## [0.7.2] - 2025-03-19
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Update CHANGELOG.md
|
||||||
|
|
||||||
|
## [0.7.1] - 2025-03-19
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Updated Jenkinsfile for publishing packages (#1313)
|
||||||
|
|
||||||
## [0.7.0] - 2025-03-18
|
## [0.7.0] - 2025-03-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #1689 - Add Convert IMG to VM' (#28) from add_python_scripts into main
|
- Image to Virtual Disk conversion (#1689)
|
||||||
|
|
||||||
## [0.6.4] - 2025-03-13
|
## [0.6.4] - 2025-03-13
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #1701 - 'convertVMtoIMG.py' improvement' (#27) from add_python_scripts into main
|
- Virtual Disk to Image conversion improvement (#1701)
|
||||||
|
|
||||||
## [0.6.3] - 2025-03-12
|
## [0.6.3] - 2025-03-12
|
||||||
|
|
||||||
### Added
|
### Fixed
|
||||||
|
|
||||||
- Merge pull request 'refs #1701 - Fix script convertVMtoIMG.py' (#26) from add_python_scripts into main
|
- Virtual Disk to Image conversion fix (#1701)
|
||||||
|
|
||||||
## [0.6.2] - 2025-03-10
|
## [0.6.2] - 2025-03-10
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #1681 - Add ogGit install status' (#25) from add_python_scripts into main
|
- ogGit Install Status info (#1681)
|
||||||
|
|
||||||
## [0.6.1] - 2025-03-05
|
## [0.6.1] - 2025-03-05
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #1642 - Modify Cancel Transfers scripts' (#24) from add_python_scripts into main
|
- Cancel Transfers scripts improvement (#1642)
|
||||||
|
|
||||||
## [0.6.0] - 2025-03-03
|
## [0.6.0] - 2025-03-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #1525 - Add Convert VM to IMG' (#23) from add_python_scripts into main
|
- Virtual Disk to Image conversion (#1525)
|
||||||
|
|
||||||
## [0.5.23] - 2025-02-20
|
## [0.5.23] - 2025-02-20
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #1530 - Add 'backupImage.py' and related endpoint' (#22) from add_python_scripts into main
|
- Backup Image improvement (#1530)
|
||||||
|
|
||||||
## [0.5.22] - 2025-02-20
|
## [0.5.22] - 2025-02-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #1530 - Add 'backupImage.py' and related endpoint' (#22) from add_python_scripts into main
|
- Backup Image (#1530)
|
||||||
|
|
||||||
## [0.5.20] - 2025-02-11
|
## [0.5.20] - 2025-02-11
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #1482 - Modify Paramiko SSH Client parameters' (#21) from add_python_scripts into main
|
- Paramiko SSH Client parameters improvement (#1482)
|
||||||
|
|
||||||
## [0.5.19] - 2025-02-06
|
## [0.5.19] - 2025-02-06
|
||||||
|
|
||||||
### Added
|
### Fixed
|
||||||
|
|
||||||
- Merge pull request 'add_python_scripts' (#20) from add_python_scripts into main
|
- Script corrections (#1437)
|
||||||
|
|
||||||
## [0.5.18] - 2025-02-03
|
## [0.5.18] - 2025-02-03
|
||||||
|
|
||||||
### Added
|
### Fixed
|
||||||
|
|
||||||
- Merge pull request 'refs #1437 - Scripts corrections' (#19) from add_python_scripts into main
|
- Script corrections (#1437)
|
||||||
|
|
||||||
## [0.5.17] - 2025-02-03
|
## [0.5.17] - 2025-02-03
|
||||||
|
|
||||||
### Added
|
### Removed
|
||||||
|
|
||||||
- Merge pull request 'refs #1437 - Remove unnecessary sudo calls' (#18) from add_python_scripts into main
|
- Remove unnecessary sudo calls (#1437)
|
||||||
|
|
||||||
## [0.5.16] - 2025-01-31
|
## [0.5.16] - 2025-01-31
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #1378 - Add API tests and modify API' (#17) from add_python_scripts into main
|
- API tests (#1378)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- API improvement (#1378)
|
||||||
|
|
||||||
## [0.5.15] - 2025-01-28
|
## [0.5.15] - 2025-01-28
|
||||||
|
|
||||||
### Added
|
### Fixed
|
||||||
|
|
||||||
- Merge pull request 'refs #1378 - Fix API tests errors' (#16) from add_python_scripts into main
|
- API tests errors fixes (#1378)
|
||||||
|
|
||||||
## [0.5.14] - 2025-01-24
|
## [0.5.14] - 2025-01-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #1346 - Add API tests' (#15) from add_python_scripts into main
|
- API tests (#1346)
|
||||||
|
|
||||||
## [0.5.13] - 2025-01-10
|
## [0.5.13] - 2025-01-10
|
||||||
|
|
||||||
### Added
|
### Removed
|
||||||
|
|
||||||
- Merge pull request 'refs #1335 - Supress recursive image search' (#14) from add_python_scripts into main
|
- Remove recursive image search (#1335)
|
||||||
|
|
||||||
## [0.5.12] - 2024-12-17
|
## [0.5.12] - 2024-12-17
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #1294 - Modify logs format' (#13) from add_python_scripts into main
|
- Modify logs format (#1294)
|
||||||
|
|
||||||
## [0.5.11] - 2024-12-12
|
## [0.5.11] - 2024-12-12
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #1242 - API logs improvement' (#12) from add_python_scripts into main
|
- API logs improvement (#1242)
|
||||||
|
|
||||||
## [0.5.10] - 2024-12-02
|
## [0.5.10] - 2024-12-02
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #631 - Modify logs in API and some scripts' (#11) from add_python_scripts into main
|
- API and Script logs improvement (#631)
|
||||||
|
|
||||||
## [0.5.9] - 2024-11-29
|
## [0.5.9] - 2024-11-29
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #631 - Add journalctl logs to scripts' (#10) from add_python_scripts into main
|
- Script journalctl logs (#631)
|
||||||
|
|
||||||
## [0.5.8] - 2024-11-28
|
## [0.5.8] - 2024-11-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Merge pull request 'refs #631 - Add journalctl logs to API' (#9) from add_python_scripts into main
|
- API journalctl logs (#631)
|
||||||
|
|
||||||
## [0.5.7] - 2024-11-26
|
## [0.5.7] - 2024-11-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 'python3-request' packet
|
||||||
|
|
||||||
## [0.5.6] - 2024-11-22
|
## [0.5.6] - 2024-11-22
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #631 - More API improvements' (#8) from add_python_scripts into main
|
- API improvements (#631)
|
||||||
|
|
||||||
## [0.5.5] - 2024-11-21
|
## [0.5.5] - 2024-11-21
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'refs #631 - API improvement' (#7) from add_python_scripts into main
|
- API improvements (#631)
|
||||||
|
|
||||||
## [0.5.4] - 2024-11-20
|
## [0.5.4] - 2024-11-20
|
||||||
|
|
||||||
### Added
|
### Changed
|
||||||
|
|
||||||
- Merge pull request 'add_python_scripts' (#6) from add_python_scripts into main
|
- API and Script improvements (#631)
|
||||||
|
|
||||||
## [0.5.3] - 2024-11-18
|
## [0.5.3] - 2024-11-18
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Update Documentation (#631)
|
||||||
|
|
||||||
## [0.5.2] - 2024-11-18
|
## [0.5.2] - 2024-11-18
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- API improvements (#631)
|
||||||
|
|
||||||
## [0.5.1] - 2024-11-15
|
## [0.5.1] - 2024-11-15
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- API improvements (#610)
|
||||||
|
|
||||||
## [0.5.0] - 2024-11-15
|
## [0.5.0] - 2024-11-15
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Update Documentation (#1084)
|
||||||
|
|
|
@ -49,15 +49,51 @@ 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') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
dir("${env.BUILD_DIR}") {
|
script {
|
||||||
sh '''
|
construirPaquete(env.BUILD_DIR, "../artifacts", "172.17.8.68", "/var/tmp/opengnsys/debian-repo/ogrepository")
|
||||||
dpkg-buildpackage -us -uc
|
}
|
||||||
mkdir -p ../artifacts && mv ../*.deb ../*.changes ../*.buildinfo ../artifacts/
|
}
|
||||||
ssh aptly@172.17.8.68 "rm -rf /var/tmp/opengnsys/debian-repo && mkdir -p /var/tmp/opengnsys/debian-repo"
|
}
|
||||||
scp -r ../artifacts/* aptly@172.17.8.68:/var/tmp/opengnsys/debian-repo/
|
stage ('Publish to Debian Repository') {
|
||||||
'''
|
when {
|
||||||
|
expression {
|
||||||
|
return env.TAG_NAME != null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
agent { label 'debian-repo' }
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
// Construir el patrón de versión esperado en el nombre del paquete
|
||||||
|
def versionPattern = "${env.TAG_NAME}-${env.BUILD_NUMBER}"
|
||||||
|
publicarEnAptly('/var/tmp/opengnsys/debian-repo/ogrepository', 'opengnsys-devel', versionPattern)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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/ogrepository', 'nightly', versionPattern)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
29
README.md
29
README.md
|
@ -74,8 +74,9 @@ El presente documento detalla los endpoints de la API, con sus respectivos pará
|
||||||
18. [Hacer Backup de una Imagen](#hacer-backup-de-una-imagen) - `PUT /ogrepository/v1/repo/images`
|
18. [Hacer Backup de una Imagen](#hacer-backup-de-una-imagen) - `PUT /ogrepository/v1/repo/images`
|
||||||
19. [Convertir Imagen Virtual a Imagen OpenGnsys](#convertir-imagen-virtual-a-imagen-opengnsys) - `POST /ogrepository/v1/images/virtual`
|
19. [Convertir Imagen Virtual a Imagen OpenGnsys](#convertir-imagen-virtual-a-imagen-opengnsys) - `POST /ogrepository/v1/images/virtual`
|
||||||
20. [Convertir Imagen OpenGnsys a Imagen Virtual](#convertir-imagen-opengnsys-a-imagen-virtual) - `PUT /ogrepository/v1/images/virtual`
|
20. [Convertir Imagen OpenGnsys a Imagen Virtual](#convertir-imagen-opengnsys-a-imagen-virtual) - `PUT /ogrepository/v1/images/virtual`
|
||||||
21. [Crear archivos auxiliares](#crear-archivos-auxiliares) - `POST /ogrepository/v1/images/torrentsum`
|
21. [Renombrar una Imagen](#renombrar-una-imagen) - `POST /ogrepository/v1/images/rename`
|
||||||
22. [Enviar paquete Wake On Lan](#enviar-paquete-wake-on-lan) - `POST /ogrepository/v1/wol`
|
22. [Crear archivos auxiliares](#crear-archivos-auxiliares) - `POST /ogrepository/v1/images/torrentsum`
|
||||||
|
23. [Enviar paquete Wake On Lan](#enviar-paquete-wake-on-lan) - `POST /ogrepository/v1/wol`
|
||||||
|
|
||||||
---
|
---
|
||||||
### Obtener Información de Estado de ogRepository
|
### Obtener Información de Estado de ogRepository
|
||||||
|
@ -677,6 +678,30 @@ curl -X PUT -H "Authorization: $API_KEY" -H "Content-Type: application/json" -d
|
||||||
- **Código 400 Bad Request:** No se ha encontrado la imagen especificada.
|
- **Código 400 Bad Request:** No se ha encontrado la imagen especificada.
|
||||||
- **Código 200 OK:** La imagen se está convirtiendo a virtual.
|
- **Código 200 OK:** La imagen se está convirtiendo a virtual.
|
||||||
|
|
||||||
|
---
|
||||||
|
### Renombrar una Imagen
|
||||||
|
|
||||||
|
Se renombrará la imagen especificada como primer parámetro (y todos sus archivos asociados), asignando el nombre especificado como segundo parámetro.
|
||||||
|
Se puede hacer con el script "**renameImage.py**", que debe ser llamado por el endpoint.
|
||||||
|
**NOTA**: El script requiere que se le pase el nombre de la imagen (sin extensión) como primer parámetro, y el nuevo nombre a asignar como segundo parámetro. El primer parámetro se obtiene en la API, a partir del ID de la imagen (que corresponde al contenido del archivo "full.sum"), pero el nuevo nombre a asignar debe enviarse en el JSON.
|
||||||
|
|
||||||
|
**URL:** `/ogrepository/v1/images/rename`
|
||||||
|
**Método HTTP:** POST
|
||||||
|
|
||||||
|
**Cuerpo de la Solicitud (JSON):**
|
||||||
|
- **ID_img**: Identificador de la imagen (correspondiente al contenido del archivo "full.sum" asociado).
|
||||||
|
- **image_new_name**: Nuevo nombre a asignar a la imagen.
|
||||||
|
|
||||||
|
**Ejemplo de Solicitud:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST -H "Authorization: $API_KEY" -H "Content-Type: application/json" -d '{"ID_img":"22735b9070e4a8043371b8c6ae52b90d", "image_new_name":"Ubuntu_BKP"}' http://example.com/ogrepository/v1/images/rename
|
||||||
|
```
|
||||||
|
**Respuestas:**
|
||||||
|
- **Código 500 Internal Server Error:** Ocurrió un error al renombrar la imagen.
|
||||||
|
- **Código 400 Bad Request:** No se ha encontrado la imagen especificada.
|
||||||
|
- **Código 200 OK:** La imagen se ha renombrado exitosamente.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Crear archivos auxiliares
|
### Crear archivos auxiliares
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,9 @@ El presente documento detalla los endpoints de la API, con sus respectivos pará
|
||||||
18. [Hacer Backup de una Imagen](#hacer-backup-de-una-imagen) - `PUT /ogrepository/v1/repo/images`
|
18. [Hacer Backup de una Imagen](#hacer-backup-de-una-imagen) - `PUT /ogrepository/v1/repo/images`
|
||||||
19. [Convertir Imagen Virtual a Imagen OpenGnsys](#convertir-imagen-virtual-a-imagen-opengnsys) - `POST /ogrepository/v1/images/virtual`
|
19. [Convertir Imagen Virtual a Imagen OpenGnsys](#convertir-imagen-virtual-a-imagen-opengnsys) - `POST /ogrepository/v1/images/virtual`
|
||||||
20. [Convertir Imagen OpenGnsys a Imagen Virtual](#convertir-imagen-opengnsys-a-imagen-virtual) - `PUT /ogrepository/v1/images/virtual`
|
20. [Convertir Imagen OpenGnsys a Imagen Virtual](#convertir-imagen-opengnsys-a-imagen-virtual) - `PUT /ogrepository/v1/images/virtual`
|
||||||
21. [Crear archivos auxiliares](#crear-archivos-auxiliares) - `POST /ogrepository/v1/images/torrentsum`
|
21. [Renombrar una Imagen](#renombrar-una-imagen) - `POST /ogrepository/v1/images/rename`
|
||||||
22. [Enviar paquete Wake On Lan](#enviar-paquete-wake-on-lan) - `POST /ogrepository/v1/wol`
|
22. [Crear archivos auxiliares](#crear-archivos-auxiliares) - `POST /ogrepository/v1/images/torrentsum`
|
||||||
|
23. [Enviar paquete Wake On Lan](#enviar-paquete-wake-on-lan) - `POST /ogrepository/v1/wol`
|
||||||
|
|
||||||
---
|
---
|
||||||
### Obtener Información de Estado de ogRepository
|
### Obtener Información de Estado de ogRepository
|
||||||
|
@ -631,6 +632,30 @@ curl -X PUT -H "Authorization: $API_KEY" -H "Content-Type: application/json" -d
|
||||||
- **Código 400 Bad Request:** No se ha encontrado la imagen especificada.
|
- **Código 400 Bad Request:** No se ha encontrado la imagen especificada.
|
||||||
- **Código 200 OK:** La imagen se está convirtiendo a virtual.
|
- **Código 200 OK:** La imagen se está convirtiendo a virtual.
|
||||||
|
|
||||||
|
---
|
||||||
|
### Renombrar una Imagen
|
||||||
|
|
||||||
|
Se renombrará la imagen especificada como primer parámetro (y todos sus archivos asociados), asignando el nombre especificado como segundo parámetro.
|
||||||
|
Se puede hacer con el script "**renameImage.py**", que debe ser llamado por el endpoint.
|
||||||
|
**NOTA**: El script requiere que se le pase el nombre de la imagen (sin extensión) como primer parámetro, y el nuevo nombre a asignar como segundo parámetro. El primer parámetro se obtiene en la API, a partir del ID de la imagen (que corresponde al contenido del archivo "full.sum"), pero el nuevo nombre a asignar debe enviarse en el JSON.
|
||||||
|
|
||||||
|
**URL:** `/ogrepository/v1/images/rename`
|
||||||
|
**Método HTTP:** POST
|
||||||
|
|
||||||
|
**Cuerpo de la Solicitud (JSON):**
|
||||||
|
- **ID_img**: Identificador de la imagen (correspondiente al contenido del archivo "full.sum" asociado).
|
||||||
|
- **image_new_name**: Nuevo nombre a asignar a la imagen.
|
||||||
|
|
||||||
|
**Ejemplo de Solicitud:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST -H "Authorization: $API_KEY" -H "Content-Type: application/json" -d '{"ID_img":"22735b9070e4a8043371b8c6ae52b90d", "image_new_name":"Ubuntu_BKP"}' http://example.com/ogrepository/v1/images/rename
|
||||||
|
```
|
||||||
|
**Respuestas:**
|
||||||
|
- **Código 500 Internal Server Error:** Ocurrió un error al renombrar la imagen.
|
||||||
|
- **Código 400 Bad Request:** No se ha encontrado la imagen especificada.
|
||||||
|
- **Código 200 OK:** La imagen se ha renombrado exitosamente.
|
||||||
|
|
||||||
---
|
---
|
||||||
### Crear archivos auxiliares
|
### Crear archivos auxiliares
|
||||||
|
|
||||||
|
|
|
@ -1724,7 +1724,7 @@ def stop_udpcast(imageId):
|
||||||
|
|
||||||
# Evaluamos los parámetros obtenidos, para construir la llamada al script, o para devolver un error si no se ha encontrado la imagen:
|
# Evaluamos los parámetros obtenidos, para construir la llamada al script, o para devolver un error si no se ha encontrado la imagen:
|
||||||
if param_dict:
|
if param_dict:
|
||||||
cmd = ['python3', f"{script_path}/stopUDPcast.py", f"{param_dict['name']}.{param_dict['extension']}"]
|
cmd = ['sudo', 'python3', f"{script_path}/stopUDPcast.py", f"{param_dict['name']}.{param_dict['extension']}"] # Se debe ejecutar con sudo, o dará error
|
||||||
else:
|
else:
|
||||||
journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint stop_udpcast', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint stop_udpcast', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
@ -1800,7 +1800,7 @@ def stop_uftp(imageId):
|
||||||
|
|
||||||
# Evaluamos los parámetros obtenidos, para construir la llamada al script, o para devolver un error si no se ha encontrado la imagen:
|
# Evaluamos los parámetros obtenidos, para construir la llamada al script, o para devolver un error si no se ha encontrado la imagen:
|
||||||
if param_dict:
|
if param_dict:
|
||||||
cmd = ['python3', f"{script_path}/stopUFTP.py", f"{param_dict['name']}.{param_dict['extension']}"]
|
cmd = ['sudo', 'python3', f"{script_path}/stopUFTP.py", f"{param_dict['name']}.{param_dict['extension']}"] # Se debe ejecutar con sudo, o dará error
|
||||||
else:
|
else:
|
||||||
journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint stop_uftp', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint stop_uftp', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
@ -2019,7 +2019,7 @@ def convert_image_to_virtual():
|
||||||
"""
|
"""
|
||||||
journal.send("Running endpoint 'Convertir imagen OpenGnsys a imagen virtual'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
journal.send("Running endpoint 'Convertir imagen OpenGnsys a imagen virtual'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
|
||||||
# Almacenamos los parámetros enviados en el JSON,:
|
# Almacenamos los parámetros enviados en el JSON:
|
||||||
json_data = json.loads(request.data)
|
json_data = json.loads(request.data)
|
||||||
image_id = json_data.get("ID_img")
|
image_id = json_data.get("ID_img")
|
||||||
vm_extension = json_data.get("vm_extension").lower().lstrip('.')
|
vm_extension = json_data.get("vm_extension").lower().lstrip('.')
|
||||||
|
@ -2112,6 +2112,78 @@ def convert_image_to_virtual():
|
||||||
}), 500
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# 22 - Endpoint "Renombrar una Imagen" (SINCRONO):
|
||||||
|
@app.route("/ogrepository/v1/images/rename", methods=['PUT'])
|
||||||
|
def rename_image():
|
||||||
|
""" Este endpoint renombra la imagen especificada como primer parámetro (y todos sus archivos asociados), asignando el nombre especificado como segundo parámetro.
|
||||||
|
Para ello, ejecuta el script "renameImage.py", con el nombre original de la imagen como primer parámetro, y el nuevo nombre a asignar como segundo parámetro.
|
||||||
|
"""
|
||||||
|
journal.send("Running endpoint 'Renombrar una Imagen'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
|
||||||
|
# Almacenamos los parámetros enviados en el JSON:
|
||||||
|
json_data = json.loads(request.data)
|
||||||
|
image_id = json_data.get("ID_img")
|
||||||
|
image_new_name = json_data.get("image_new_name").rstrip('.img')
|
||||||
|
|
||||||
|
# Obtenemos el nombre y la extensión de la imagen:
|
||||||
|
param_dict = get_image_params(image_id, "repo")
|
||||||
|
|
||||||
|
# Evaluamos los parámetros obtenidos, para construir la llamada al script, o para devolver un error si no se ha encontrado la imagen:
|
||||||
|
if param_dict:
|
||||||
|
image_original_name = f"{param_dict['name']}"
|
||||||
|
cmd = ['python3', f"{script_path}/renameImage.py", image_original_name, image_new_name]
|
||||||
|
else:
|
||||||
|
journal.send("Image not found", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint rename_image', 'desc':'Warning: Image not found'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
return jsonify({
|
||||||
|
"success": False,
|
||||||
|
"error": "Image not found"
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
# Comprobamos si ya existe una imagen con el mismo nombre que se quiere asignar, llamando a la función "check_file_exists":
|
||||||
|
image_newname_exists = check_file_exists(f"{repo_path}{image_new_name}.img")
|
||||||
|
|
||||||
|
# Si existe una imagen con el mismo nombre que se quiere asignar, devolvemos un error:
|
||||||
|
if image_newname_exists == True:
|
||||||
|
journal.send("There is an image with the name to assign", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
journal.send("{'component':'ogRepo', 'severity':'WARNING', 'http_code':'400', 'operation':'Run endpoint convert_image_to_virtual', 'desc':'Warning: There is an image with the name to assign'}", PRIORITY=journal.LOG_WARNING, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
return jsonify({
|
||||||
|
"success": False,
|
||||||
|
"exception": "There is an image with the name to assign"
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
try:
|
||||||
|
journal.send("Running script 'renameImage.py'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
# Ejecutamos el script "renameImage.py" (con los parámetros almacenados), y almacenamos el resultado:
|
||||||
|
result = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='UTF8')
|
||||||
|
|
||||||
|
# Evaluamos el resultado de la ejecución, y devolvemos la respuesta:
|
||||||
|
if result.returncode == 0:
|
||||||
|
journal.send("Script 'renameImage.py' result OK (ReturnCode: 0)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
journal.send("{'component':'ogRepo', 'severity':'INFO', 'http_code':'200', 'operation':'Run script renameImage.py', 'desc':'Result OK (ReturnCode: 0)'}", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
return jsonify({
|
||||||
|
"success": True,
|
||||||
|
"output": "Image renamed successfully"
|
||||||
|
}), 200
|
||||||
|
else:
|
||||||
|
journal.send(f"Script 'renameImage.py' result KO (Error: {result.stderr})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script renameImage.py', 'desc':'Result KO (Error: {result.stderr})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
return jsonify({
|
||||||
|
"success": False,
|
||||||
|
"error": result.stderr
|
||||||
|
}), 500
|
||||||
|
except Exception as error_description:
|
||||||
|
journal.send(f"Script 'renameImage.py' result KO (Exception: {str(error_description)})", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
journal.send(f"{{'component':'ogRepo', 'severity':'ERROR', 'http_code':'500', 'operation':'Run script renameImage.py', 'desc':'Result KO (Exception: {str(error_description)})'}}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api")
|
||||||
|
return jsonify({
|
||||||
|
"success": False,
|
||||||
|
"exception": str(error_description)
|
||||||
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1876,4 +1876,87 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
example: "(Exception description)"
|
example: "(Exception description)"
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/ogrepository/v1/images/rename:
|
||||||
|
put:
|
||||||
|
summary: "Renombrar una Imagen"
|
||||||
|
description: |
|
||||||
|
Este endpoint renombra la imagen especificada como primer parámetro (y todos sus archivos asociados), asignando el nombre especificado como segundo parámetro.
|
||||||
|
Utiliza el script "**renameImage.py**", que recibe como parámetros el nombre original y el nuevo nombre a asignar.
|
||||||
|
tags:
|
||||||
|
- "Varios"
|
||||||
|
parameters:
|
||||||
|
- name: JSON
|
||||||
|
in: body
|
||||||
|
required: true
|
||||||
|
description: |
|
||||||
|
* **ID_img** - Identificador de la imagen, correspondiente al contenido del archivo 'full.sum'
|
||||||
|
* **image_new_name** - Nuevo nombre a asignar a la imagen
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
ID_img:
|
||||||
|
type: string
|
||||||
|
example: "22735b9070e4a8043371b8c6ae52b90d"
|
||||||
|
image_new_name:
|
||||||
|
type: string
|
||||||
|
example: "Ubuntu_BKP"
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: "La imagen se ha renombrado exitosamente."
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
example: true
|
||||||
|
output:
|
||||||
|
type: string
|
||||||
|
example: "Image renamed successfully"
|
||||||
|
"400 (Image not found)":
|
||||||
|
description: "No se ha encontrado la imagen."
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
example: false
|
||||||
|
exception:
|
||||||
|
type: string
|
||||||
|
example: "Image not found"
|
||||||
|
"400 (Name incorrect)":
|
||||||
|
description: "Ya existe una imagen con el nombre a asignar."
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
example: false
|
||||||
|
exception:
|
||||||
|
type: string
|
||||||
|
example: "There is an image with the name to assign"
|
||||||
|
"500 (Error)":
|
||||||
|
description: "Error al renombrar la imagen."
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
example: false
|
||||||
|
error:
|
||||||
|
type: string
|
||||||
|
example: "(Error description)"
|
||||||
|
"500 (Exception)":
|
||||||
|
description: "Excepción inesperada al renombrar la imagen."
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
success:
|
||||||
|
type: boolean
|
||||||
|
example: false
|
||||||
|
exception:
|
||||||
|
type: string
|
||||||
|
example: "(Exception description)"
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -1109,6 +1109,62 @@ class RepoApiTestCase(unittest.TestCase):
|
||||||
self.assertIn('Error al cancelar las transmisiones P2P', response.data.decode())
|
self.assertIn('Error al cancelar las transmisiones P2P', response.data.decode())
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------- Tests "Renombrar una Imagen"
|
||||||
|
|
||||||
|
|
||||||
|
@patch('repo_api.get_image_params')
|
||||||
|
@patch('repo_api.subprocess.run')
|
||||||
|
def test_rename_image(self, mock_subprocess, mock_get_image_params):
|
||||||
|
""" Método de prueba del endpoint "Renombrar una Imagen".
|
||||||
|
"""
|
||||||
|
print("Testing endpoint 'Renombrar una Imagen'...")
|
||||||
|
mock_get_image_params.return_value = {'name': 'test4unittest', 'extension': 'img'}
|
||||||
|
mock_subprocess.return_value = MagicMock(returncode=0)
|
||||||
|
response = self.app.put('/ogrepository/v1/images/rename', data=json.dumps({"ID_img":"test_image_id", "image_new_name":"new_name"}), content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn('Image renamed successfully', json.loads(response.data)['output'])
|
||||||
|
|
||||||
|
|
||||||
|
@patch('repo_api.get_image_params')
|
||||||
|
@patch('repo_api.subprocess.run')
|
||||||
|
def test_rename_image_error500(self, mock_subprocess, mock_get_image_params):
|
||||||
|
""" Método de prueba del endpoint "Renombrar una Imagen"
|
||||||
|
(en caso de error "500").
|
||||||
|
"""
|
||||||
|
print("Testing endpoint 'Renombrar una Imagen' (error 500)...")
|
||||||
|
mock_get_image_params.return_value = {'name': 'test4unittest', 'extension': 'img'}
|
||||||
|
mock_subprocess.side_effect = Exception("Error al renombrar la imagen")
|
||||||
|
response = self.app.put('/ogrepository/v1/images/rename', data=json.dumps({"ID_img":"test_image_id", "image_new_name":"new_name"}), content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code, 500)
|
||||||
|
self.assertIn('Error al renombrar la imagen', response.data.decode())
|
||||||
|
|
||||||
|
|
||||||
|
@patch('repo_api.get_image_params')
|
||||||
|
def test_rename_image_error400_no_image(self, mock_get_image_params):
|
||||||
|
""" Método de prueba del endpoint "Renombrar una Imagen"
|
||||||
|
(en caso de error "400", por imagen inexistente).
|
||||||
|
"""
|
||||||
|
print("Testing endpoint 'Renombrar una Imagen' (error 400, no image)...")
|
||||||
|
mock_get_image_params.return_value = None
|
||||||
|
response = self.app.put('/ogrepository/v1/images/rename', data=json.dumps({"ID_img":"test_image_id", "image_new_name":"new_name"}), content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
self.assertIn('Image not found', json.loads(response.data)['error'])
|
||||||
|
|
||||||
|
|
||||||
|
@patch('repo_api.check_file_exists')
|
||||||
|
@patch('repo_api.get_image_params')
|
||||||
|
def test_rename_image_error400_name_incorrect(self, mock_get_image_params, mock_check_file_exists):
|
||||||
|
""" Método de prueba del endpoint "Renombrar una Imagen"
|
||||||
|
(en caso de error "400", por nombre incorrecto).
|
||||||
|
"""
|
||||||
|
print("Testing endpoint 'Renombrar una Imagen' (error 400, name incorrect)...")
|
||||||
|
mock_get_image_params.return_value = {'name': 'test4unittest', 'extension': 'img'}
|
||||||
|
mock_check_file_exists.return_value = True
|
||||||
|
response = self.app.put('/ogrepository/v1/images/rename', data=json.dumps({"ID_img":"test_image_id", "image_new_name":"new_name"}), content_type='application/json')
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
self.assertIn('There is an image with the name to assign', json.loads(response.data)['exception'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Este script renombra la imagen especificada como primer parámetro (y todos sus archivos asociados), asignando el nombre especificado como segundo parámetro.
|
||||||
|
|
||||||
|
Una vez renombrados los archivos, llama al script "updateRepoInfo.py", para actualizar la información del repositorio.
|
||||||
|
|
||||||
|
Parámetros
|
||||||
|
------------
|
||||||
|
sys.argv[1] - Nombre de la imagen a renombrar (sin extensión y sin ruta).
|
||||||
|
- Ejemplo1: Ubuntu24
|
||||||
|
- Ejemplo2: Windows10
|
||||||
|
|
||||||
|
sys.argv[2] - Nuevo nombre a asignar a la imagen (sin extensión y sin ruta).
|
||||||
|
- Ejemplo1: Ubuntu24_BKP
|
||||||
|
- Ejemplo2: Windows10_BKP
|
||||||
|
|
||||||
|
Sintaxis
|
||||||
|
----------
|
||||||
|
./renameImage.py image_to_rename image_new_name
|
||||||
|
|
||||||
|
Ejemplos
|
||||||
|
---------
|
||||||
|
./renameImage.py Ubuntu24 Ubuntu24_BKP
|
||||||
|
./renameImage.py Windows10 Windows10_BKP
|
||||||
|
"""
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
# IMPORTS
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
from systemd import journal
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
# VARIABLES
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
script_name = os.path.basename(__file__)
|
||||||
|
repo_path = '/opt/opengnsys/ogrepository/images/' # No borrar la barra final
|
||||||
|
update_repo_script = '/opt/opengnsys/ogrepository/bin/updateRepoInfo.py'
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
# FUNCTIONS
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def show_help():
|
||||||
|
""" Imprime la ayuda, cuando se ejecuta el script con el parámetro "help".
|
||||||
|
"""
|
||||||
|
help_text = f"""
|
||||||
|
Sintaxis: {script_name} image_to_rename image_new_name
|
||||||
|
Ejemplo1: {script_name} Ubuntu24 Ubuntu24_BKP
|
||||||
|
Ejemplo2: {script_name} Windows10 Windows10_BKP
|
||||||
|
"""
|
||||||
|
print(help_text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def check_params():
|
||||||
|
""" Comprueba que se haya enviado la cantidad correcta de parámetros, y en el formato correcto.
|
||||||
|
Si no es así, muestra un mensaje de error, y sale del script.
|
||||||
|
LLama a la función "show_help" cuando se ejecuta el script con el parámetro "help".
|
||||||
|
"""
|
||||||
|
# Si se ejecuta el script con el parámetro "help", se muestra la ayuda, y se sale del script:
|
||||||
|
if len(sys.argv) == 2 and sys.argv[1] == "help":
|
||||||
|
show_help()
|
||||||
|
sys.exit(0)
|
||||||
|
# Si se ejecuta el script con más o menos de 2 parámetros, se muestra un error y la ayuda, y se sale del script:
|
||||||
|
elif len(sys.argv) != 3:
|
||||||
|
print(f"{script_name} Error: Formato incorrecto: Se debe especificar 2 parámetros")
|
||||||
|
show_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def rename_image(image_original_name, image_new_name):
|
||||||
|
""" Asigna el nuevo nombre especificado a la imagen y a todos los archivos asociados.
|
||||||
|
Al archivo ".info.checked" también le cambia la extensión a ".info",
|
||||||
|
para poder actualizar la información del repositorio posteriormente.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
journal.send("renameImage.py: Renaming image files...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
|
||||||
|
# Creamos una lista con las extensiones de los archivos de la imagen (menos "info.checked"):
|
||||||
|
extensions = ['.img', '.img.full.sum', '.img.size', '.img.sum', '.img.torrent']
|
||||||
|
|
||||||
|
# Renombramos cada uno de los archivos (menos "info.checked"):
|
||||||
|
for ext in extensions:
|
||||||
|
os.rename(f"{repo_path}{image_original_name}{ext}", f"{repo_path}{image_new_name}{ext}")
|
||||||
|
|
||||||
|
# Renombramos separadamente el archivo "info.checked" (porque también le cambiamos la extensión a "info"):
|
||||||
|
os.rename(f"{repo_path}{image_original_name}.img.info.checked", f"{repo_path}{image_new_name}.img.info")
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
journal.send(f"renameImage.py: Rename Image exception: {error}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def update_repo_info():
|
||||||
|
""" Actualiza la información del repositorio, ejecutando el script "updateRepoInfo.py".
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
journal.send("renameImage.py: Running script 'updateRepoInfo.py'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
result = subprocess.run(['python3', update_repo_script], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
journal.send(f"renameImage.py: 'updateRepoInfo.py' error: {error}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
sys.exit(3)
|
||||||
|
except Exception as error:
|
||||||
|
journal.send(f"renameImage.py: 'updateRepoInfo.py' exception: {error}", PRIORITY=journal.LOG_ERR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||||
|
sys.exit(4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
# MAIN
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
# Evaluamos si se ha enviado la cantidad correcta de parámetros, y en el formato correcto:
|
||||||
|
check_params()
|
||||||
|
|
||||||
|
# Almacenamos el nombre original de la imagen, y el nuevo nombre a asignar (desde los parámetros):
|
||||||
|
image_original_name = sys.argv[1]
|
||||||
|
image_new_name = sys.argv[2]
|
||||||
|
|
||||||
|
# Renombramos la imagen y sus archivos asociados:
|
||||||
|
rename_image(image_original_name, image_new_name)
|
||||||
|
|
||||||
|
# Actualizamos la información del repositorio, ejecutando el script "updateRepoInfo.py":
|
||||||
|
update_repo_info()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------------------
|
|
@ -8,6 +8,7 @@ Build-Depends: debhelper-compat (= 12)
|
||||||
Package: ogrepository
|
Package: ogrepository
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Pre-Depends: debian-archive-keyring , debconf (>= 1.5.0),
|
Pre-Depends: debian-archive-keyring , debconf (>= 1.5.0),
|
||||||
Depends: ${misc:Depends}, git, python3, python3-pip, python3-flask, python3-paramiko, python3-psutil, python3-flasgger, samba, gunicorn, wakeonlan , lzop , partclone , qemu-utils , udpcast
|
Depends: ${misc:Depends}, git, python3, python3-pip, python3-flask, python3-paramiko, python3-psutil, python3-flasgger, samba, gunicorn, wakeonlan , lzop , partclone , qemu-utils , udpcast, uftp
|
||||||
Description: Ogrepsoitory Package
|
Description: Ogrepsoitory Package
|
||||||
This package provides Ogrepsoitory service.
|
This package provides Ogrepository service.
|
||||||
|
X-OG-Release: opengnsys-1.6.0-beta, opengnsys-1.6.1-beta
|
||||||
|
|
|
@ -45,16 +45,23 @@ done
|
||||||
# Copy ssh keys
|
# Copy ssh keys
|
||||||
cp /opt/opengnsys/ogrepository/etc/opengnsys $OPENGNSYS_HOME/.ssh/id_ed25519
|
cp /opt/opengnsys/ogrepository/etc/opengnsys $OPENGNSYS_HOME/.ssh/id_ed25519
|
||||||
cp /opt/opengnsys/ogrepository/etc/opengnsys.pub $OPENGNSYS_HOME/.ssh/id_ed25519.pub
|
cp /opt/opengnsys/ogrepository/etc/opengnsys.pub $OPENGNSYS_HOME/.ssh/id_ed25519.pub
|
||||||
|
# Change permissions
|
||||||
|
chmod 700 $OPENGNSYS_HOME/.ssh
|
||||||
|
chmod 600 $OPENGNSYS_HOME/.ssh/id_ed25519
|
||||||
|
chmod 644 $OPENGNSYS_HOME/.ssh/id_ed25519.pub
|
||||||
|
# Genera authorized_keys
|
||||||
|
cat $OPENGNSYS_HOME/.ssh/id_ed25519.pub >> $OPENGNSYS_HOME/.ssh/authorized_keys
|
||||||
|
chmod 600 $OPENGNSYS_HOME/.ssh/authorized_keys
|
||||||
|
chown -R opengnsys:opengnsys $OPENGNSYS_HOME/.ssh
|
||||||
|
|
||||||
if [ -f /etc/samba/smb.conf ]; then
|
if [ -f /etc/samba/smb.conf ]; then
|
||||||
dpkg-divert --package ogrepository --add --rename --divert /etc/samba/smb.conf.orig /etc/samba/smb.conf
|
dpkg-divert --package ogrepository --add --rename --divert /etc/samba/smb.conf.orig /etc/samba/smb.conf
|
||||||
|
cp /etc/samba/smb.conf.orig /etc/samba/smb.conf
|
||||||
|
if ! grep -q "include = /etc/samba/ogrepo-smb.conf" /etc/samba/smb.conf; then
|
||||||
|
echo "include = /etc/samba/ogrepo-smb.conf" >> /etc/samba/smb.conf
|
||||||
|
fi
|
||||||
|
(echo "$SAMBA_PASS"; echo "$SAMBA_PASS") | smbpasswd -a $SAMBA_USER
|
||||||
fi
|
fi
|
||||||
# Incluir el archivo de configuración de samba si no está incluido ya
|
|
||||||
if ! grep -q "include = /etc/samba/ogrepo-smb.conf" /etc/samba/smb.conf; then
|
|
||||||
echo "include = /etc/samba/ogrepo-smb.conf" >> /etc/samba/smb.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
(echo "$SAMBA_PASS"; echo "$SAMBA_PASS") | smbpasswd -a $SAMBA_USER
|
|
||||||
|
|
||||||
# Configure Repo
|
# Configure Repo
|
||||||
|
|
||||||
|
@ -62,13 +69,26 @@ done
|
||||||
sed -i "s/SERVERIP/$OGREPO_IP/g" /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg
|
sed -i "s/SERVERIP/$OGREPO_IP/g" /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg
|
||||||
sed -i "s/OGCOREIP/$OGCORE_IP/g" /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg
|
sed -i "s/OGCOREIP/$OGCORE_IP/g" /opt/opengnsys/ogrepository/etc/ogAdmRepo.cfg
|
||||||
|
|
||||||
|
# Copiar sudoers file ogrepository/etc/opengnsys-repository
|
||||||
|
cp /opt/opengnsys/ogrepository/etc/opengnsys-repository /etc/sudoers.d/opengnsys
|
||||||
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
|
elif [ "$1" = "configure" ] && [ -n "$2" ]; then
|
||||||
echo "Actualización desde la versión $2"
|
echo "Actualización desde la versión $2"
|
||||||
|
# Recopy static files without configuration
|
||||||
|
cp /opt/opengnsys/ogrepository/etc/opengnsys-repository /etc/sudoers.d/opengnsys-repository
|
||||||
|
OPENGNSYS_HOME=$(getent passwd opengnsys | cut -d: -f6)
|
||||||
|
# Create .ssh directory
|
||||||
|
mkdir -p $OPENGNSYS_HOME/.ssh
|
||||||
|
# Copy ssh keys
|
||||||
|
cp /opt/opengnsys/ogrepository/etc/opengnsys $OPENGNSYS_HOME/.ssh/id_ed25519
|
||||||
|
cp /opt/opengnsys/ogrepository/etc/opengnsys.pub $OPENGNSYS_HOME/.ssh/id_ed25519.pub
|
||||||
|
cat $OPENGNSYS_HOME/.ssh/id_ed25519.pub >> $OPENGNSYS_HOME/.ssh/authorized_keys
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cambiar la propiedad de los archivos al usuario especificado
|
# Cambiar la propiedad de los archivos al usuario especificado
|
||||||
chown opengnsys:www-data /opt/opengnsys/
|
chown opengnsys:www-data /opt/opengnsys/
|
||||||
chown -R opengnsys:www-data /opt/opengnsys/ogrepository
|
chown -R opengnsys:www-data /opt/opengnsys/ogrepository
|
||||||
|
chmod 755 /opt/opengnsys/ogrepository/bin/*
|
||||||
|
|
||||||
# Install http server stuff
|
# Install http server stuff
|
||||||
# Reiniciar servicios si es necesario
|
# Reiniciar servicios si es necesario
|
||||||
|
|
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
UNIT_FILE="/etc/systemd/system/ogrepo-api.service"
|
||||||
NGINX_FILE="/etc/nginx/sites-enabled/oggui.conf"
|
|
||||||
UNIT_FILE="/etc/systemd/system/oggui.service"
|
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
remove)
|
remove)
|
||||||
echo "El paquete se está desinstalando..."
|
echo "El paquete se está desinstalando..."
|
||||||
# Aquí puedes hacer limpieza de archivos o servicios
|
# Aquí puedes hacer limpieza de archivos o servicios
|
||||||
if [ -L "$NGINX_FILE" ]; then
|
|
||||||
rm -f "$NGINX_FILE"
|
|
||||||
systemctl restart nginx
|
|
||||||
fi
|
|
||||||
if [ -L "$UNIT_FILE" ]; then
|
if [ -L "$UNIT_FILE" ]; then
|
||||||
rm -f "$UNIT_FILE"
|
rm -f "$UNIT_FILE"
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
|
@ -44,11 +44,18 @@ case "$1" in
|
||||||
rm -f /var/lib/dpkg/info/ogrepository.post-invoke
|
rm -f /var/lib/dpkg/info/ogrepository.post-invoke
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Remove sudoers file
|
||||||
|
if [ -f /etc/sudoers.d/opengnsys-repository ]; then
|
||||||
|
echo "Removing sudoers file..."
|
||||||
|
rm -f /etc/sudoers.d/opengnsys-repository
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Limpieza completada."
|
echo "Limpieza completada."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
upgrade|deconfigure)
|
upgrade|deconfigure)
|
||||||
# No hacer nada en actualización o desconfiguración
|
# No hacer nada en actualización o desconfiguración
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Variables para facilitar la lectura
|
||||||
|
Cmnd_Alias MOUNT_RECOVERY = \
|
||||||
|
/usr/bin/mkdir -p /mnt/recovery, \
|
||||||
|
/usr/bin/mount /dev/* /mnt/recovery, \
|
||||||
|
/usr/bin/mount --bind /dev /mnt/recovery/dev, \
|
||||||
|
/usr/bin/mount --bind /proc /mnt/recovery/proc, \
|
||||||
|
/usr/bin/mount --bind /sys /mnt/recovery/sys, \
|
||||||
|
/usr/bin/umount /mnt/recovery/dev, \
|
||||||
|
/usr/bin/umount /mnt/recovery/proc, \
|
||||||
|
/usr/bin/umount /mnt/recovery/sys, \
|
||||||
|
/usr/bin/umount -l /mnt/recovery
|
||||||
|
|
||||||
|
Cmnd_Alias CHROOT_GRUB = \
|
||||||
|
/usr/sbin/chroot /mnt/recovery /usr/sbin/grub-install --target=i386-pc *, \
|
||||||
|
/usr/sbin/chroot /mnt/recovery /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
|
||||||
|
|
||||||
|
Cmnd_Alias LOOP_KPARTX = \
|
||||||
|
/usr/sbin/losetup -d *, \
|
||||||
|
/usr/sbin/kpartx -av /opt/opengnsys/ogrepository/images_virtual/*, \
|
||||||
|
/usr/sbin/kpartx -d /opt/opengnsys/ogrepository/images_virtual/*, \
|
||||||
|
/usr/sbin/blkid /dev/mapper/*
|
||||||
|
|
||||||
|
Cmnd_Alias KILL_BT = \
|
||||||
|
/usr/bin/pkill -9 btlaunchmany, \
|
||||||
|
/usr/bin/pkill -9 bttrack, \
|
||||||
|
/usr/bin/kill -9 *
|
||||||
|
|
||||||
|
# Permitir al usuario opengnsys ejecutar estos comandos sin contraseña
|
||||||
|
opengnsys ALL=(root) NOPASSWD: MOUNT_RECOVERY, CHROOT_GRUB, LOOP_KPARTX, KILL_BT
|
|
@ -3,8 +3,8 @@ Description=Gunicorn instance to serve repo_api
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=%%OGREPOSITORY_USER%%
|
User=opengnsys
|
||||||
Group=%%OGREPOSITORY_USER%%
|
Group=opengnsys
|
||||||
WorkingDirectory=/opt/opengnsys/ogrepository/api
|
WorkingDirectory=/opt/opengnsys/ogrepository/api
|
||||||
ExecStart=/usr/bin/gunicorn -w 4 -b 0.0.0.0:8006 repo_api:app
|
ExecStart=/usr/bin/gunicorn -w 4 -b 0.0.0.0:8006 repo_api:app
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue