Commit Graph

104 Commits (488518c625ef0a750d416ceb0634211b3119ba14)
 

Author SHA1 Message Date
OpenGnSys Support Team 488518c625 disk: use NTFS for partition code
ogclient supports NTFS partition code.
2024-08-06 12:01:06 +02:00
Alejandro Sirgo Rica 740b2eab60 utils: place dictionary and list at the end of the json tree
Place dictionaries and lists at the end of the payload to improve
readability when it has a lot of nested components.

Remove and add again every element of type list or dict within a
dict or list in the payload.
Python dictionaries preserve insertion order from 3.7 onwardsi so
it is safe to reorder them by removing and readding an element.
2024-07-09 16:48:29 +02:00
Alejandro Sirgo Rica 6f9da3fdbb objects: fix restore image default repo value
Obtain the image's repository from the API REST.
Don't send 127.0.0.1 as image server when --repo is not defined.
2024-07-04 16:14:20 +02:00
OpenGnSys Support Team f53a60129b images: update command requires string id in server
ogserver expects a string as an id, otherwise it fails to parse it.
2024-06-17 12:35:01 +02:00
Alejandro Sirgo Rica 1fadb06b7e cli: objects: unbreak ogcli with python 3.8
Older versions of Python can't handle interleaved quote types.
Use single quotes as external string delimiter and double quotes
in every part of the strings when quotation is needed.
2024-06-03 21:33:53 +02:00
Alejandro Sirgo Rica 29ab6cc0ed disk: improve disk setup command validation
Checks:
--type is gpt or dos.
--num must have numeric argument.
--part defines 4 coma-separated values.
--part number must be an integer.
--part number is not repeated between partitions.
--part partition type is a known type.
--part filesystem type is a known type.
--part size has a valid format.
2024-06-03 15:51:58 +02:00
Alejandro Sirgo Rica 7ff45e5fcc disk: use proper partition sizes
Use base 2 size units for the partition configuration units.
Using base 10 units causes incoherency with the web.
2024-06-03 15:43:47 +02:00
Alejandro Sirgo Rica 10d7b972ca cli: add list scopes --client-ip
Implement a --client-ip filter to ease the task of finding the
hierarchy associated to a client or list of clients.

Usage:
/ogcli list scopes --client-ip 10.141.10.23

/ogcli list scopes --client-ip 10.141.10.23 --client-ip 10.141.10.22
2024-06-03 12:46:28 +02:00
Alejandro Sirgo Rica e92e38bcca remove whitespace printed after every command execution
The POST handling logic didn't check for empty responses before
printing its contents resulting in a line of whitespace being
written in the output of the program.
2024-03-04 10:43:26 +01:00
Alejandro Sirgo Rica f26a8c3d23 improve missing clients error reporting in multiple commands
All the commands that need target clients now have a more descriptive
error message when the clients of the command are missing.
2024-03-04 10:14:37 +01:00
Alejandro Sirgo Rica 9a11fd8346 rename argument of 'restore' command to 'restore_obj'
The argument was called 'send_obj' probably due to copypaste.
The rename aims to provide a better name for the command.
2024-03-04 10:01:03 +01:00
Alejandro Sirgo Rica b242ee9f6e change 'ogcli send' command into 'ogcli request'
By using the word 'request' the command becomes more semantic and
represents the 'best effort' nature of the communication with
ogserver.
2024-03-04 09:58:41 +01:00
Alejandro Sirgo Rica 9f78cc5ace add 'send session' to request the boot from a client's partition
example to boot OS from 10.141.10.22 disk 1 partition 2

	send session --client-ip 10.141.10.22 --disk 1 --part 2
2024-02-29 12:33:59 +01:00
Alejandro Sirgo Rica 48f596436c remove duplicated parse_args in repo.py and server.py
Remove the line 'parsed_args = parser.parse_args(args)' parsing the
command line arguments a second time when it is not needed.
2024-02-29 11:26:10 +01:00
Alejandro Sirgo Rica 9be4de87b7 ogcli: add update command for folder, room and center
Expand of the update command to be able to modify the values of
previous folder, room and center configurations.
2024-02-13 12:13:00 +01:00
Alejandro Sirgo Rica 499272fa29 repository: improve .gitignore syntax
the __pycache__ folder will now be ignored by git in every folder.
2024-02-13 12:12:43 +01:00
Alejandro Sirgo Rica 569b0107c1 ogcli: validate integer type in every --id argument
missing validation of --id, user needs to supply an integer
2024-02-05 13:29:57 +01:00
Alejandro Sirgo Rica 4881610656 folder: add commands to create and delete folders
add command to add folders

	add folder --name test --room-id 123

