Commit Graph

20 Commits (5abe86222892be4c21fe0d041d2e05d07ddcd7bb)

Author SHA1 Message Date
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 40bd146377 Fix utils.py
When utils.py was created, moved functions declaration was not kept for
scope_lookup by mistake, in previous commit it was named
'scope_lookup_id'.

ips_in_scope is a function that maps a list of scopes to the list of ips
contained in it, recursively. (if the scope is a room it will gather all
computers ips in that room). Add 'None' check for its scope param,
avoiding duplication of this check in several other objects using this
function.

Also import utils in 'modes' object, which was not added previously.

Fixes: be84b0a ("Add utils.py")
2021-03-30 13:29:06 +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
Jose M. Guisado be84b0a15c Add utils.py
Move auxiliary code that will be used by several objects. In this case,
scope filtering and searching by id is going to be used by 'send wol'
too.

Avoid duplicating this code creating utils.py
2021-03-29 13:47:18 +02:00
Jose M. Guisado 565e798ef9 Print json instead of python dict in responses
r.json() decodes the responses json and passes it to json.loads() which
will convert the content into a python dictionary.

Print the literal JSON text so that output can be further manipulated by
other tools like jq.
2021-03-18 15:40:35 +01:00
Jose M. Guisado c80f27c98c Make client and center params more specific
Non specific parameter names like '--center' or '--client' should not be
used to specify an ip or id, only a literal name.

Rename --client to --client-ip and --center to --center-id to leave
unspecific parameters free to later implement --center or --client using
names.
2021-03-03 11:17:05 +01:00
Jose M. Guisado 63ef83806d Rename --room param to --room-id in "set modes"
--room will be used to specify the room name instead of the id.
2021-03-03 11:17:05 +01:00
Jose M. Guisado 2b7d6b081c Add client, room and center args to set_modes
New arguments to make specifying the target machines more flexible when
changing their boot mode (known as "set client mode"). These argument
are optional although any of them must be used to specify some target.

	--client IP
	--room id
	--center id

The arguments can be specified several times like "--client ip --client
ip --room id --room id --room id", etc.

Center or room id can be obtained via /scopes.

As of this patch, set_modes does iterate through the whole /scopes
output and then filters ips with those that were specified by user.
2021-02-26 15:34:11 +01:00
Jose M. Guisado f6fa795803 Bring clients.py up to date with ogServer API
get_client_properties is not using a valid API resource to fetch
computer details. Use /client/info.

list_client_hardware is not building a valid payload. Drop
payload building using 'scope' as key and updates o that its
uses "{ client : ip }" scheme for specifying a client. This is the
standard way of specifying a client in ogServer.
2021-02-26 15:34:02 +01:00
Roberto Hueso Gómez 015a43ac3a Rework set mode command
This reworks the POST /mode command to the new API:
POST /mode
{
  'clients': ['192.168.1.5', '192.168.1.6']
  'mode': 'pxe'
}
2020-08-12 15:17:10 +02:00
Roberto Hueso Gómez d4f4497056 Change GET and POST /modes URI to /mode
This adapts to the ogServer.
2020-08-03 11:49:38 +02:00
Roberto Hueso Gómez adb2e9ffba Rework ogcli set mode command
This patch adapts the command to the fixed POST /modes request. It can
now be called with something like: ogcli set modes --scope-name=pc12
--mode=pxe

NOTE: This inherits from the legacy setclientmode script and requires
scope names to be unique. This should be fixed in the future in case
it's convenient to have duplicated scope names.
2020-07-30 10:16:56 +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