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.
master
Jose M. Guisado 2021-02-26 14:44:14 +01:00 committed by OpenGnSys Support Team
parent f6fa795803
commit 2b7d6b081c
1 changed files with 32 additions and 17 deletions

View File

@ -18,18 +18,28 @@ class OgModes():
@staticmethod @staticmethod
def set_modes(rest, args): def set_modes(rest, args):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--scope-id', group = parser.add_argument_group('clients', 'Client selection args')
nargs=1, group.add_argument('--center',
required=True, type=int,
help='ID of the scope') action='append',
parser.add_argument('--scope-type', default=[],
nargs=1, required=False,
required=True, help='Clients from given center')
help='Type of the scope') group.add_argument('--room',
type=int,
action='append',
default=[],
required=False,
help='Clients from given room')
group.add_argument('--client',
action='append',
default=[],
required=False,
help='Specific client IP')
parser.add_argument('--mode', parser.add_argument('--mode',
nargs=1, nargs=1,
required=True, required=True,
help='Mode for the scope') help='Boot mode to be set')
parsed_args = parser.parse_args(args) parsed_args = parser.parse_args(args)
def scope_lookup(scope_id, scope_type, d): def scope_lookup(scope_id, scope_type, d):
@ -54,15 +64,20 @@ class OgModes():
r = rest.get('/scopes') r = rest.get('/scopes')
scopes = r.json() scopes = r.json()
found_scope = scope_lookup(int(parsed_args.scope_id[0]), ips = set()
parsed_args.scope_type[0],
scopes)
if found_scope is None: for center in parsed_args.center:
print("Scope not found") center_scope = scope_lookup(center, 'center', scopes)
ips.update(ips_in_scope(center_scope))
for room in parsed_args.room:
room_scope = scope_lookup(room, 'room', scopes)
ips.update(ips_in_scope(room_scope))
for l in parsed_args.client:
ips.add(l)
if not ips:
print("No clients found")
return None return None
ips = ips_in_scope(found_scope) payload = {'clients': list(ips), 'mode': parsed_args.mode[0]}
payload = {'clients': ips, 'mode': parsed_args.mode[0]}
r = rest.post('/mode', payload=payload) r = rest.post('/mode', payload=payload)