Commit Graph

434 Commits (2d68f8a0ec04b1f7700dce6bc0635c3bce516453)
 

Author SHA1 Message Date
Roberto Hueso Gómez 7f5ab4ac35 #942 Add GET /session REST API function
This function returns the installed and available OSs in a client to be
booted from.

Request:
GET /session
{
  "client": ["192.168.56.11"]
}

Response
200 OK
{
  "sessions": [
    {
      "disk": 1,
      "name": "Ubuntu 18.04.4 LTS",
      "partition": 1
    }
  ]
}
2020-10-20 15:34:15 +02:00
Roberto Hueso Gómez 2958d23db2 #942 Use client's IP as filter in GET /hardware
This patch uses client's IP instead of scope ID as a filter for the
request.

Request:
GET /hardware
{
  "client": ["192.168.56.11"]
}

Response:
200 OK
{
  "hardware": [
    {
      "description": "BIOS",
      "type": "Tipo de proceso de arranque"
    },
    {
      "description": "QEMU Standard PC (i440FX + PIIX, 1996)  v.pc-i440fx-5.1",
      "type": "Marca y modelo del equipo"
    },
    {
      "description": "Intel Corp. Intel Core Processor (Haswell, no TSX, IBRS) 2GHz v.pc-i440fx-5.1",
      "type": "Microprocesadores"
    },
    {
      "description": "QEMU  2049MiB  (DIMM 0)",
      "type": "Memorias"
    },
    {
      "description": "Red Hat, Inc. Virtio network device  v.00",
      "type": "Tarjetas de Red"
    }
  ]
}
2020-10-20 13:44:44 +02:00
Roberto Hueso Gómez 25c1c16e99 #942 Add GET /software REST API function
This function retrieves a list of the software installed in a specific
disk and partition of a client. This list can be updated by using POST
/software beforehand.

Request:
GET /software
{
  "client": ["192.168.56.11"],
  "disk": 1,
  "partition": 1
}

Response:
200 OK
{
  "software": [
    "grub-pc-bin 2",
    "grub-pc 2.02",
    "grub2-common 2.02",
    "groff-base 1.22.3",
    "gpg 2.2.4",
    "gnupg-utils 2.2.4",
    "gnupg-l10n 2.2.4",
    "gnupg 2.2.4",
    "gnome-video-effects 0.4.3",
    "gnome-user-guide 3.28.2+git20180715",
    "gnome-user-docs 3.28.2+git20180715",
    "gnome-todo-common 3.28.1",
    "gnome-mines 3.28.0",
    "gnome-menus 3.13.3",
    "gnome-mahjongg 3.22.0",
    "gnome-keyring-pkcs11 3.28.0.2",
    "gnome-keyring 3.28.0.2",
    "gnome-initial-setup 3.28.0",
    "accountsservice 0.6.45"
  ]
}
2020-10-16 14:40:33 +02:00
Roberto Hueso Gómez d8b78bb922 #942 Extend GET /images function
This extension removes replaces the field 'filename' for 'name' and adds
new fields (software_id, type and id). These new fields are useful when
restoring an image.

Request:
GET /images

Response:
200 OK
{
  "disk": {
    "free": 37091418112,
    "total": 52573995008
  },
  "images": [
    {
      "datasize": 5939200000,
      "id": 25,
      "modified": "Wed Oct 14 11:49:00 2020",
      "name": "archlinux",
      "permissions": "744",
      "size": 1844222333,
      "software_id": 19,
      "type": 1
    }
  ]
}
2020-10-14 17:31:43 +02:00
Roberto Hueso Gómez d2f20d0be0 #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
2020-10-14 12:05:25 +02:00
Roberto Hueso Gómez 24c8b940e6 Add REST POST /client/delete method
This method deletes a client from the DB.

Request:
POST /client/delete
{
  "clients": ["192.168.56.30"]
}

Response:
200 OK

