summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-10-13 14:46:28 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-10-14 12:05:25 +0200
commitd2f20d0be06617f421eecca111449d94672695eb (patch)
tree6547ad52f265f89158553d26bc9e7eac9ed72518 /src/dbi.c
parent24c8b940e614fa795b679628be2e6c0d68bd41e5 (diff)
#942 Create DB image when calling POST /image/create
In case the DB entry for an image does not exist when POST /image/create is called, this patch takes care of calling it. This adds few optional json parameters to the POST /image/create API. If optional parameters are included then this patch creates the DB entry, otherwise it just creates the actual image and updates the existing entry. Request: POST /image/create { "clients":["192.168.56.11"], "disk":"1", "partition":"1", "name":"archlinux", "repository":"192.168.56.10", "id":"24", "code":"131", "description":"This is a test", "group_id":0, "center_id":1 } Response: 200 OK
Diffstat (limited to 'src/dbi.c')
-rw-r--r--src/dbi.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 968b00e..33c4a8e 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -123,3 +123,39 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
return 0;
}
+
+#define OG_UNASSIGNED_SW_ID 0
+#define OG_DEFAULT_REPO_ID 1
+#define OG_IMAGE_DEFAULT_TYPE 1 /* monolithic */
+
+int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image)
+{
+ const char *msglog;
+ dbi_result result;
+
+ result = dbi_conn_queryf(dbi->conn,
+ "INSERT INTO imagenes (nombreca, "
+ "descripcion, "
+ "idperfilsoft, "
+ "idcentro, "
+ "comentarios, "
+ "grupoid, "
+ "idrepositorio, "
+ "tipo, "
+ "ruta) "
+ "VALUES ('%s', '%s', %u, %lu, '', %u, %lu, %u, '')",
+ image->name, image->description,
+ OG_UNASSIGNED_SW_ID, image->center_id,
+ image->group_id, OG_DEFAULT_REPO_ID,
+ OG_IMAGE_DEFAULT_TYPE);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to add client to database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ dbi_result_free(result);
+ return dbi_conn_sequence_last(dbi->conn, NULL);
+}