summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-07-03 14:25:22 +0200
committerRoberto Hueso Gómez <rhueso@soleta.eu>2020-07-03 14:25:22 +0200
commit4dddd359e73d96eba4c472138ea70064d0f39616 (patch)
treedb163aae847fb732e0eba157d381955114abd60a
parent53ed3933d9fb2e746328d3ee3dc5402130571b1d (diff)
Add post() to OgREST
This is a wrapper that provides HTTP POST requests.
-rw-r--r--cli/cli.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/cli/cli.py b/cli/cli.py
index 2b80c95..01e15eb 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -29,6 +29,19 @@ class OgREST():
sys.exit(f"Cannot connect to ogServer: {e}")
return r
+ def post(self, path, payload):
+ try:
+ r = requests.post(f'{self.URL}{path}',
+ headers=self.HEADERS,
+ json=payload)
+ print(r.text)
+ if r.status_code not in {200, 202}:
+ sys.exit(f"Cannot connect to ogServer: "
+ f"{r.status_code} HTTP status code")
+ except IOError as e:
+ sys.exit(f"Cannot connect to ogServer: {e}")
+ return r
+
class OgCLI():
def __init__(self, cfg):
self.rest = OgREST(cfg['ip'], cfg['port'], cfg['api_token'])