1 | # Copyright (C) 2020-2021 Soleta Networks <info@soleta.eu> |
---|
2 | # |
---|
3 | # This program is free software: you can redistribute it and/or modify it under |
---|
4 | # the terms of the GNU Affero General Public License as published by the |
---|
5 | # Free Software Foundation; either version 3 of the License, or |
---|
6 | # (at your option) any later version. |
---|
7 | |
---|
8 | from cli.utils import * |
---|
9 | |
---|
10 | import argparse |
---|
11 | |
---|
12 | |
---|
13 | class OgPoweroff(): |
---|
14 | |
---|
15 | @staticmethod |
---|
16 | def send_poweroff(rest, args): |
---|
17 | parser = argparse.ArgumentParser() |
---|
18 | group = parser.add_argument_group( |
---|
19 | 'clients', 'Client selection options') |
---|
20 | group.add_argument('--center-id', |
---|
21 | type=int, |
---|
22 | action='append', |
---|
23 | default=[], |
---|
24 | required=False, |
---|
25 | help='Clients from given center id') |
---|
26 | group.add_argument('--room-id', |
---|
27 | type=int, |
---|
28 | action='append', |
---|
29 | default=[], |
---|
30 | required=False, |
---|
31 | help='Clients from given room id') |
---|
32 | group.add_argument('--client-ip', |
---|
33 | action='append', |
---|
34 | default=[], |
---|
35 | required=False, |
---|
36 | help='Specific client IP') |
---|
37 | parsed_args = parser.parse_args(args) |
---|
38 | |
---|
39 | r = rest.get('/scopes') |
---|
40 | scopes = r.json() |
---|
41 | ips = set() |
---|
42 | |
---|
43 | for center in parsed_args.center_id: |
---|
44 | center_scope = scope_lookup(center, 'center', scopes) |
---|
45 | ips.update(ips_in_scope(center_scope)) |
---|
46 | for room in parsed_args.room_id: |
---|
47 | room_scope = scope_lookup(room, 'room', scopes) |
---|
48 | ips.update(ips_in_scope(room_scope)) |
---|
49 | for l in parsed_args.client_ip: |
---|
50 | ips.add(l) |
---|
51 | |
---|
52 | if not ips: |
---|
53 | print("No clients found") |
---|
54 | return None |
---|
55 | |
---|
56 | payload = {'clients': list(ips)} |
---|
57 | r = rest.post('/poweroff', payload=payload) |
---|