Commit Graph

37 Commits (31849a776cd2303ba8320372cb167585f339d11d)

Author SHA1 Message Date
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
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 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
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
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 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 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 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 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
Jose M. Guisado 2f824d8429 send: add send reboot
Takes usual client options
(--client-ip, --room-id, --center-id)

Example:

> ogcli send reboot --client-ip 192.168.56.11
2022-05-25 10:56:14 +02:00
Jose M. Guisado d90ab82cec format: use autopep8
Use autopep8 for coding format, and only for whitespace changes. This
change drops use of tabs in favor of spaces.

Doesn't use autopep8 --aggresive option.

Format command:

$ autopep8 --inline --recursive .

When using git-blame, use --ignore-rev in order to ignore this
reformatting commit.
2022-05-20 10:22:42 +02:00
Jose M. Guisado 397663fd37 send: add send refresh
Send refresh to a given client.

$ ogcli send refresh --client-ip 192.168.56.11
2022-05-20 08:52:23 +02:00
OpenGnSys Support Team 5f922571e2 ogCLI is AGPLv3+
Update license header in files.
2021-05-14 00:26:33 +02:00
Javier Sánchez Parra a2f1056c40 Add alias "set mode"
"ogcli set modes ..." should be "ogcli set mode ..." because clients
only have one mode assigned at a time.

To not break the backwards compatibility, this commits adds "set mode"
but maintains "set modes".
2021-05-12 17:23:06 +02:00
Jose M. Guisado 01ed5a3039 Add "setup disk" command
Enables sending format and partition commands to the ogServer.

Syntax: ogcli setup disk {options}

Options are:

  --type [{dos,gpt}]    Disk partition scheme
  --num [NUM]           Disk number (defaults to 1)
  --format [FORMAT]     Indicates which partitions to reformat if they
                        are already present. Use --part alone to mean all
                        partitions.
  --part PART [PART ...]
                        Partition definition (syntax:
                        "num,part_scheme,fs,size")

	size is specified as a positive digit followed by a size unit
	like [MGT]

		512M, 50G, 1T, etc.

	ogcli accepts {LINUX,WINDOWS,EFI,CACHE} as part types and {EXT4,
	NTFS, FAT32, CACHE} as filesystem types inside the partition
	definition string

	1,LINUX,EXT4,50G => partition 1, of type linux with ext4 fs of
			    50 GB size

	If you wanted to add a partition cache (OpenGnsys usually
	mandates this partition to be number 4) you can omit partitions
	up to that number and ogcli will fill with EMPTY partitions.

	So if you define the following parts:
		--part 1,...
		--part 4,...
	ogcli will fill parts 2 and 3 with EMPTY part type and fs.

Client selection argument follow previous used options

  --center-id CENTER_ID
  --room-id ROOM_ID
  --client-ip CLIENT_IP
2021-04-07 12:58:54 +02:00
Jose M. Guisado 19e7d98aec Add 'send poweroff' command
Enables sending poweroff commands to clients.

Only arguments required are the usual client selection like:

	--client-ip
	--room-id
	--center-id
2021-04-06 13:16:46 +02:00
Jose M. Guisado a576aeaf1e Add 'create image'
Enables creation of images using /image/create from ogServer API.

Summary of the options:

	--disk
	Disk number

	--part
	Partition number

	--name
	Image name which will be used for the .img file.

	--desc
	Description of the image. This option enables ogServer to store
	an entry in the database regarding this image.

	--repo
	Optional. Holds the ip address of the repo which will store the
	created image. Defaults to ogserver address specified inside
	ogcli.json

	--client-ip
	Client ip for which we want to create a partition image
2021-04-06 13:16:46 +02:00
Jose M. Guisado 4dfb90cf56 Add 'list disks'
Enables consuming /client/setup API from ogServer in order to fetch
partition and disk setup information from a given client.

Example, if pc11 is a client with 1 disk, 4 part (1:linux,2-3:empty,4:cache):

ogcli list disk --client-ip 192.168.56.11