Co-authored-by: Javier Sánchez Parra <jsanchez@soleta.eu>
2020-10-08 12:56:32 +02:00
Roberto Hueso Gómez 068c0f2794 #915 Use string for tests config port
This adapts the test configuration to the changes made in the commit
fe1ce97c50
2020-10-07 16:56:26 +02:00
Roberto Hueso Gómez 4a06c7a391 #915 Update run-tests.py to the latest changes
This handles changes in:
- The host of the DB.
- New json config file.
2020-10-07 14:05:56 +02:00
Roberto Hueso Gómez 5b1efd0b53 #915 Add default SQL schema for tests
This schema is now adapted to work on this repository instead of the
"OpenGnsys" general repository.
2020-10-07 14:05:02 +02:00
OpenGnSys Support Team 35f067bf90 #971 remove unused contieneIP function in ogAdmLib 2020-10-07 11:18:37 +02:00
OpenGnSys Support Team fe1ce97c50 #988 remove legacy configuration
Use og_server_cfg everywhere. Convert port to string to make it easy for the
dbi API since it expects a string. Remove legacy example configuration file.
2020-10-07 11:17:00 +02:00
OpenGnSys Support Team 3cea4bb763 #988 rename og_server_cfg to cfg
to avoid clash with existing variable cfg in client.c
2020-10-07 11:11:04 +02:00
Roberto Hueso Gómez d7a871b529 #988 Update ogserver.service to use json config file
This is convenient for the ogServer to use the new config file.
2020-10-06 16:04:17 +02:00
Roberto Hueso Gómez f537dafa77 #941 Use fixed length strings in og_computer and og_dbi_get_computer_info
This patch is a refactor for og_computer and og_dbi_get_computer_info.
It now uses fixed lenght strings to make it more reliable and avoid
errors if the DB is not returning a null ended string.
2020-10-06 16:04:17 +02: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
OpenGnSys Support Team d89d6c6ce7 #1004 set default path to repository
This is /opt/opengnsys/images if not specified.
2020-10-06 13:01:54 +02:00
OpenGnSys Support Team 7500700777 #988 remove legacy configuration file
Add getopt parser and use json configuration file instead.
2020-10-05 14:49:17 +02:00
Javier Sánchez Parra a67f27a092 #1004 Fix integer overflow in datasize
ogClient datasize is now in bytes, update format to fix a possible overflow.
2020-09-29 12:43:07 +02:00
Javier Sánchez Parra 403e7c323b #1004 Add GET /images
This commit adds GET /images to the ogServer REST API.

This call returns information of all the images in ogServer.

Example response:

{
  "images": [
    {
      "filename": "ubuntu.img",
      "datasize": 2150400000,
      "size": 613476223,
      "modified": "Wed Sep 23 10:37:36 2020",
      "permissions": "744"
    },
    {
      "filename": "test.img",
      "datasize": 2150400000,
      "size": 613236475,
      "modified": "Tue Sep 29 08:57:47 2020",
      "permissions": "744"
    }
  ],
  "disk": {
    "total": 52573995008,
    "free": 39624544256
  }
}
2020-09-29 12:43:07 +02:00
Javier Sánchez Parra f068a79c1a #988 Add global config variable
This commit makes configuration variable global.

To use this variable you have to #import "cfg.h".
2020-09-29 12:42:53 +02:00
Roberto Hueso Gómez 65a14e56d3 #942 Add POST /client/add HTTP REST method
This method adds a new client. This new client's IP cannot be duplicated
in the DB.

Request:
POST /client/add
{
  "boot": "19pxeADMIN",
  "center": 0,
  "hardware_id": 0,
  "id": 2,
  "ip": "192.168.56.12",
  "livedir": "ogLive",
  "mac": "0800270E6512",
  "maintenance": true,
  "name": "pc12",
  "netdriver": "generic",
  "netiface": "eth1",
  "netmask": "255.255.255.0",
  "remote": false,
  "repo_id": 1,
  "room": 1,
  "serial_number": ""
}

Response:
200 OK
2020-09-24 17:03:56 +02:00
OpenGnSys Support Team bdd8519d03 #988 use-after-free in json configuration parser
The cfg structure stores pointers to the string in this json tree. Do not
release the json tree, keep it as field in the cfg structure.
2020-09-22 15:24:43 +02:00
Roberto Hueso Gómez af47a082ad #1004 Add GET /client/info HTTP REST method
This method provides information about a specific client. The request
must contain exactly 1 client's IP.

Request:
GET /client/info
{"client": ["192.168.56.12"]}

