source: ogServer-Git/src/dbi.h @ d2f20d0

Last change on this file since d2f20d0 was d2f20d0, checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago

#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

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#ifndef __OG_DBI
2#define __OG_DBI
3
4#include <dbi/dbi.h>
5#include <stdbool.h>
6#include <sys/stat.h>
7
8struct og_dbi_config {
9        const char      *user;
10        const char      *pass;
11        const char      *ip;
12        const char      *port;
13        const char      *name;
14};
15
16struct og_dbi {
17        dbi_conn        conn;
18        dbi_inst        inst;
19};
20
21struct og_dbi *og_dbi_open(struct og_dbi_config *config);
22void og_dbi_close(struct og_dbi *db);
23
24#define OG_DB_COMPUTER_NAME_MAXLEN      100
25#define OG_DB_CENTER_NAME_MAXLEN        100
26#define OG_DB_ROOM_NAME_MAXLEN          100
27#define OG_DB_SERIAL_NUMBER_MAXLEN      25
28#define OG_DB_IMAGE_DESCRIPTION_MAXLEN  250
29#define OG_DB_IMAGE_NAME_MAXLEN 50
30#define OG_DB_FILESYSTEM_MAXLEN 16
31#define OG_DB_NETDRIVER_MAXLEN  30
32#define OG_DB_NETIFACE_MAXLEN   4
33#define OG_DB_LIVEDIR_MAXLEN    50
34#define OG_DB_INT8_MAXLEN       8
35#define OG_DB_BOOT_MAXLEN       30
36#define OG_DB_INT_MAXLEN        11
37#define OG_DB_MAC_MAXLEN        15
38#define OG_DB_IP_MAXLEN         15
39#define OG_DB_SMALLINT_MAXLEN   6
40
41struct og_image_legacy {
42        char software_id[OG_DB_INT_MAXLEN + 1];
43        char image_id[OG_DB_INT_MAXLEN + 1];
44        char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
45        char repo[OG_DB_IP_MAXLEN + 1];
46        char part[OG_DB_SMALLINT_MAXLEN + 1];
47        char disk[OG_DB_SMALLINT_MAXLEN + 1];
48        char code[OG_DB_INT8_MAXLEN + 1];
49};
50
51struct og_image {
52        char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
53        char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1];
54        const char *filename;
55        uint64_t center_id;
56        uint64_t datasize;
57        uint64_t group_id;
58        struct stat image_stats;
59};
60
61struct og_legacy_partition {
62        char partition[OG_DB_SMALLINT_MAXLEN + 1];
63        char code[OG_DB_INT8_MAXLEN + 1];
64        char size[OG_DB_INT_MAXLEN + 1];
65        char filesystem[OG_DB_FILESYSTEM_MAXLEN + 1];
66        char format[2]; /* Format is a boolean 0 or 1 => length is 2 */
67};
68
69struct og_computer {
70        unsigned int    procedure_id;
71        unsigned int    hardware_id;
72        unsigned int    repo_id;
73        unsigned int    center;
74        unsigned int    room;
75        unsigned int    id;
76        bool            maintenance;
77        bool            remote;
78        char            serial_number[OG_DB_SERIAL_NUMBER_MAXLEN + 1];
79        char            netdriver[OG_DB_NETDRIVER_MAXLEN + 1];
80        char            name[OG_DB_COMPUTER_NAME_MAXLEN + 1];
81        char            netiface[OG_DB_NETIFACE_MAXLEN + 1];
82        char            livedir[OG_DB_LIVEDIR_MAXLEN + 1];
83        char            netmask[OG_DB_IP_MAXLEN + 1];
84        char            boot[OG_DB_BOOT_MAXLEN + 1];
85        char            mac[OG_DB_MAC_MAXLEN + 1];
86        char            ip[OG_DB_IP_MAXLEN + 1];
87};
88
89struct in_addr;
90int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
91                             struct in_addr addr);
92int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image);
93
94#endif
Note: See TracBrowser for help on using the repository browser.