summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-01-24 09:04:15 +0200
committerLars Wirzenius <liw@liw.fi>2019-01-24 09:04:15 +0200
commit9570f628ec485cb2fe52685555103dfe2a89e596 (patch)
tree8645424e602769008edeb064675515a84b41e234
parent376fe411eb45fbf4c2d38b75b440e281336bcc27 (diff)
downloadeffitool-9570f628ec485cb2fe52685555103dfe2a89e596.tar.gz
Add: status subcommand
-rw-r--r--README4
-rwxr-xr-xeffitool38
2 files changed, 40 insertions, 2 deletions
diff --git a/README b/README
index de4a787..ccc3425 100644
--- a/README
+++ b/README
@@ -39,9 +39,9 @@ The list of known servers can be listed:
Usage:
-----------------------------------------------------------------------------
-To check the version of the membership register:
+To check the status of the membership register:
- ./effitool version
+ ./effitool status
Legalese
-----------------------------------------------------------------------------
diff --git a/effitool b/effitool
index 35c03c0..1032da5 100755
--- a/effitool
+++ b/effitool
@@ -18,11 +18,15 @@
import argparse
import configparser
+import http
+import json
import os
import sys
+import urllib.request
CONFIG_FILENAME = os.path.expanduser('~/.config/effitool/credentials.conf')
+JSON = 'application/json'
class Config:
@@ -49,6 +53,30 @@ class Config:
}
+class HTTPAPI:
+
+ def __init__(self, url):
+ self._url = url
+
+ def url(self, path):
+ return '{}{}'.format(self._url, path)
+
+ def get(self, path):
+ url = self.url(path)
+ with urllib.request.urlopen(url) as r:
+ status = r.getcode()
+ if status != http.HTTPStatus.OK:
+ raise Exception('Got HTTP status {}'.format(status))
+
+ info = r.info()
+ ct = info.get_content_type()
+ if ct != JSON:
+ raise Exception('Response is not JSON: {}'.ct)
+
+ body = r.read()
+ return json.loads(body)
+
+
def list_servers(args, config):
for name in config.servers():
print('server', name)
@@ -57,9 +85,19 @@ def list_servers(args, config):
print(' ', key, server[key])
+def status(args, config):
+ for name in config.servers():
+ server = config.get(name)
+ url = server['url']
+ api = HTTPAPI(url)
+ obj = api.get('/status')
+ print('server', name, obj['resources'])
+
+
def process_args(config):
subcommands = [
('list-servers', list_servers),
+ ('status', status),
]
p = argparse.ArgumentParser()