Response:
200 OK
{
  "boot": "19pxeADMIN",
  "center": 0,
  "hardware_id": 0,
  "id": 2,
  "ip": "192.168.56.12",
  "livedir": "ogLive",
  "mac": "0800280E6871",
  "maintenance": true,
  "name": "pc12",
  "netdriver": "generic",
  "netiface": "eth1",
  "netmask": "255.255.255.0",
  "remote": false,
  "repo_id": 1,
  "room": 1,
  "serial_number": ""
}
2020-09-22 15:24:38 +02:00
Roberto Hueso Gómez cbd9421bae #941 Extend og_dbi_get_computer_info(...)
For the strings in og_computer we do not need to know the max size in
advance but instead we need to free up memmory using
og_dbi_free_computer_info(...) function.
2020-09-22 15:20:57 +02:00
OpenGnSys Support Team d7e2022bdd #941 pass og_dbi to og_dbi_get_computer_info()
Reuse the existing dbi handler, instead of opening a new one.
2020-09-18 15:38:16 +02:00
OpenGnSys Support Team 3cb98c7187 #941 move og_dbi_get_computer_info() to dbi
Move this function to the dbi.{h,c} files.
2020-09-18 15:34:30 +02:00
OpenGnSys Support Team 540cfb597f #988 fix compilation warning in json configuration file to legacy
src/cfg.c: In function ‘from_json_to_legacy’:
src/cfg.c:161:2: warning: format not a string literal and no format arguments [-Wformat-security]
2020-09-15 20:16:12 +02:00
Roberto Hueso Gómez ff71a2ad6e Fix size of og_cmd_get_client_setup() return array
The return array needs to store 1 extra element for the disk setup.
2020-09-15 15:00:17 +02:00
Roberto Hueso Gómez b59ff7c604 #1004 Add GET /client/setup HTTP REST method
This method provides the partitions setup for a specific client. The
request must contain exactly 1 client's IP.

Request:
GET /client/setup
{'client': ['192.168.56.12']}

Response:
200 OK
{
  "partitions": [
    {
      "disk": 1,
      "partition": 0,
      "code": 0,
      "size": 20971520,
      "used_size": 0,
      "filesystem": 0,
      "os": 0,
      "image": 0,
      "software": 0
    }
  ]
}
2020-09-14 12:13:06 +02:00
OpenGnSys Support Team 280e23f8ee #971 replace reservaMemoria() by calloc()
reservaMemoria() is only used once, remove it.
2020-09-10 16:24:18 +02:00
OpenGnSys Support Team 7dbe1a73a0 #971 remove unused functions in ogAdmLib
Remove unused legacy code.
2020-09-10 16:20:02 +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
OpenGnSys Support Team a1aaad46fb #980 do not report busy client if probing is pending
og_client_status() should not report busy when probing is going on.
2020-08-21 18:10:39 +02:00
Roberto Hueso Gómez 91c3a285ba #980 Add 'ip' field in GET /scopes request
The 'ip' field is added to the json for scopes that have an IP (i.e.
computers).
2020-08-14 12:55:18 +02:00
Roberto Hueso Gómez 4ae9903dc3 #980 Select POST /mode clients by ip instead of scope name
This patch selects clients whose modes need to be changed in the current
request. This patch makes POST /mode consistent with the rest of the
REST API where clients are selected and filtered by ip.
2020-08-14 12:50:24 +02:00
OpenGnSys Support Team ca545d39bd #998 disable incremental image API
This API is not supported by ogClient yet and it uses the obsolete socket hydra API.
2020-08-14 12:48:21 +02:00
OpenGnSys Support Team 060e31cb53 #990 add wol_socket_open()
Add wol_socket_open() to initialize the WoL socket
2020-08-06 13:39:46 +02:00
OpenGnSys Support Team 1855b68af3 #980 fix compile warning in og_set_client_mode
CC       src/rest.o
src/rest.c: In function ‘og_cmd_post_modes.isra.27’:
src/rest.c:966:4: warning: ‘%s’ directive output may be truncated writing up to 4096 bytes into a region of size between 3018 and 4041 -Wformat-truncation=]
    "MODE_FILE='%s'\nMAC='%s'\nDATA='%s'\n"
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/rest.c:1085:7:
       template_name, scope_name);
       ~~~~~~~~~~~~~
src/rest.c:967:33: note: format string is defined here
    "MODE='PERM'\nTEMPLATE_NAME='%s'",
                                 ^~
src/rest.c:965:2: note: ‘snprintf’ output 57 or more bytes (assuming 5176) into a destination of size 4096
  snprintf(cmd_params, sizeof(cmd_params),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    "MODE_FILE='%s'\nMAC='%s'\nDATA='%s'\n"
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    "MODE='PERM'\nTEMPLATE_NAME='%s'",
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mode, mac, params, template_name);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-08-06 10:45:03 +02:00
OpenGnSys Support Team 5286c93d69 #980 error reporting in setclientmode
Add syslog and use exit()
2020-08-06 10:36:44 +02:00
Irina Gomez 139633a334 #986 Fixs error in 'Advanced Netboot' caused by loss information from ogserver process owner (author Roberto Hueso Gómez). 2020-08-05 14:21:16 +02:00
Roberto Hueso Gómez b8a509b1dd #980 Change GET and POST /modes URI to /mode
This patch changes the URI since it is semantically more correct to use
the singular.
2020-08-03 13:14:44 +02:00
Roberto Hueso Gómez 532b0819c4 #980 Fix POST /modes to use 'setclientmode' script
Now POST /modes does not only write to the database, it also uses the
external bash script 'setclientmode' to generate configured PXE
templates for each machine.

