summaryrefslogtreecommitdiffstats
path: root/cli/objects
diff options
context:
space:
mode:
Diffstat (limited to 'cli/objects')
-rw-r--r--cli/objects/client.py89
-rw-r--r--cli/objects/disks.py266
-rw-r--r--cli/objects/images.py274
-rw-r--r--cli/objects/modes.py93
-rw-r--r--cli/objects/poweroff.py86
-rw-r--r--cli/objects/scopes.py9
-rw-r--r--cli/objects/wol.py110
7 files changed, 471 insertions, 456 deletions
diff --git a/cli/objects/client.py b/cli/objects/client.py
index 4dc64fd..dbb7f15 100644
--- a/cli/objects/client.py
+++ b/cli/objects/client.py
@@ -9,49 +9,50 @@ import argparse
from cli.utils import print_json
+
class OgClient():
- @staticmethod
- def list_clients(rest):
- r = rest.get('/clients')
- print_json(r.text)
-
- @staticmethod
- def list_client_hardware(rest, args):
- parser = argparse.ArgumentParser()
- parser.add_argument('--client-ip',
- nargs=1,
- type=str,
- required=True,
- help='client IP')
- parsed_args = parser.parse_args(args)
-
- payload = {'client': parsed_args.client_ip}
- r = rest.get('/hardware', payload=payload)
- print_json(r.text)
-
- @staticmethod
- def get_client_properties(rest, args):
- parser = argparse.ArgumentParser()
- parser.add_argument('--client-ip',
- nargs=1,
- required=True,
- help='client IP')
- parsed_args = parser.parse_args(args)
-
- payload = {'client': parsed_args.client_ip}
- r = rest.get('/client/info', payload=payload)
- print_json(r.text)
-
- @staticmethod
- def send_refresh(rest, args):
- parser = argparse.ArgumentParser()
- parser.add_argument('--client-ip',
- action='append',
- default=[],
- required=True,
- help='Client IP')
- parsed_args = parser.parse_args(args)
-
- payload = {'clients': parsed_args.client_ip}
- rest.post('/refresh', payload=payload)
+ @staticmethod
+ def list_clients(rest):
+ r = rest.get('/clients')
+ print_json(r.text)
+
+ @staticmethod
+ def list_client_hardware(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--client-ip',
+ nargs=1,
+ type=str,
+ required=True,
+ help='client IP')
+ parsed_args = parser.parse_args(args)
+
+ payload = {'client': parsed_args.client_ip}
+ r = rest.get('/hardware', payload=payload)
+ print_json(r.text)
+
+ @staticmethod
+ def get_client_properties(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--client-ip',
+ nargs=1,
+ required=True,
+ help='client IP')
+ parsed_args = parser.parse_args(args)
+
+ payload = {'client': parsed_args.client_ip}
+ r = rest.get('/client/info', payload=payload)
+ print_json(r.text)
+
+ @staticmethod
+ def send_refresh(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=True,
+ help='Client IP')
+ parsed_args = parser.parse_args(args)
+
+ payload = {'clients': parsed_args.client_ip}
+ rest.post('/refresh', payload=payload)
diff --git a/cli/objects/disks.py b/cli/objects/disks.py
index deaf5b3..4df9994 100644
--- a/cli/objects/disks.py
+++ b/cli/objects/disks.py
@@ -10,136 +10,140 @@ import re
from cli.utils import print_json
+
class OgDisk():
- @staticmethod
- def list_disks(rest, args):
- parser = argparse.ArgumentParser()
- parser.add_argument('--client-ip',
- nargs='?',
- required=True,
- help='Client IP to query')
- parsed_args = parser.parse_args(args)
- payload = {'client': [parsed_args.client_ip]}
-
- r = rest.get('/client/setup', payload=payload)
- print_json(r.text)
-
- @staticmethod
- def setup_disk(rest, args):
- def parse_size(size):
- size = size.upper()
- units = {"M": 10**3, "G": 10**6, "T": 10**9} # Mapped to K
- # size = re.sub(r'(\d+)([MGT])', r'\1 \2', size)
- match = re.match(r'(\d+)([MGT])', size)
- if match:
- if len(match.groups()) == 2:
- number, unit = match.groups()
- return str(int(float(number)*units[unit]))
- print(f'Error parsing size {size}. Aborting.')
- return None
-
- disk_type_map = {'dos': 'MSDOS', 'gpt': 'GPT'}
- part_types = ['LINUX', 'EFI', 'WINDOWS', 'CACHE']
- fs_types = ['EXT4', 'FAT32', 'NTFS', 'CACHE']
-
- parser = argparse.ArgumentParser()
- parser.add_argument('--type',
- nargs='?',
- required=True,
- choices=['dos','gpt'],
- help='Disk partition scheme')
- parser.add_argument('--num',
- nargs='?',
- default=1,
- help='Disk number (defaults to 1)')
- parser.add_argument('--format',
- nargs='?',
- const=True,
- type=lambda x: x.split(','),
- help='Indicates which partitions to reformat if they are already present. '\
- 'Use --part alone to mean all partitions.')
- parser.add_argument('--part',
- nargs='+',
- action='append',
- type=lambda x: x.split(','),
- required=True,
- help='Partition definition (syntax: "num,part_scheme,fs,size")')
- group = parser.add_argument_group('clients', 'Client selection args')
- group.add_argument('--center-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given center id')
- group.add_argument('--room-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given room id')
- group.add_argument('--client-ip',
- action='append',
- default=[],
- required=False,
- help='Specific client IP')
-
- parsed_args = parser.parse_args(args)
- r = rest.get('/scopes')
- scopes = r.json()
- ips = set()
-
- for center in parsed_args.center_id:
- center_scope = scope_lookup(center, 'center', scopes)
- ips.update(ips_in_scope(center_scope))
- for room in parsed_args.room_id:
- room_scope = scope_lookup(room, 'room', scopes)
- ips.update(ips_in_scope(room_scope))
- for l in parsed_args.client_ip:
- ips.add(l)
- if not ips:
- print("No clients found")
- return None
-
- payload = {'clients': parsed_args.client_ip, 'type': disk_type_map[parsed_args.type], 'disk': str(parsed_args.num),
- 'cache': '0', 'cache_size': '0', 'partition_setup': []}
- for i, p in enumerate(parsed_args.part, start=1):
- p = p[0]
- part_num, code, fs, size = p[0], p[1].upper(), p[2].upper(), p[3]
-
- if code not in part_types:
- print(f'Specified partition type {code} is not supported. Aborting...')
- return
- if fs not in fs_types:
- print(f'Specified filesystem {code} is not supported. Aborting...')
- return
- size = parse_size(size)
-
- for j in range(i, int(part_num)):
- part = {'partition': str(j), 'code':'EMPTY',
- 'filesystem': 'EMPTY', 'size': '0',
- 'format': '0'}
- payload['partition_setup'].append(part)
-
- if parsed_args.format is True or (type(parsed_args.format) == list and part_num in parsed_args.format):
- do_format = '1'
- else:
- do_format = '0'
-
- if fs == 'CACHE':
- payload['cache'] = '1' # Assuming flag specifying if there's cache in the setup
- payload['cache_size'] = size
- part = {'partition': str(p[0]), 'code':code.upper(),
- 'filesystem': fs.upper(), 'size': size,
- 'format': do_format}
- payload['partition_setup'].append(part)
-
- last_partnum = int(parsed_args.part[-1][0][0])
- # Pad with empty partitions if no 4th part was defined
- for i in range(last_partnum + 1, 5):
- part = {'partition': str(i), 'code':'EMPTY',
- 'filesystem': 'EMPTY', 'size': '0',
- 'format': '0'}
- payload['partition_setup'].append(part)
-
- rest.post('/setup', payload=payload)
+ @staticmethod
+ def list_disks(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--client-ip',
+ nargs='?',
+ required=True,
+ help='Client IP to query')
+ parsed_args = parser.parse_args(args)
+ payload = {'client': [parsed_args.client_ip]}
+
+ r = rest.get('/client/setup', payload=payload)
+ print_json(r.text)
+
+ @staticmethod
+ def setup_disk(rest, args):
+ def parse_size(size):
+ size = size.upper()
+ units = {"M": 10**3, "G": 10**6, "T": 10**9} # Mapped to K
+ # size = re.sub(r'(\d+)([MGT])', r'\1 \2', size)
+ match = re.match(r'(\d+)([MGT])', size)
+ if match:
+ if len(match.groups()) == 2:
+ number, unit = match.groups()
+ return str(int(float(number)*units[unit]))
+ print(f'Error parsing size {size}. Aborting.')
+ return None
+
+ disk_type_map = {'dos': 'MSDOS', 'gpt': 'GPT'}
+ part_types = ['LINUX', 'EFI', 'WINDOWS', 'CACHE']
+ fs_types = ['EXT4', 'FAT32', 'NTFS', 'CACHE']
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--type',
+ nargs='?',
+ required=True,
+ choices=['dos', 'gpt'],
+ help='Disk partition scheme')
+ parser.add_argument('--num',
+ nargs='?',
+ default=1,
+ help='Disk number (defaults to 1)')
+ parser.add_argument('--format',
+ nargs='?',
+ const=True,
+ type=lambda x: x.split(','),
+ help='Indicates which partitions to reformat if they are already present. '
+ 'Use --part alone to mean all partitions.')
+ parser.add_argument('--part',
+ nargs='+',
+ action='append',
+ type=lambda x: x.split(','),
+ required=True,
+ help='Partition definition (syntax: "num,part_scheme,fs,size")')
+ group = parser.add_argument_group('clients', 'Client selection args')
+ group.add_argument('--center-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given center id')
+ group.add_argument('--room-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given room id')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=False,
+ help='Specific client IP')
+
+ parsed_args = parser.parse_args(args)
+ r = rest.get('/scopes')
+ scopes = r.json()
+ ips = set()
+
+ for center in parsed_args.center_id:
+ center_scope = scope_lookup(center, 'center', scopes)
+ ips.update(ips_in_scope(center_scope))
+ for room in parsed_args.room_id:
+ room_scope = scope_lookup(room, 'room', scopes)
+ ips.update(ips_in_scope(room_scope))
+ for l in parsed_args.client_ip:
+ ips.add(l)
+ if not ips:
+ print("No clients found")
+ return None
+
+ payload = {'clients': parsed_args.client_ip, 'type': disk_type_map[parsed_args.type], 'disk': str(parsed_args.num),
+ 'cache': '0', 'cache_size': '0', 'partition_setup': []}
+ for i, p in enumerate(parsed_args.part, start=1):
+ p = p[0]
+ part_num, code, fs, size = p[0], p[1].upper(), p[2].upper(), p[3]
+
+ if code not in part_types:
+ print(
+ f'Specified partition type {code} is not supported. Aborting...')
+ return
+ if fs not in fs_types:
+ print(
+ f'Specified filesystem {code} is not supported. Aborting...')
+ return
+ size = parse_size(size)
+
+ for j in range(i, int(part_num)):
+ part = {'partition': str(j), 'code': 'EMPTY',
+ 'filesystem': 'EMPTY', 'size': '0',
+ 'format': '0'}
+ payload['partition_setup'].append(part)
+
+ if parsed_args.format is True or (type(parsed_args.format) == list and part_num in parsed_args.format):
+ do_format = '1'
+ else:
+ do_format = '0'
+
+ if fs == 'CACHE':
+ # Assuming flag specifying if there's cache in the setup
+ payload['cache'] = '1'
+ payload['cache_size'] = size
+ part = {'partition': str(p[0]), 'code': code.upper(),
+ 'filesystem': fs.upper(), 'size': size,
+ 'format': do_format}
+ payload['partition_setup'].append(part)
+
+ last_partnum = int(parsed_args.part[-1][0][0])
+ # Pad with empty partitions if no 4th part was defined
+ for i in range(last_partnum + 1, 5):
+ part = {'partition': str(i), 'code': 'EMPTY',
+ 'filesystem': 'EMPTY', 'size': '0',
+ 'format': '0'}
+ payload['partition_setup'].append(part)
+
+ rest.post('/setup', payload=payload)
diff --git a/cli/objects/images.py b/cli/objects/images.py
index 8299923..89d57c2 100644
--- a/cli/objects/images.py
+++ b/cli/objects/images.py
@@ -10,140 +10,144 @@ from cli.utils import *
import argparse
+
class OgImage():
- @staticmethod
- def list_images(rest):
- r = rest.get('/images')
- print_json(r.text)
-
- @staticmethod
- def restore_image(rest, args):
- parser = argparse.ArgumentParser()
- parser.add_argument('--disk',
- nargs='?',
- required=True,
- help='Disk')
- parser.add_argument('--part',
- nargs='?',
- required=True,
- help='Partition')
- parser.add_argument('--id',
- nargs='?',
- type=int,
- required=True,
- help='Image id to be restored')
- parser.add_argument('--type',
- nargs='?',
- required=False,
- choices=['unicast', 'unicast-direct', 'tiptorrent'],
- default='tiptorrent',
- help='Transfer method. (Default: tiptorrent)')
- parser.add_argument('--repo',
- nargs='?',
- default=urlparse(rest.URL).netloc.split(':')[0],
- help='Images repository ip')
- group = parser.add_argument_group('clients', 'Client selection args')
- group.add_argument('--center-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given center id')
- group.add_argument('--room-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given room id')
- group.add_argument('--client-ip',
- action='append',
- default=[],
- required=False,
- help='Specific client IP')
- parsed_args = parser.parse_args(args)
-
- r = rest.get('/scopes')
- scopes = r.json()
- ips = set()
-
- for center in parsed_args.center_id:
- center_scope = scope_lookup(center, 'center', scopes)
- ips.update(ips_in_scope(center_scope))
- for room in parsed_args.room_id:
- room_scope = scope_lookup(room, 'room', scopes)
- ips.update(ips_in_scope(room_scope))
- for l in parsed_args.client_ip:
- ips.add(l)
-
- if not ips:
- print('No clients specified.')
- return
-
- r = rest.get('/images')
- images = r.json()
- found_image = [img for img in images['images'] if img['id'] == parsed_args.id]
- if not found_image:
- print(f'Image with id {parsed_args.id} not found.')
- return
- else:
- found_image = found_image[0]
-
- payload = {'disk': parsed_args.disk, 'partition': parsed_args.part,
- 'id': str(parsed_args.id), 'name': found_image['name'],
- 'profile': str(found_image['software_id']),
- 'repository': parsed_args.repo,
- 'type': parsed_args.type.upper(), 'clients': list(ips)}
- r = rest.post('/image/restore', payload=payload)
-
- @staticmethod
- def create_image(rest, args):
- parser = argparse.ArgumentParser()
- parser.add_argument('--disk',
- nargs='?',
- required=True,
- help='Disk')
- parser.add_argument('--part',
- nargs='?',
- required=True,
- help='Partition')
- parser.add_argument('--name',
- nargs='?',
- required=True,
- help='Image name')
- parser.add_argument('--desc',
- nargs='?',
- required=False,
- help='Image description (for new images)')
- parser.add_argument('--repo',
- nargs='?',
- default=urlparse(rest.URL).netloc.split(':')[0],
- help='Images repository ip')
- group = parser.add_argument_group('clients', 'Client selection args')
- group.add_argument('--client-ip',
- action='append',
- default=[],
- required=False,
- help='Specific client IP')
- parsed_args = parser.parse_args(args)
-
- r = rest.get('/client/info', payload={'client':parsed_args.client_ip})
- center_id = r.json()['center']
-
- r = rest.get('/client/setup', payload={'client':parsed_args.client_ip})
- if r.status_code == 200:
- part_info = list(filter(lambda x: x['disk'] == int(parsed_args.disk) and
- x['partition'] == int(parsed_args.part),
- r.json()['partitions']))
- if not part_info:
- print('Partition not found.')
- return
- fs_code = list(part_info)[0]['code']
-
- payload = {'clients': parsed_args.client_ip, 'disk': parsed_args.disk, 'center_id': center_id,
- 'partition': parsed_args.part, 'code': str(fs_code), 'name': parsed_args.name,
- 'repository': parsed_args.repo, 'id': '0'}
- if parsed_args.desc:
- payload['description'] = parsed_args.desc
-
- rest.post('/image/create', payload=payload)
+ @staticmethod
+ def list_images(rest):
+ r = rest.get('/images')
+ print_json(r.text)
+
+ @staticmethod
+ def restore_image(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--disk',
+ nargs='?',
+ required=True,
+ help='Disk')
+ parser.add_argument('--part',
+ nargs='?',
+ required=True,
+ help='Partition')
+ parser.add_argument('--id',
+ nargs='?',
+ type=int,
+ required=True,
+ help='Image id to be restored')
+ parser.add_argument('--type',
+ nargs='?',
+ required=False,
+ choices=['unicast',
+ 'unicast-direct', 'tiptorrent'],
+ default='tiptorrent',
+ help='Transfer method. (Default: tiptorrent)')
+ parser.add_argument('--repo',
+ nargs='?',
+ default=urlparse(rest.URL).netloc.split(':')[0],
+ help='Images repository ip')
+ group = parser.add_argument_group('clients', 'Client selection args')
+ group.add_argument('--center-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given center id')
+ group.add_argument('--room-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given room id')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=False,
+ help='Specific client IP')
+ parsed_args = parser.parse_args(args)
+
+ r = rest.get('/scopes')
+ scopes = r.json()
+ ips = set()
+
+ for center in parsed_args.center_id:
+ center_scope = scope_lookup(center, 'center', scopes)
+ ips.update(ips_in_scope(center_scope))
+ for room in parsed_args.room_id:
+ room_scope = scope_lookup(room, 'room', scopes)
+ ips.update(ips_in_scope(room_scope))
+ for l in parsed_args.client_ip:
+ ips.add(l)
+
+ if not ips:
+ print('No clients specified.')
+ return
+
+ r = rest.get('/images')
+ images = r.json()
+ found_image = [img for img in images['images']
+ if img['id'] == parsed_args.id]
+ if not found_image:
+ print(f'Image with id {parsed_args.id} not found.')
+ return
+ else:
+ found_image = found_image[0]
+
+ payload = {'disk': parsed_args.disk, 'partition': parsed_args.part,
+ 'id': str(parsed_args.id), 'name': found_image['name'],
+ 'profile': str(found_image['software_id']),
+ 'repository': parsed_args.repo,
+ 'type': parsed_args.type.upper(), 'clients': list(ips)}
+ r = rest.post('/image/restore', payload=payload)
+
+ @staticmethod
+ def create_image(rest, args):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--disk',
+ nargs='?',
+ required=True,
+ help='Disk')
+ parser.add_argument('--part',
+ nargs='?',
+ required=True,
+ help='Partition')
+ parser.add_argument('--name',
+ nargs='?',
+ required=True,
+ help='Image name')
+ parser.add_argument('--desc',
+ nargs='?',
+ required=False,
+ help='Image description (for new images)')
+ parser.add_argument('--repo',
+ nargs='?',
+ default=urlparse(rest.URL).netloc.split(':')[0],
+ help='Images repository ip')
+ group = parser.add_argument_group('clients', 'Client selection args')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=False,
+ help='Specific client IP')
+ parsed_args = parser.parse_args(args)
+
+ r = rest.get('/client/info', payload={'client': parsed_args.client_ip})
+ center_id = r.json()['center']
+
+ r = rest.get('/client/setup',
+ payload={'client': parsed_args.client_ip})
+ if r.status_code == 200:
+ part_info = list(filter(lambda x: x['disk'] == int(parsed_args.disk) and
+ x['partition'] == int(parsed_args.part),
+ r.json()['partitions']))
+ if not part_info:
+ print('Partition not found.')
+ return
+ fs_code = list(part_info)[0]['code']
+
+ payload = {'clients': parsed_args.client_ip, 'disk': parsed_args.disk, 'center_id': center_id,
+ 'partition': parsed_args.part, 'code': str(fs_code), 'name': parsed_args.name,
+ 'repository': parsed_args.repo, 'id': '0'}
+ if parsed_args.desc:
+ payload['description'] = parsed_args.desc
+
+ rest.post('/image/create', payload=payload)
diff --git a/cli/objects/modes.py b/cli/objects/modes.py
index 8a9754e..2abb091 100644
--- a/cli/objects/modes.py
+++ b/cli/objects/modes.py
@@ -9,56 +9,57 @@ from cli.utils import *
import argparse
+
class OgModes():
- @staticmethod
- def list_available_modes(rest):
- r = rest.get('/mode')
- print(r.text)
+ @staticmethod
+ def list_available_modes(rest):
+ r = rest.get('/mode')
+ print(r.text)
- @staticmethod
- def set_modes(rest, args):
- parser = argparse.ArgumentParser(prog='ogcli set mode')
- group = parser.add_argument_group('clients', 'Client selection args')
- group.add_argument('--center-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given center id')
- group.add_argument('--room-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given room id')
- group.add_argument('--client-ip',
- action='append',
- default=[],
- required=False,
- help='Specific client IP')
- parser.add_argument('--mode',
- nargs=1,
- required=True,
- help='Boot mode to be set')
- parsed_args = parser.parse_args(args)
+ @staticmethod
+ def set_modes(rest, args):
+ parser = argparse.ArgumentParser(prog='ogcli set mode')
+ group = parser.add_argument_group('clients', 'Client selection args')
+ group.add_argument('--center-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given center id')
+ group.add_argument('--room-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given room id')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=False,
+ help='Specific client IP')
+ parser.add_argument('--mode',
+ nargs=1,
+ required=True,
+ help='Boot mode to be set')
+ parsed_args = parser.parse_args(args)
- r = rest.get('/scopes')
- scopes = r.json()
- ips = set()
+ r = rest.get('/scopes')
+ scopes = r.json()
+ ips = set()
- for center in parsed_args.center_id:
- center_scope = scope_lookup(center, 'center', scopes)
- ips.update(ips_in_scope(center_scope))
- for room in parsed_args.room_id:
- room_scope = scope_lookup(room, 'room', scopes)
- ips.update(ips_in_scope(room_scope))
- for l in parsed_args.client_ip:
- ips.add(l)
+ for center in parsed_args.center_id:
+ center_scope = scope_lookup(center, 'center', scopes)
+ ips.update(ips_in_scope(center_scope))
+ for room in parsed_args.room_id:
+ room_scope = scope_lookup(room, 'room', scopes)
+ ips.update(ips_in_scope(room_scope))
+ for l in parsed_args.client_ip:
+ ips.add(l)
- if not ips:
- print("No clients found")
- return None
+ if not ips:
+ print("No clients found")
+ return None
- payload = {'clients': list(ips), 'mode': parsed_args.mode[0]}
- r = rest.post('/mode', payload=payload)
+ payload = {'clients': list(ips), 'mode': parsed_args.mode[0]}
+ r = rest.post('/mode', payload=payload)
diff --git a/cli/objects/poweroff.py b/cli/objects/poweroff.py
index f5eb1dd..da3666c 100644
--- a/cli/objects/poweroff.py
+++ b/cli/objects/poweroff.py
@@ -9,47 +9,49 @@ from cli.utils import *
import argparse
+
class OgPoweroff():
- @staticmethod
- def send_poweroff(rest, args):
- parser = argparse.ArgumentParser()
- group = parser.add_argument_group('clients', 'Client selection options')
- group.add_argument('--center-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given center id')
- group.add_argument('--room-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given room id')
- group.add_argument('--client-ip',
- action='append',
- default=[],
- required=False,
- help='Specific client IP')
- parsed_args = parser.parse_args(args)
-
- r = rest.get('/scopes')
- scopes = r.json()
- ips = set()
-
- for center in parsed_args.center_id:
- center_scope = scope_lookup(center, 'center', scopes)
- ips.update(ips_in_scope(center_scope))
- for room in parsed_args.room_id:
- room_scope = scope_lookup(room, 'room', scopes)
- ips.update(ips_in_scope(room_scope))
- for l in parsed_args.client_ip:
- ips.add(l)
-
- if not ips:
- print("No clients found")
- return None
-
- payload = {'clients': list(ips)}
- r = rest.post('/poweroff', payload=payload)
+ @staticmethod
+ def send_poweroff(rest, args):
+ parser = argparse.ArgumentParser()
+ group = parser.add_argument_group(
+ 'clients', 'Client selection options')
+ group.add_argument('--center-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given center id')
+ group.add_argument('--room-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given room id')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=False,
+ help='Specific client IP')
+ parsed_args = parser.parse_args(args)
+
+ r = rest.get('/scopes')
+ scopes = r.json()
+ ips = set()
+
+ for center in parsed_args.center_id:
+ center_scope = scope_lookup(center, 'center', scopes)
+ ips.update(ips_in_scope(center_scope))
+ for room in parsed_args.room_id:
+ room_scope = scope_lookup(room, 'room', scopes)
+ ips.update(ips_in_scope(room_scope))
+ for l in parsed_args.client_ip:
+ ips.add(l)
+
+ if not ips:
+ print("No clients found")
+ return None
+
+ payload = {'clients': list(ips)}
+ r = rest.post('/poweroff', payload=payload)
diff --git a/cli/objects/scopes.py b/cli/objects/scopes.py
index 5383932..9416f4f 100644
--- a/cli/objects/scopes.py
+++ b/cli/objects/scopes.py
@@ -9,9 +9,10 @@ import argparse
from cli.utils import print_json
+
class OgScope():
- @staticmethod
- def list_scopes(rest):
- r = rest.get('/scopes')
- print_json(r.text)
+ @staticmethod
+ def list_scopes(rest):
+ r = rest.get('/scopes')
+ print_json(r.text)
diff --git a/cli/objects/wol.py b/cli/objects/wol.py
index 5b8e490..e788ce1 100644
--- a/cli/objects/wol.py
+++ b/cli/objects/wol.py
@@ -9,64 +9,66 @@ from cli.utils import *
import argparse
+
class OgWol():
- @staticmethod
- def send_wol(rest, args):
- def scope_lookup(scope_id, scope_type, d):
- if scope_id == d.get('id') and \
- scope_type == d.get('type'):
- return d
- for scope in d['scope']:
- lookup = scope_lookup(scope_id,
- scope_type,
- scope)
- if lookup is not None:
- return lookup
- return None
+ @staticmethod
+ def send_wol(rest, args):
+ def scope_lookup(scope_id, scope_type, d):
+ if scope_id == d.get('id') and \
+ scope_type == d.get('type'):
+ return d
+ for scope in d['scope']:
+ lookup = scope_lookup(scope_id,
+ scope_type,
+ scope)
+ if lookup is not None:
+ return lookup
+ return None
- parser = argparse.ArgumentParser()
- parser.add_argument('--type',
- nargs='?',
- choices=['broadcast','unicast'],
- default='broadcast',
- help='')
- group = parser.add_argument_group('clients', 'Client selection options')
- group.add_argument('--center-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given center id')
- group.add_argument('--room-id',
- type=int,
- action='append',
- default=[],
- required=False,
- help='Clients from given room id')
- group.add_argument('--client-ip',
- action='append',
- default=[],
- required=False,
- help='Specific client IP')
- parsed_args = parser.parse_args(args)
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--type',
+ nargs='?',
+ choices=['broadcast', 'unicast'],
+ default='broadcast',
+ help='')
+ group = parser.add_argument_group(
+ 'clients', 'Client selection options')
+ group.add_argument('--center-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given center id')
+ group.add_argument('--room-id',
+ type=int,
+ action='append',
+ default=[],
+ required=False,
+ help='Clients from given room id')
+ group.add_argument('--client-ip',
+ action='append',
+ default=[],
+ required=False,
+ help='Specific client IP')
+ parsed_args = parser.parse_args(args)
- r = rest.get('/scopes')
- scopes = r.json()
- ips = set()
+ r = rest.get('/scopes')
+ scopes = r.json()
+ ips = set()
- for center in parsed_args.center_id:
- center_scope = scope_lookup(center, 'center', scopes)
- ips.update(ips_in_scope(center_scope))
- for room in parsed_args.room_id:
- room_scope = scope_lookup(room, 'room', scopes)
- ips.update(ips_in_scope(room_scope))
- for l in parsed_args.client_ip:
- ips.add(l)
+ for center in parsed_args.center_id:
+ center_scope = scope_lookup(center, 'center', scopes)
+ ips.update(ips_in_scope(center_scope))
+ for room in parsed_args.room_id:
+ room_scope = scope_lookup(room, 'room', scopes)
+ ips.update(ips_in_scope(room_scope))
+ for l in parsed_args.client_ip:
+ ips.add(l)
- if not ips:
- print("No clients found")
- return None
+ if not ips:
+ print("No clients found")
+ return None
- payload = {'type': parsed_args.type, 'clients': list(ips)}
- r = rest.post('/wol', payload=payload)
+ payload = {'type': parsed_args.type, 'clients': list(ips)}
+ r = rest.post('/wol', payload=payload)