to delete

	delete folder --id 456

you can fetch the id with 'list scopes'
2024-02-05 12:58:52 +01:00
Javier Hernandez 642b0a49d4 room: use room_id field in json
instead of group, which is not used by the ogserver anymore.
2024-01-11 17:41:17 +01:00
OpenGnSys Support Team 31849a776c ogcli: really ignore SIGPIPE
SIG_DFL needs to be used to disable SIGPIPE in python, SIG_IGN does not work.
2024-01-04 11:59:06 +01:00
OpenGnSys Support Team c1aae6e35e src: update copyright statement
use opengnsys@soleta.eu email instead of info@soleta.eu
2024-01-02 14:00:53 +01:00
OpenGnSys Support Team 020592d6fc live: add command to list available live images
Add new command to display the available live images:

 # ogcli list live
2024-01-02 13:52:36 +01:00
OpenGnSys Support Team 76b4492fe6 cli: remove 'list server'
list servers already provides the same.
2024-01-02 13:38:36 +01:00
Javier Hernandez 717a1021d3 images: Remove option to specify repo
Remove option to specify a repository when creating an image.

Remove option to specify a repository when updating an image.

These features is are not yet supported in ogserver.

With this commit, the image that is created/updated is assigned to the
same repo the client is assigned
2023-12-21 16:58:50 +01:00
OpenGnSys Support Team cf4af2a057 images: use new POST image/update
use POST image/update when updating an image.
2023-12-19 12:49:03 +01:00
OpenGnSys Support Team 27f632e3ed repository: fix incorrect help
# ogcli delete repo -h
 [...]
     --id [ID]   room id in scopes

this is not the room id, it should be the repo id.
2023-12-01 10:38:40 +01:00
OpenGnSys Support Team 6b4a7a64ee repository: delete command
Allow to delete a repository with:

 $ ogcli delete repo --id 10
2023-11-30 22:22:45 +01:00
OpenGnSys Support Team 4286c45877 client: remove --netmask
This set from the room --netmask, this is obsolete, remove it.
2023-11-30 22:22:45 +01:00
OpenGnSys Support Team b91ab6ef78 ogcli: add SIGINT handler
if user presses ctrl-c, interrupt ongoing operation to avoid python backtrace.
2023-11-30 22:22:42 +01:00
OpenGnSys Support Team da8f8e8009 client: support for deleting clients
Delete a client with command:

 $ ogcli delete client --ip 1.2.3.4
2023-11-30 22:03:51 +01:00
OpenGnSys Support Team 09cb99b057 ogcli: ignore SIGPIPE
# ogcli list scope | less
 ... leave it open for one minute, then press 'q' to exit less

 it shows:

Traceback (most recent call last):
  File "/usr/bin/ogcli", line 60, in <module>
    CLI()
  File "/usr/bin/ogcli", line 56, in __init__
    getattr(self.ogcli, args.command)(sys.argv[2:])
  File "/opt/opengnsys/bin/cli/cli.py", line 93, in list
    OgScope.list_scopes(self.rest)
  File "/opt/opengnsys/bin/cli/objects/scopes.py", line 18, in list_scopes
    print_json(r.text)
  File "/opt/opengnsys/bin/cli/utils.py", line 34, in print_json
    print(json.dumps(payload, sort_keys=True, indent=2))
BrokenPipeError: [Errno 32] Broken pipe

It seems that the request library in python leaves the socket open
while it still displays the listing.

Ignore SIGPIPE which reports that socket is not there anymore, it is
a common practise to ignore this signal in socket.
2023-11-03 10:40:00 +01:00
Javier Hernandez 4bf4f91f54 client: support for adding clients
Add a new client with command:

$ ogcli add client --repo-id <repo id>
      --netmask <netmask>
      --room-id <room id>
      --hostname <hostname>
      --mac <mac address>
      --ip <ip address>
      --boot-mode <boot mode>

For example: To add a new client with hostname "javipc", netmask
255.255.255.0, mac address a2:54:00:2e:05:7a, ip address 192.168.56.101,
assign it to repo id 1, room id 1 and set its boot mode to oglive
use:

$ ogcli add client --hostname javipc --netmask 255.255.255.0 --mac
a2:54:00:2e:05:7a --ip 192.168.56.101 --repo-id 1 --room-id 1
--boot-mode oglive

