summaryrefslogtreecommitdiffstats
path: root/cli/objects
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-02-26 14:44:14 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-02-26 15:34:11 +0100
commit2b7d6b081ce7aa7cd10a7301f06eb2b8880c946a (patch)
tree56dd464ca497965bf13eb2bdf56e3f966176fb09 /cli/objects
parentf6fa7958035164029e3a20b6ac8959811e16b7eb (diff)
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.
Diffstat (limited to 'cli/objects')
-rw-r--r--cli/objects/modes.py49
1 files changed, 32 insertions, 17 deletions
diff --git a/cli/objects/modes.py b/cli/objects/modes.py
index ccb32f5..a46cae7 100644
--- a/cli/objects/modes.py
+++ b/cli/objects/modes.py
@@ -18,18 +18,28 @@ class OgModes():
@staticmethod
def set_modes(rest, args):
parser = argparse.ArgumentParser()
- parser.add_argument('--scope-id',
- nargs=1,
- required=True,
- help='ID of the scope')
- parser.add_argument('--scope-type',
- nargs=1,
- required=True,
- help='Type of the scope')
+ group = parser.add_argument_group('clients', 'Client selection args')
+ group.add_argument('--center',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given center')
+ 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',
nargs=1,
required=True,
- help='Mode for the scope')
+ help='Boot mode to be set')
parsed_args = parser.parse_args(args)
def scope_lookup(scope_id, scope_type, d):
@@ -54,15 +64,20 @@ class OgModes():
r = rest.get('/scopes')
scopes = r.json()
- found_scope = scope_lookup(int(parsed_args.scope_id[0]),
- parsed_args.scope_type[0],
- scopes)
+ ips = set()
- if found_scope is None:
- print("Scope not found")
- return None
+ for center in parsed_args.center:
+ 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)
- ips = ips_in_scope(found_scope)
+ if not ips:
+ print("No clients found")
+ return None
- payload = {'clients': ips, 'mode': parsed_args.mode[0]}
+ payload = {'clients': list(ips), 'mode': parsed_args.mode[0]}
r = rest.post('/mode', payload=payload)