summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.c98
-rw-r--r--src/ogAdmServer.c104
-rw-r--r--src/ogAdmServer.h1
3 files changed, 91 insertions, 112 deletions
diff --git a/src/client.c b/src/client.c
index 93bd8f8..9c4ec59 100644
--- a/src/client.c
+++ b/src/client.c
@@ -497,6 +497,96 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
return 0;
}
+static bool og_dbi_update_image(struct og_dbi *dbi,
+ const struct og_image_legacy *img_info,
+ const char *computer_id)
+{
+ const char *msglog;
+ dbi_result result;
+ int repo_id, sw_id;
+
+ /* find repository identifier by repository ip and computer ID. */
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT repositorios.idrepositorio"
+ " FROM repositorios"
+ " LEFT JOIN ordenadores USING (idrepositorio)"
+ " WHERE repositorios.ip='%s' AND ordenadores.idordenador=%s",
+ img_info->repo, computer_id);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return false;
+ }
+ if (!dbi_result_next_row(result)) {
+ syslog(LOG_ERR,
+ "repository does not exist in database (%s:%d)\n",
+ __func__, __LINE__);
+ dbi_result_free(result);
+ return false;
+ }
+ repo_id = dbi_result_get_uint(result, "idrepositorio");
+ dbi_result_free(result);
+
+ /* find software id by computer ID, disk number and partition. */
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT idperfilsoft"
+ " FROM ordenadores_particiones"
+ " WHERE idordenador=%s AND numdisk=%s AND numpar=%s",
+ computer_id, img_info->disk, img_info->part);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return false;
+ }
+ if (!dbi_result_next_row(result)) {
+ syslog(LOG_ERR,
+ "software profile does not exist in database (%s:%d)\n",
+ __func__, __LINE__);
+ dbi_result_free(result);
+ return false;
+ }
+ sw_id = dbi_result_get_uint(result, "idperfilsoft");
+ dbi_result_free(result);
+
+ /* update image table with this new image. */
+ result = dbi_conn_queryf(dbi->conn,
+ "UPDATE imagenes"
+ " SET idordenador=%s, numdisk=%s, numpar=%s, codpar=%s,"
+ " idperfilsoft=%d, idrepositorio=%d,"
+ " fechacreacion=NOW(), revision=revision+1"
+ " WHERE idimagen=%s",
+ computer_id, img_info->disk, img_info->part, img_info->code,
+ sw_id, repo_id, img_info->image_id);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return false;
+ }
+ dbi_result_free(result);
+
+ /* attach image to partition. */
+ result = dbi_conn_queryf(dbi->conn,
+ "UPDATE ordenadores_particiones"
+ " SET idimagen=%s, revision=(SELECT revision FROM imagenes WHERE idimagen=%s),"
+ " fechadespliegue=NOW()"
+ " WHERE idordenador=%s AND numdisk=%s AND numpar=%s",
+ img_info->image_id, img_info->image_id,
+ computer_id, img_info->disk, img_info->part);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return false;
+ }
+ dbi_result_free(result);
+
+ return true;
+}
+
static int update_image_info(struct og_dbi *dbi, const char *image_id,
const char *clonator, const char *compressor,
const char *filesystem, const uint64_t datasize,
@@ -628,13 +718,7 @@ static int og_resp_image_create(json_t *data, struct og_client *cli)
return -1;
}
- res = actualizaCreacionImagen(dbi,
- img_legacy.image_id,
- img_legacy.disk,
- img_legacy.part,
- img_legacy.code,
- img_legacy.repo,
- soft_legacy.id);
+ res = og_dbi_update_image(dbi, &img_legacy, soft_legacy.id);
if (!res) {
og_dbi_close(dbi);
syslog(LOG_ERR, "Problem updating client configuration\n");
diff --git a/src/ogAdmServer.c b/src/ogAdmServer.c
index 6f4f704..915f69c 100644
--- a/src/ogAdmServer.c
+++ b/src/ogAdmServer.c
@@ -278,110 +278,6 @@ int checkDato(struct og_dbi *dbi, char *dato, const char *tabla,
}
// ________________________________________________________________________________________________________
-// Función: actualizaCreacionImagen
-//
-// Descripción:
-// Esta función actualiza la base de datos con el resultado de la creación de una imagen
-// Parámetros:
-// - db: Objeto base de datos (ya operativo)
-// - tbl: Objeto tabla
-// - idi: Identificador de la imagen
-// - dsk: Disco de donde se creó
-// - par: Partición de donde se creó
-// - cpt: Código de partición
-// - ipr: Ip del repositorio
-// - ido: Identificador del ordenador modelo
-// Devuelve:
-// true: Si el proceso es correcto
-// false: En caso de ocurrir algún error
-// ________________________________________________________________________________________________________
-bool actualizaCreacionImagen(struct og_dbi *dbi, char *idi, char *dsk,
- char *par, char *cpt, char *ipr, char *ido)
-{
- const char *msglog;
- dbi_result result;
- int idr,ifs;
-
- /* Toma identificador del repositorio correspondiente al ordenador modelo */
- result = dbi_conn_queryf(dbi->conn,
- "SELECT repositorios.idrepositorio"
- " FROM repositorios"
- " LEFT JOIN ordenadores USING (idrepositorio)"
- " WHERE repositorios.ip='%s' AND ordenadores.idordenador=%s", ipr, ido);
-
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return false;
- }
- if (!dbi_result_next_row(result)) {
- syslog(LOG_ERR,
- "repository does not exist in database (%s:%d)\n",
- __func__, __LINE__);
- dbi_result_free(result);
- return false;
- }
- idr = dbi_result_get_uint(result, "idrepositorio");
- dbi_result_free(result);
-
- /* Toma identificador del perfilsoftware */
- result = dbi_conn_queryf(dbi->conn,
- "SELECT idperfilsoft"
- " FROM ordenadores_particiones"
- " WHERE idordenador=%s AND numdisk=%s AND numpar=%s", ido, dsk, par);
-
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return false;
- }
- if (!dbi_result_next_row(result)) {
- syslog(LOG_ERR,
- "software profile does not exist in database (%s:%d)\n",
- __func__, __LINE__);
- dbi_result_free(result);
- return false;
- }
- ifs = dbi_result_get_uint(result, "idperfilsoft");
- dbi_result_free(result);
-
- /* Actualizar los datos de la imagen */
- result = dbi_conn_queryf(dbi->conn,
- "UPDATE imagenes"
- " SET idordenador=%s, numdisk=%s, numpar=%s, codpar=%s,"
- " idperfilsoft=%d, idrepositorio=%d,"
- " fechacreacion=NOW(), revision=revision+1"
- " WHERE idimagen=%s", ido, dsk, par, cpt, ifs, idr, idi);
-
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return false;
- }
- dbi_result_free(result);
-
- /* Actualizar los datos en el cliente */
- result = dbi_conn_queryf(dbi->conn,
- "UPDATE ordenadores_particiones"
- " SET idimagen=%s, revision=(SELECT revision FROM imagenes WHERE idimagen=%s),"
- " fechadespliegue=NOW()"
- " WHERE idordenador=%s AND numdisk=%s AND numpar=%s",
- idi, idi, ido, dsk, par);
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return false;
- }
- dbi_result_free(result);
-
- return true;
-}
-
-// ________________________________________________________________________________________________________
// Función: actualizaHardware
//
// Descripción:
diff --git a/src/ogAdmServer.h b/src/ogAdmServer.h
index 59c7ea1..2b7a93d 100644
--- a/src/ogAdmServer.h
+++ b/src/ogAdmServer.h
@@ -23,7 +23,6 @@
struct og_dbi;
bool actualizaConfiguracion(struct og_dbi *,char* ,int);
-bool actualizaCreacionImagen(struct og_dbi *,char*,char*,char*,char*,char*,char*);
bool actualizaHardware(struct og_dbi *dbi, char* ,char*,char*,char*);
bool cuestionPerfilHardware(struct og_dbi *dbi,char*,char*,int,char*,char*,int *,int);
bool actualizaSoftware(struct og_dbi *, char* , char* , char*,char*,char*);