summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-10-11 17:50:19 +0200
committerJose M. Guisado <jguisado@soleta.eu>2023-10-11 17:50:47 +0200
commita4bf35ef28ee1f18cea0541addcbb24d92dfdb62 (patch)
treebdfb7270563aeb6df710d1522f23b496727f0224 /cli
parent4e89fe44d0c69406b3f6ec1ca885c93bd6793448 (diff)
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.
Diffstat (limited to 'cli')
-rw-r--r--cli/cli.py4
-rw-r--r--cli/objects/repo.py25
2 files changed, 28 insertions, 1 deletions
diff --git a/cli/cli.py b/cli/cli.py
index de344e5..cfe99f6 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -209,7 +209,7 @@ class OgCLI():
OgServer.delete_server(self.rest, args[1:])
def add(self, args):
- choices = ['server']
+ choices = ['server', 'repo']
parser = argparse.ArgumentParser(prog='ogcli add')
parser.add_argument('add_obj', choices=choices)
@@ -221,3 +221,5 @@ class OgCLI():
parsed_args = parser.parse_args([args[0]])
if parsed_args.add_obj == 'server':
OgServer.add_server(self.rest, args[1:])
+ elif parsed_args.add_obj == 'repo':
+ OgRepo.add_repo(self.rest, args[1:])
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
@@ -17,6 +17,31 @@ class OgRepo():
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')
parser.add_argument('--id',