From 9be4de87b7ba14adc6754f408d855b960ffeca25 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Fri, 9 Feb 2024 11:32:10 +0100 Subject: ogcli: add update command for folder, room and center Expand of the update command to be able to modify the values of previous folder, room and center configurations. --- cli/cli.py | 10 ++++++++-- cli/objects/center.py | 25 +++++++++++++++++++++++++ cli/objects/folder.py | 23 +++++++++++++++++++++-- cli/objects/room.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) diff --git a/cli/cli.py b/cli/cli.py index 1271982..ecff067 100644 --- a/cli/cli.py +++ b/cli/cli.py @@ -186,7 +186,7 @@ class OgCLI(): OgDisk.setup_disk(self.rest, args[1:]) def update(self, args): - choices = ['image'] + choices = ['image', 'center', 'room', 'folder'] parser = argparse.ArgumentParser(prog='ogcli update') parser.add_argument('update_obj', choices=choices) @@ -198,6 +198,12 @@ class OgCLI(): parsed_args = parser.parse_args([args[0]]) if parsed_args.update_obj == 'image': OgImage.update_image(self.rest, args[1:]) + elif parsed_args.update_obj == 'center': + OgCenter.update_center(self.rest, args[1:]) + elif parsed_args.update_obj == 'room': + OgRoom.update_room(self.rest, args[1:]) + elif parsed_args.update_obj == 'folder': + OgFolder.update_folder(self.rest, args[1:]) def delete(self, args): choices = ['server', 'repo', 'center', 'room', 'client', 'folder'] @@ -220,7 +226,7 @@ class OgCLI(): OgRoom.delete_room(self.rest, args[1:]) elif parsed_args.delete_obj == 'client': OgClient.delete_client(self.rest, args[1:]) - elif parsed_args.add_obj == 'folder': + elif parsed_args.delete_obj == 'folder': OgFolder.delete_folder(self.rest, args[1:]) def add(self, args): diff --git a/cli/objects/center.py b/cli/objects/center.py index 0318a57..80e5e3e 100644 --- a/cli/objects/center.py +++ b/cli/objects/center.py @@ -25,6 +25,31 @@ class OgCenter(): payload['comment'] = parsed_args.desc rest.post('/center/add', payload=payload) + @staticmethod + def update_center(rest, args): + parser = argparse.ArgumentParser(prog='ogcli update center') + parser.add_argument('--id', + type=int, + nargs='?', + required=True, + help='center id in database') + parser.add_argument('--name', + nargs='?', + required=True, + help='the new name for the center') + parser.add_argument('--comment', + nargs='?', + required=False, + help='the new comment for the center') + parsed_args = parser.parse_args(args) + payload = { + 'id': parsed_args.id, + 'name': parsed_args.name, + } + if parsed_args.comment: + payload['comment'] = parsed_args.comment + rest.post('/center/update', payload=payload) + @staticmethod def delete_center(rest, args): parser = argparse.ArgumentParser(prog='ogcli delete center') diff --git a/cli/objects/folder.py b/cli/objects/folder.py index 4b9485b..c4da900 100644 --- a/cli/objects/folder.py +++ b/cli/objects/folder.py @@ -18,12 +18,12 @@ class OgFolder(): group.add_argument('--center-id', nargs='?', type=int, - required=True, + required=False, help='provide the id of the center that will contain the folder') group.add_argument('--room-id', nargs='?', type=int, - required=True, + required=False, help='provide the id of the room that will contain the folder') parser.add_argument('--name', @@ -41,6 +41,25 @@ class OgFolder(): payload['center'] = parsed_args.center_id rest.post('/folder/add', payload=payload) + @staticmethod + def update_folder(rest, args): + parser = argparse.ArgumentParser(prog='ogcli update folder') + parser.add_argument('--id', + type=int, + nargs='?', + required=True, + help='folder id in database') + parser.add_argument('--name', + nargs='?', + required=True, + help='the new name for the folder') + parsed_args = parser.parse_args(args) + payload = { + 'id': parsed_args.id, + 'name': parsed_args.name, + } + rest.post('/folder/update', payload=payload) + @staticmethod def delete_folder(rest, args): parser = argparse.ArgumentParser(prog='ogcli delete folder') diff --git a/cli/objects/room.py b/cli/objects/room.py index 9198237..f22c843 100644 --- a/cli/objects/room.py +++ b/cli/objects/room.py @@ -84,10 +84,53 @@ class OgRoom(): payload['location'] = parsed_args.desc rest.post('/room/add', payload=payload) + @staticmethod + def update_room(rest, args): + parser = argparse.ArgumentParser(prog='ogcli update room') + parser.add_argument('--id', + type=int, + nargs='?', + required=True, + help='room id in database') + parser.add_argument('--name', + nargs='?', + required=True, + help='the updated name for the room') + parser.add_argument('--netmask', + nargs='?', + required=True, + help='the updated netmask for the room') + parser.add_argument('--gateway', + nargs='?', + required=True, + help='updated address of the main gateway in the room') + parsed_args = parser.parse_args(args) + + err = False + if parsed_args.netmask and not check_address(parsed_args.netmask): + print('invalid netmask address', file=sys.stderr) + err = True + if parsed_args.gateway and not check_address(parsed_args.gateway): + print('invalid gateway address', file=sys.stderr) + err = True + if err: + parser.print_help(file=sys.stderr) + sys.exit(1) + + payload = { + 'id': parsed_args.id, + 'name': parsed_args.name, + 'netmask': parsed_args.netmask, + 'gateway': parsed_args.gateway, + } + + rest.post('/room/update', payload=payload) + @staticmethod def delete_room(rest, args): parser = argparse.ArgumentParser(prog='ogcli delete room') parser.add_argument('--id', + type=int, nargs='?', required=True, help='room id in database') -- cgit v1.2.3-18-g5258