Commit Graph

25 Commits (5cecb4f294f48a61f51dac6d5cec81b02dedcafc)

Author SHA1 Message Date
OpenGnSys Support Team da31efb4e0 rest: statify image restore and create function
only used in rest.c, remove the forward declaration in json.h
2024-12-02 23:55:35 +01:00
Alejandro Sirgo Rica 00d54325d3 rest: update POST /shell/run for cmd execution
Remove legacy "echo" parameter.
Add boolean "inline" parameter to determine if the execution is
an inline command or a predefined script in /opt/opengnsys/shell/
2024-11-27 14:06:29 +01:00
OpenGnSys Support Team 3c395ecea2 client: move image list to cache data to consolidate it
Move list of images in the cache to cache_data. Add new functions to
initialize cache data (image list) and release it.
2024-09-25 14:49:17 +02:00
OpenGnSys Support Team 65aee8f3f3 json: move list_head at the tip of struct og_cache_image
this is accessed on list iterations in first place, improve cache locality.
2024-09-25 14:48:49 +02:00
Alejandro Sirgo Rica c7bfc370ae src: add used_size and free_size to partition data
Extend database table ordenadores_particiones to add new "used_size" and "free_size" fields.

  FIELD       TYPE
| tamano    | bigint   |
| uso       | tinyint  |
| used_size | bigint   |
| free_size | bigint   |

"tamano" is the field storing the total size of the partition.
"uso" is a field storing the integer percentage of use, it is preserved for backwards compatibility with scritps that access the database.
"used_size" and "free_size" contain the used and free partition
size in bytes.

