From a4bf35ef28ee1f18cea0541addcbb24d92dfdb62 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 11 Oct 2023 17:50:19 +0200 Subject: repo: add add_repo function User can add a new repository to the database using "ogcli add repo": $ ogcli add repo --name ogcli --address 10.10.10.10 { "center": 1, "id": 13, "ip": "10.10.10.10", "name": "ogcli" } The --center optional parameter is used to set the center column of "repositorios" table in the database to the specified value. If this parameter is missing ogServer API will default to center with id 1 (the default center). This is to not break the repository in the legacy webconsole users. --- cli/objects/repo.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cli/objects') diff --git a/cli/objects/repo.py b/cli/objects/repo.py index c4c4164..9728f33 100644 --- a/cli/objects/repo.py +++ b/cli/objects/repo.py @@ -16,6 +16,31 @@ class OgRepo(): r = rest.get('/repositories') print_json(r.text) + @staticmethod + def add_repo(rest, args): + parser = argparse.ArgumentParser(prog='ogcli add repo') + parser.add_argument('--address', + nargs='?', + required=True, + help='valid ip address') + parser.add_argument('--name', + nargs='?', + required=True, + help='valid ip address') + parser.add_argument('--center', + nargs='?', + type=int, + help='(Optional, Legacy) Center id serving this repository') + parsed_args = parser.parse_args(args) + payload = { + 'ip': parsed_args.address, + 'name': parsed_args.name, + } + if parsed_args.center: + payload['center']: center + + rest.post('/repository/add', payload=payload) + @staticmethod def set_repo(rest, args): parser = argparse.ArgumentParser(prog='ogcli set repo') -- cgit v1.2.3-18-g5258