From d2f20d0be06617f421eecca111449d94672695eb Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Tue, 13 Oct 2020 14:46:28 +0200 Subject: #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 --- src/dbi.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/dbi.h') diff --git a/src/dbi.h b/src/dbi.h index 7bfe311..8cd6fe6 100644 --- a/src/dbi.h +++ b/src/dbi.h @@ -3,6 +3,7 @@ #include #include +#include struct og_dbi_config { const char *user; @@ -24,6 +25,7 @@ void og_dbi_close(struct og_dbi *db); #define OG_DB_CENTER_NAME_MAXLEN 100 #define OG_DB_ROOM_NAME_MAXLEN 100 #define OG_DB_SERIAL_NUMBER_MAXLEN 25 +#define OG_DB_IMAGE_DESCRIPTION_MAXLEN 250 #define OG_DB_IMAGE_NAME_MAXLEN 50 #define OG_DB_FILESYSTEM_MAXLEN 16 #define OG_DB_NETDRIVER_MAXLEN 30 @@ -46,6 +48,16 @@ struct og_image_legacy { char code[OG_DB_INT8_MAXLEN + 1]; }; +struct og_image { + char name[OG_DB_IMAGE_NAME_MAXLEN + 1]; + char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1]; + const char *filename; + uint64_t center_id; + uint64_t datasize; + uint64_t group_id; + struct stat image_stats; +}; + struct og_legacy_partition { char partition[OG_DB_SMALLINT_MAXLEN + 1]; char code[OG_DB_INT8_MAXLEN + 1]; @@ -77,5 +89,6 @@ struct og_computer { struct in_addr; int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer, struct in_addr addr); +int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image); #endif -- cgit v1.2.3-18-g5258