Notes:

- ogserver API REST json payload does not allow to specify a server
  (table 'entorno') for the client. It will automatically assign
  client to server with id 1

- ogserver API REST json payload specifies mac address without ':'.

- payload must contain 'netiface', ogcli specifies 'eth0' is specified
  which is the default value in netiface column in db (table 'ordenadores')

- netdriver column uses "generic" as default, this field is not used
  anymore, but it is set to "generic" by now.

- ogserver should validate that boot mode set is correct.
2023-10-27 11:57:25 +02:00
Jose M. Guisado 37c4065f06 cli: objects: use --desc and --folder
Try to reduce the usage of different parameter names due to the
OpenGnsys database using different column names for similar purposes.

Any database field regarding a description of some sort will use the
parameter --desc, even if the DB uses another column name (for example,
comment column in center table).

Use --folder parameter when requiring a folder id. The database uses
"grupo" as table name but present this to the user as folder, so use
--folder instead of --group.

Also, add 'location' field in the payload of "add room" command, it was
missing the addition of 'location' field in the JSON payload.
2023-10-19 13:36:00 +02:00
Javier Hernandez 1c2e5c4c96 cli: add room
add functionality to add and remove a room

to add a new room use the command: ogcli add room --name <name>
--netmask <netmask> --center <center> --gateway <gateway> [--location
<location>] [--ntp <ntp>] [--dns <dns>] [--group <group>]

for instance, to create a room with name 'dummyroom', netmask
'255.255.255.0' and gateway 10.141.10.1 that is inside the center with
id 1, use:

$ ogcli add room --name dummyroom --netmask 255.255.255.0 --gateway
10.141.10.1 --center 1

Optionally, it is possible to provide additional information such as
location (--location <location>), ntp server (--ntp <ntp>), dns server
(--dns <dns>), and a group to contain the room (--group <group>).

to delete a room use: ogcli delete room --id <id>

for instance, to delete room with id 4 use:

$ ogcli delete room --id 4
2023-10-19 12:26:31 +02:00
Jose M. Guisado 7c30d56910 cli: fix messages when receiving an error response
ogCLI displays a message like "Cannot connect to ogServer: [...]" when
ogServer replies with something different from 2XX.

Fix these strings because ogServer is actually connected and replying to
an ogCLI request.
2023-10-18 10:41:26 +02:00
Javier Hernandez 181075e505 center: add delete command
command to delete center
ogcli delete center --id <center id>

To delete the center with id 6

$ ogcli delete center --id 6
2023-10-18 09:29:38 +02:00
Javier Hernandez 8be21d4ac5 cli: add center.py
command to add center, specifying name and optionally a description
ogcli add center --name <name> [--comment <name>]

For example, to add a center with name "foocenter" and comment "foocenter description" type

$ ogcli add center --name foocenter --comment "foocenter description"
2023-10-18 09:29:38 +02:00
Jose M. Guisado e7c2ad0ee1 images: change --repo help message 2023-10-12 09:48:15 +02:00
Jose M. Guisado a4bf35ef28 repo: add add_repo function
User can add a new repository to the database using "ogcli add repo":

$ ogcli add repo --name ogcli --address 10.10.10.10
{
    "center": 1,
    "id": 13,
    "ip": "10.10.10.10",
    "name": "ogcli"
}

The --center optional parameter is used to set the center column of
"repositorios" table in the database to the specified value. If this
parameter is missing ogServer API will default to center with id 1 (the
default center). This is to not break the repository in the legacy
webconsole users.
2023-10-11 17:50:47 +02:00
Jose M. Guisado 4e89fe44d0 cli: add repo.py object
A user can list repos using "ogcli list repos":

$ ogcli list repos
{
    "repositories": [
        {
            "id": 1,
            "ip": "10.141.10.1",
            "name": "Repositorio (Default)"
        },
        {
            "id": 3,
            "ip": "127.0.0.1",
            "name": "dummy"
        },
        {
            "id": 4,
            "ip": "192.168.21.21",
            "name": "helloworld"
        }
    ]
}

The repository of a client or group of clients in a room is configured
using "ogcli set repo --id <id> [--client-ip <ip address>, --room-id
<room id>]:

$ ogcli set repo --id 4 --room-id 1
2023-10-11 17:29:49 +02:00
Jose M. Guisado 68a9d6fe8f disks: remove --format parameter in setup disk
Every partition will be formatted since disk setup command was rewritten
into Python code in ogClient. This makes "ogcli setup disk" --format
parameter unusable.