Old response from ogClient for /cache/delete, /cache/fetch
and /image/restore:
{
  'cache': [
    {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
    {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
  ]
}

New response:
{
  'cache': {
    'used_size': 4520232322423,
    'free_size': 48273465287452945,
    'images': [
      {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
      {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
    ]
  }
}

Parse the new "free_size" and "used_size" fields of each partition data in the response payload of /refresh

Parse "free_size" and "used_size" fields of the cache data in the reponse payload of /image/restore, /cache/delete and /cache/fetch

Replace "used_size" field of GET /client/setup with the value
of the new database field "used_size"
2024-09-25 12:09:32 +02:00
OpenGnSys Support Team ad31c3832d rest: remove scheduler code
Put ogserver into diet, remove this feature, including pending command queue.
2024-09-17 17:46:07 +02:00
Alejandro Sirgo Rica e3a73a504f rest: add GET /efi
Add GET /efi request to obtain information about the client's
boot entries.

Field inside the /refresh payload
'efi': {
  'entries': [
    {
      "order": 0,
      "name": "Boot0000",
      "active": false,
      "description": "grub"
    },
    {
      "order": 1,
      "name": "Boot0001",
      "active": true,
      "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller"
    }
  ]
}

If the client is not a EFI system it won't add the 'efi' field.
If an entry is not in the boot order it won't have the 'order' field.

GET /efi resquest payload structure:
{
    'clients': ['10.141.10.21', '10.141.10.22']
}

GET /efi response's structure:
{
  'clients': [
    {
      'ip': '10.141.10.21',
      'entries': [
        {
          "order": 0,
          "name": "Boot0000",
          "active": false,
          "description": "grub"
        },
        {
          "order": 1,
          "name": "Boot0001",
          "active": true,
          "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller"
        }
      ]
    },
    {
      'ip': '10.141.10.22',
      'entries': []
    }
  ]
}

The client with ip 10.141.10.22 is a BIOS system.

If an entry does not appear in the boot order it won't have the
'order' field.
2024-09-11 14:09:51 +02:00
Alejandro Sirgo Rica efb5f27585 client: store image cache data in database
Parse the 'cache' field of the refresh payload sent by the clients.

Cache field structure in the payload:
{
    ...
    'cache': [
        {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
        {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'},
    ]
    ...
}

Store that data in the 'cache' table of the  database so it can
be obtained later on.
The table contains the following fields:
- clientid: the numeric identifier of the client.
- imagename: name of the image in cache.
- size: size in bytes of the image in cache.
- checksum: checksum of the image in cache.
2024-05-30 11:16:13 +02:00
Jose M. Guisado 6f6372d0e0 src: move og_repository to dbi.h
Move struct og_repository to dbi.h and use field max length for name and
ip.

Use og_json_parse_string_copy instead of og_json_parse_string to check
maximum length against the request payload.

Fixes: 86ccc3c2e8 ("#915 Add POST /repository/add")
2023-10-10 18:09:19 +02:00
Jose M. Guisado 74b6e3ec72 rest: add optional param "backup" for create_image
This parameter is used by ogServer to instruct target client if image
backup should be performed before image creation.

This parameter is optional to preserve backward compatibility with
webconsole (legacy web client) and avoid the need of updating any legacy
client.

Default is true if the REST request is missing this parameter.
2023-07-07 10:04:36 +02:00
Javier Sánchez Parra 86ccc3c2e8 #915 Add POST /repository/add
This method adds a new repository to the database.

Request:
POST /repository/add
{
  "name": "Repository 1",
  "ip": "192.168.56.10"
}

Response:
200 OK
2022-07-01 12:09:16 +02:00
Jose M. Guisado e16f36cdef #915 Fix create image payload parsing
Commit 141b0797e1 introduced command scheduling rest api to
ogserver. Part of this changeset included
og_json_parse_create_image as a utility funtion to parse the json
payload of a "create image" command.

og_json_parse_create_image did not include the parsing of optional
parameters "description", "center_id" and "group_id". New components
like ogCP or ogCLI use these parameters.

Fix this by adding a struct og_image member to the struct og_msg_params
and assigning it when processing a "create image" command.

This could be extended to further payload parsing for image related
commands in the future.
2021-10-19 07:54:35 +00:00
Javier Sánchez Parra 7325a8629e #915 Add POST /task/add method
Adds the possibility to create a task with procedures and other tasks
integrated as steps.

Note: "steps" parameter is optional and "steps" array object order
defines execution order.

Request:
POST /task/add
{
  "center": "1",
  "name": "task",
  "description": "My task",
  "steps": [
             {
               "procedure": 4
             },
             {
               "task": 1
             },
             {
               "procedure": 24
             }
           ]
}

Response:
200 OK

This commit also add task case to procedure's step processing.
Otherwise, gcc prints the following warning:

src/rest.c: In function ‘og_procedure_add_steps’:
src/rest.c:4089:17: warning: enumeration value ‘OG_STEP_TASK’ not handled in switch [-Wswitch]
 4089 |                 switch (step->type) {
      |                 ^~~~~~
2021-07-01 09:20:46 +02:00
OpenGnSys Support Team 87774ab087 constify json parse helper function
json_t * parameter is not modified, constify to allow compiler to spew warnings
in case the function tries to modify it.
2021-06-10 17:05:07 +02:00
OpenGnSys Support Team 88c8b52e88 move json function declarations to json.h
These function declarations belong to json.h:

int og_json_parse_partition_setup(json_t *element, struct og_msg_params *params);
int og_json_parse_create_image(json_t *element, struct og_msg_params *params);
int og_json_parse_restore_image(json_t *element, struct og_msg_params *params);
2021-06-10 17:00:43 +02:00
Javier Sánchez Parra 1fdb7e6d1c #915 Add commands and procedures to procedure creation
Adds the possibility to create a procedure with commands and other
procedures integrated as steps.

Note: "steps" parameter is optional and "steps" array object order
defines execution order.

Request:
POST /procedure/add
{
  "center": "1",
  "name": "procedure",
  "description": "My procedure",
  "steps": [
             {
               "command": "wol",
               "params": { "type": "broadcast" }
             },
             {
               "procedure": 22
             },
             {
               "command": "poweroff",
               "params": {}
             }
           ]
}

Response:
200 OK

This commit also updates unit tests for /procedure/add POST method to
include steps.
2021-06-10 17:00:01 +02:00
Jose M. Guisado 141b0797e1 #915 Add schedule/command
Enables ogserver to schedule commands (also referred as actions in
legacy web console jargon).

This feature enables ogserver to write in the "acciones" table in order
to have full capabilities for command scheduling purposes, thus not
depending in the legacy web console to insert into "acciones" table.
2021-06-09 13:41:28 +02:00
Javier Sánchez Parra 12d8fff3ef #1037 Add disk type
Add ogServer support for parsing and storing in the DB disk type data
from ogClient refresh response.

See also commits with #1037 in ogClient and WebConsole repo.
2021-05-26 17:19:30 +02:00
Jose M. Guisado 0212091e7f #915 Add /center/add POST method
Adds POST method to add centers (organizational unit), required payload
parameter is the name, and an additional comment is optional.

	{"name": "ACME"}

	{"name": "ACME", "comment": "Some comment"}
2021-04-08 11:12:23 +02:00
Javier Sánchez Parra 24e6fbf1de #1008 Restore support for 4 disks and 16 partitions
ogServer expects to receive information of 1 disk and 4 partitions
from ogClient. Previous ogServer versions support several disks and
partitions.

Add ogServer support for 4 disks and 16 partitions.
2020-11-18 13:10:34 +01:00
Roberto Hueso Gómez 27fbc65829 #941 Add og_json_parse_string_copy(...) function
This function provides an easy way to copy the content of a json string
into a regular C string.
2020-10-06 16:04:14 +02:00
Javier Sánchez Parra 0efc182c9b #1004 Handle new fields in /image/create response
ogClient now includes more information regarding the new image. This patch
modifies ogServer to support new elements sent in ogClient /image/create
response and store them in the database.

Example of new /image/create response:

{
  "disk": "1",
  "partition": "1",
  "code": "131",
  "id": "1",
  "name": "ubuntu",
  "repository": "192.168.56.10",
  "software": "Ubuntu 18.04.5 LTS \naccountsservice 0.6.45\n...",
  "clonator": "PARTCLONE",
  "compressor": "LZOP",
  "filesystem": "EXTFS",
  "datasize": 2100000
}

New fields are "clonator", "compressor", "filesystem" and "datasize".
2020-09-10 14:48:26 +02:00
Roberto Hueso Gómez 33b0c6f694 Add POST /modes REST request
This patch implements HTTP POST /modes request which can change the mode of any
particular scope.

Request: POST /modes
{
  "scope": {"id": 1,
            "type": "computer"},
  "mode": "pxe"
}
Response: 200 OK
2020-07-06 17:27:33 +02:00
Javier Sánchez Parra 06af0c26f4 #990 Use client broadcast address on WoL
Some universities have computers in a different subnet where the
ogServer is, but ogServer WoL functionality only supported to send
packet to its own subnets. This commit solves this.

Now ogServer sends two WoL packets per client, one with the broadcast
address of the interface indicated in the config file, the other with
the broadcast address calculated with the address and netmask of the
client.

To ensure that the second WoL works correctly you must configure
correctly the IP and netmask of the clients. Also, you have to configure
the network of your organization to route WoL packet to the correct
subnet.
2020-07-03 14:11:35 +02:00
OpenGnSys Support Team 37e91b2ebb #971 rename sources folder to src
Use the same folder as in ogClient.
2020-06-26 20:13:42 +02:00