source: ogServer-Git/src/dbi.h

Last change on this file was 30d6af0, checked in by Javier Sánchez Parra <jsanchez@…>, 22 months ago

#915 Use the repository id on image list

API "GET /images" shows the repository ID the image belongs to, instead
of the IP. This is a preparative commit to the support of repositories
with several IPs.

Request GET /images
Response 200 OK:
{

"images": [

{

"name": "windows10",
"datasize": 0,
"size": 626088433,
"modified": "Fri Jun 10 12:20:32 2022",
"permissions": "744",
"software_id": 1,
"type": 1,
"id": 6,
"repo_id": 1

}

],
"disk": {

"total": 52573995008,
"free": 38964637696

}

}

  • Property mode set to 100644
File size: 3.0 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_ROOM_LOC_MAXLEN           255
28#define OG_DB_SERIAL_NUMBER_MAXLEN      25
29#define OG_DB_IMAGE_DESCRIPTION_MAXLEN  250
30#define OG_DB_PART_NAME_MAXLEN  250
31#define OG_DB_IMAGE_NAME_MAXLEN 50
32#define OG_DB_FILESYSTEM_MAXLEN 16
33#define OG_DB_NETDRIVER_MAXLEN  30
34#define OG_DB_NETIFACE_MAXLEN   4
35#define OG_DB_LIVEDIR_MAXLEN    50
36#define OG_DB_INT8_MAXLEN       8
37#define OG_DB_BOOT_MAXLEN       30
38#define OG_DB_INT_MAXLEN        11
39#define OG_DB_MAC_MAXLEN        15
40#define OG_DB_IP_MAXLEN         15
41#define OG_DB_SMALLINT_MAXLEN   6
42
43struct og_image_legacy {
44        char software_id[OG_DB_INT_MAXLEN + 1];
45        char image_id[OG_DB_INT_MAXLEN + 1];
46        char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
47        char repo[OG_DB_IP_MAXLEN + 1];
48        char part[OG_DB_SMALLINT_MAXLEN + 1];
49        char disk[OG_DB_SMALLINT_MAXLEN + 1];
50        char code[OG_DB_INT8_MAXLEN + 1];
51};
52
53struct og_image {
54        char name[OG_DB_IMAGE_NAME_MAXLEN + 1];
55        char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1];
56        uint64_t software_id;
57        uint64_t center_id;
58        uint64_t datasize;
59        uint64_t group_id;
60        uint64_t repo_id;
61        uint64_t type;
62        uint64_t id;
63        struct stat image_stats;
64};
65
66struct og_legacy_partition {
67        char partition[OG_DB_SMALLINT_MAXLEN + 1];
68        char code[OG_DB_PART_NAME_MAXLEN + 1];
69        char size[OG_DB_INT_MAXLEN + 1];
70        char filesystem[OG_DB_FILESYSTEM_MAXLEN + 1];
71        char format[2]; /* Format is a boolean 0 or 1 => length is 2 */
72};
73
74struct og_computer {
75        unsigned int    procedure_id;
76        unsigned int    hardware_id;
77        unsigned int    repo_id;
78        unsigned int    center;
79        unsigned int    room;
80        unsigned int    id;
81        bool            maintenance;
82        bool            remote;
83        char            serial_number[OG_DB_SERIAL_NUMBER_MAXLEN + 1];
84        char            netdriver[OG_DB_NETDRIVER_MAXLEN + 1];
85        char            name[OG_DB_COMPUTER_NAME_MAXLEN + 1];
86        char            netiface[OG_DB_NETIFACE_MAXLEN + 1];
87        char            livedir[OG_DB_LIVEDIR_MAXLEN + 1];
88        char            netmask[OG_DB_IP_MAXLEN + 1];
89        char            boot[OG_DB_BOOT_MAXLEN + 1];
90        char            mac[OG_DB_MAC_MAXLEN + 1];
91        char            ip[OG_DB_IP_MAXLEN + 1];
92};
93
94struct og_room {
95        uint32_t        center;
96        uint32_t        group;
97        char            location[OG_DB_ROOM_LOC_MAXLEN + 1];
98        char            name[OG_DB_ROOM_NAME_MAXLEN + 1];
99        char            gateway[OG_DB_IP_MAXLEN + 1];
100        char            netmask[OG_DB_IP_MAXLEN + 1];
101        char            ntp[OG_DB_IP_MAXLEN + 1];
102        char            dns[OG_DB_IP_MAXLEN + 1];
103        bool            remote;
104};
105
106struct in_addr;
107int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
108                             struct in_addr addr);
109int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image);
110
111int og_dbi_schema_update(void);
112
113int og_dbi_get_repository_ip(const struct og_dbi *dbi, const uint64_t image_id,
114                             char *repository_ip);
115
116#endif
Note: See TracBrowser for help on using the repository browser.