NOTE: This fix requires that room and computer names are unique in the
OpenGnsys DB. This behaviour is inherited from the previous
'setclientmode' script but, eventually, it should be replaced for an
actual scope selector.
2020-07-29 20:17:34 +02:00
Roberto Hueso Gómez a8e5b844c5 #988 Check DB port size is in [0, UINT16_MAX]
Max port number is UINT16_MAX, so this checks whether this config
parameter is in the correct range.
2020-07-15 12:47:45 +02:00
Roberto Hueso Gómez 0631b0e8e6 #988 Add DB port option to ogserver.json config file
This patch provides functionality to select a database port. It also adds a
default IP for the database.
2020-07-10 16:21:58 +02:00
Roberto Hueso Gómez a8eccba706 Add GET /hardware REST request
This patch implements HTTP GET /hardware request which returns a list of
the hardware associated with a particular computer.

Request: GET /hardware
{
  "scope": {
    "id": 6,
    "type": "computer"
  }
}

Response: 200 OK
{
  "hardware": [
    {
      "type": "Microprocesadores",
      "description": "CPU arch:x86 target:x86_64 cores:4"
    },
    {
      "type": "Memorias",
      "description": "QEMU 4096MiB"
    },
    {
      "type": "Tarjetas gráficas",
      "description": "Red Hat, Inc Virtio GPU"
    },
    {
      "type": "Tarjetas de Red",
      "description": "Intel Corporation 82540EM Gigabit Ethernet Controller
                      QEMU Virtual Machine"
    },
    {
      "type": "Controladores IDE",
      "description": "Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
                      Qemu virtual machine"
    }
  ]
}
2020-07-08 17:08:46 +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
OpenGnSys Support Team 96b02b5424 #971 split wake on lan code
Add wol.c and wol.h that implements WakeOnLan.
2020-07-06 11:14:43 +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 d6789f1384 #971 linkage error after split
/usr/bin/ld: src/cfg.o:/home/opengnsys/ogServer/src/ogAdmServer.h:25: multiple definition of `servidoradm'; src/ogAdmServer.o:/home/javi/trabajo/soleta/opengnsys/ogServer/src/ogAdmServer.h:25: first defined here
/usr/bin/ld: src/cfg.o:/home/opengnsys/ogServer/src/ogAdmServer.h:26: multiple definition of `puerto'; src/ogAdmServer.o:/home/javi/trabajo/soleta/opengnsys/ogServer/src/ogAdmServer.h:26: first defined here
/usr/bin/ld: src/cfg.o:/home/opengnsys/ogServer/src/ogAdmServer.h:35: multiple definition of `tbsockets'; src/ogAdmServer.o:/home/javi/trabajo/soleta/opengnsys/ogServer/src/ogAdmServer.h:35: first defined here
/usr/bin/ld: src/cfg.o:/home/opengnsys/ogServer/src/ogAdmLib.h:81: multiple definition of `ndebug'; src/ogAdmServer.o:/home/javi/trabajo/soleta/opengnsys/ogServer/src/ogAdmLib.h:81: first defined here
/usr/bin/ld: src/cfg.o:/home/opengnsys/ogServer/src/ogAdmLib.h:80: multiple definition of `szPathFileLog'; src/ogAdmServer.o:/home/javi/trabajo/soleta/opengnsys/ogServer/src/ogAdmLib.h:80: first defined here
/usr/bin/ld: src/cfg.o:/home/opengnsys/ogServer/src/ogAdmLib.h:80: multiple definition of `szPathFileCfg'; src/ogAdmServer.o:/home/javi/trabajo/soleta/opengnsys/ogServer/src/ogAdmLib.h:80: first defined here
2020-07-02 12:34:38 +02:00
Roberto Hueso Gómez f520a57f58 #980 Refactor GET /scopes backend
This improves style and fixes some memleaks.

Co-authored-by: OpenGnSys Support Team <soporte-og@soleta.eu>
2020-07-02 12:14:19 +02:00