As the time of this commit, for backward compatibility (with the legacy
web console interface) ogServer expects the "format" field inside the
partition json objects conforming the "partition_setup" array. For this
reason, ogCLI still adds the "format" field into the partition objects
present in the partition_setup array, but using a default value which
will have no effect whatsoever.
2023-10-09 12:45:07 +02:00
Jose M. Guisado d259629445 cli: better error handling for subcommand args
Some subcommands need following arguments (e.g.: ogcli list ...), check
if following arguments are present. If no required following argument is
detected then print an error message, show help and exit with status
code 1.
2023-10-06 11:30:43 +02:00
Jose M. Guisado 35b4b1422a cli: fix help message typos in some subcommands
For the delete subcommand: s/remove/delete

For the add subcommand: s/remove/add
2023-10-06 10:56:25 +02:00
Jose M. Guisado c224c596f4 ogcli: improve handling of subcommand errors
If no subcommand or an invalid one is specified print an error message
followed by ogcli --help. Also exit with status code 1.
2023-10-06 10:49:10 +02:00
Jose M. Guisado b1fc9cabb4 objects: add missing prog parameter in subcommands
The specific subcommand name is missing in some of the subcommands help
message. For example:

	$ ogcli list hardware
	usage: ogcli [-h] --client-ip CLIENT_IP
	ogcli: error: the following arguments are required: --client-ip

Fix this by adding the missing prog= parameter so argparse use this
instead of argv[0]. If no prog parameter is specified then argv[0] is
printed (i.e: "ogcli").
2023-10-05 11:21:19 +02:00
Jose M. Guisado a721957cc4 cli: add server commands
Add OgServer class inside cli/objects/server.py

This OgServer class implements add, list, set and delete commands
related to the server API (/server and /client/server) exposed by the
ogServer. These server endpoints correspond with the "entornos" table and
"identorno" foreign key in the "ordenadores" tables.

To list all rows from the "entornos" table. i.e: Listing all stored
addresses for the ogServer:

	ogcli list servers

	{
	  "servers": [
	    {
	      "address": "192.168.2.240",
	      "id": 1
	    },
	    {
	      "address": "1.1.1.1",
	      "id": 2
	    }
	  ]
	}

To store a new ip address for the ogServer, ogCLI will reply with the
new id:

	ogcli add server --address "10.141.10.1"

	{"id", "2"}

To set a client's associated ogServer address using the server id:

	ogcli set server --id 2 --client-ip 10.141.10.100

To set the associated server of a whole room use --room-id parameter:

	ogcli set server --id 2 --room-id 1

To remove any existing address (which is not currently set as the
ogServer addres for any client) using the server id:

	ogcli delete server --id 2

To determine a client's associated server just list the client's
information (this requires an updated ogServer):

	ogcli list client --client-ip 10.141.10.100

	{
	  "boot": "oglive",
	  "center": 1,
	  ...
	  "server_id": 1
	}
2023-08-24 09:14:49 +02:00
Jose M. Guisado 563e30893d cli: add delete http method
Add delete function to OgRest class. Enable ogCLI to send HTTP
requests using DELETE as request verb.

Encapsulates requests python module .delete() method.
2023-08-24 09:14:36 +02:00
Jose M. Guisado 82e8880841 update image: add optional --backup parameter
Add support for backup image file when running the image update command.

For this optional parameter to be useful, the target ogServer
and ogClient must also support the 'backup' parameter. See commits:

ogServer 74b6e3ec7275164e2ecbf6f98b24357b2a9bb174
ogClient 035995fc8c55740693575ca5f7b408bfc46c1f7d
2023-07-20 12:05:45 +02:00
Jose M. Guisado 5e546fbee2 examples: add examples folder
deploy-ubuntu.sh is a simple bash script combining multiple ogcli
commands used to format and deploy some image.

poweroff.cron is a sample cron file used to schedule client
poweroff.
2022-11-13 18:49:59 +01:00
Jose M. Guisado dff298d421 create image: split into create and update
Image creation example:

	ogcli create image
		--disk
		--part 1
		--name 18oct2
		--desc 18oct2
		--repo-id 1
		--client-ip 192.168.56.11

Image update example:

	ogcli update image
		--disk 1
		--part 1
		--id 20
		--client-ip 192.168.56.11
2022-10-20 12:25:10 +02:00