mirror of https://git.48k.eu/ogserver
#915 Set repository on image creation
Assign to the image the repository indicated in the JSON body instead of a default one.master
parent
b86b6e1443
commit
c0573b9ef0
45
src/dbi.c
45
src/dbi.c
|
@ -127,14 +127,55 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
|
|||
return 0;
|
||||
}
|
||||
|
||||
const int og_dbi_get_repository(const struct og_dbi *dbi, const char *repo_ip)
|
||||
{
|
||||
const char *msglog;
|
||||
dbi_result result;
|
||||
int repo_id;
|
||||
|
||||
/* database can store duplicated repositories, limit query to return
|
||||
* only one */
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"SELECT idrepositorio FROM repositorios "
|
||||
"WHERE ip = '%s' LIMIT 1",
|
||||
repo_ip);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||
__func__, __LINE__, msglog);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!dbi_result_next_row(result)) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR,
|
||||
"software profile does not exist in database (%s:%d) %s\n",
|
||||
__func__, __LINE__, msglog);
|
||||
dbi_result_free(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
repo_id = dbi_result_get_int(result, "idrepositorio");
|
||||
dbi_result_free(result);
|
||||
|
||||
return repo_id;
|
||||
}
|
||||
|
||||
#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;
|
||||
int repo_id;
|
||||
|
||||
repo_id = og_dbi_get_repository(dbi, image->repo_ip);
|
||||
if (repo_id < 0) {
|
||||
syslog(LOG_ERR, "failed to get repository (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"SELECT nombreca FROM imagenes WHERE nombreca = '%s'",
|
||||
|
@ -167,7 +208,7 @@ int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image)
|
|||
"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,
|
||||
image->group_id, repo_id,
|
||||
OG_IMAGE_DEFAULT_TYPE);
|
||||
|
||||
if (!result) {
|
||||
|
|
|
@ -2127,7 +2127,9 @@ int og_json_parse_create_image(json_t *element,
|
|||
sizeof(params->image.name));
|
||||
params->flags |= OG_REST_PARAM_NAME;
|
||||
} else if (!strcmp(key, "repository")) {
|
||||
err = og_json_parse_string(value, ¶ms->repository);
|
||||
err = og_json_parse_string_copy(value,
|
||||
(char *)¶ms->image.repo_ip,
|
||||
sizeof(params->image.repo_ip));
|
||||
params->flags |= OG_REST_PARAM_REPO;
|
||||
} else if (!strcmp(key, "clients")) {
|
||||
err = og_json_parse_clients(value, params);
|
||||
|
|
Loading…
Reference in New Issue