{
  "partitions": [
    {
      "disk": 1,
      "partition": 0,
      "code": 1,
      "size": 52428800,
      "used_size": 0,
      "filesystem": 0,
      "os": 0,
      "image": 0,
      "software": 0
    },
    {
      "disk": 1,
      "partition": 1,
      "code": 131,
      "size": 40000000,
      "used_size": 4,
      "filesystem": 6,
      "os": 8,
      "image": 0,
      "software": 0
    },
    {
      "disk": 1,
      "partition": 2,
      "code": 0,
      "size": 0,
      "used_size": 0,
      "filesystem": 1,
      "os": 0,
      "image": 0,
      "software": 0
    },
    {
      "disk": 1,
      "partition": 3,
      "code": 0,
      "size": 0,
      "used_size": 0,
      "filesystem": 1,
      "os": 0,
      "image": 0,
      "software": 0
    },
    {
      "disk": 1,
      "partition": 4,
      "code": 202,
      "size": 10000000,
      "used_size": 1,
      "filesystem": 2,
      "os": 0,
      "image": 0,
      "software": 0
    }
  ]
}
2021-04-06 13:16:46 +02:00
Jose M. Guisado 6fd3cb7a25 Add 'restore image' command
Adds cli capability to send image restore commands to the ogServer.

It has the following options:

	--id
	To specify image id

	--disk
	Target disk

	--part
	Target partition

	--type
	To specify type of restore to send. UNICAST-DIRECT or
	UNICAST-CACHE are supported as of this patch.

	--repo
	Optional argument to specify image repo to fetch the image. This
	applies for UNICAST-DIRECT cases. (not restoring from a cache
	partition). If not specified it will default to rest.URL ip
	(ie. ogServer ip)

	--client-ip, --room-id and --center-id
	Target client args
2021-03-30 14:01:39 +02:00
Jose M. Guisado 5abe862228 Add list images
ogServer exposes a list of known partition images at /images, use it to
implement 'list images' command.
2021-03-30 14:00:25 +02:00
Jose M. Guisado e81c38f098 Fix help messages
program name of subsequent parsers after the first one need their
"prog=" parameter specified so they do not show sys.argv[0] only.

With this patch, for example:

	ogcli list --help

Shows:

	usage: ogcli list [-h] {clients,scopes,modes,hardware,client}
	...

Instead of:

	usage: ogcli [-h] {clients,scopes,modes,hardware,client}
	...
2021-03-29 13:54:37 +02:00
Jose M. Guisado 0f55ce7341 Add WoL sending capability
Builds a json payload to consume the ogServer API to send
WoL packets.

Adds 'send' as a command:

	ogcli send

Adds a wol object for to the 'send' command, so that sending a wol can
be specified as:

	ogcli send wol

* WoL packet type is specified with --type option.
* Specifying targets follows same parameters as 'set modes' with:
	--client-ip
	--room-id
	--center-id
2021-03-29 13:47:28 +02:00
Roberto Hueso Gómez 513308fe81 Add ogcli list client command
This requests GET /client/properties by calling something like:
ogcli list client --id=6

It is important to notice that 'id' must be a "computer" type
scope id.
2020-07-14 11:21:16 +02:00
Roberto Hueso Gómez f4e1bb767b Add ogcli list hardware command
This requests GET /hardware by calling something like:
ogcli list hardware --scope-id=6

It is important to notice that 'scope-id' must be a "computer" type scope id.
2020-07-08 13:38:50 +02:00
Roberto Hueso Gómez e3d30d23ff Add payload option on GET requests
Instead of using query strings we use a json body for GET HTTP requests. This is
allowed under RFCs 7230-7237.

https://stackoverflow.com/questions/978061/http-get-with-request-body
2020-07-08 11:43:49 +02:00
Roberto Hueso Gómez 8961937329 Add ogcli set mode command
This requests POST /modes and changes a scope mode by calling something like:
ogcli set modes --scope-id=1 --scope-type=computer --mode=pxe
2020-07-06 13:32:02 +02:00
Roberto Hueso Gómez 4dddd359e7 Add post() to OgREST
This is a wrapper that provides HTTP POST requests.
2020-07-03 14:25:22 +02:00
OpenGnSys Support Team 14b7729a71 add license header to source code files 2020-07-01 12:34:46 +02:00
Roberto Hueso Gómez dbf0f00650 Rename files to remove 'og' prefix
This prefix is redundant on almost every file, so the prefix is removed from
filenames and imports.
2020-06-30 12:51:51 +02:00