#6430: add customers-list feature

This commit is contained in:
PCoder 2019-08-13 12:00:19 +05:30
parent 992bd6d11b
commit 3af7d04a9a
2 changed files with 38 additions and 0 deletions

View file

@ -8,6 +8,7 @@ from ungleich_account import Account_Create
from ungleich_weather import ungleichWeather
from ungleich_ssh_key import SSHKey
from ungleich_config import Ungleich_Config
from ungleich_pay import ungleichPay
VERSION = "0.0.4"
@ -22,6 +23,7 @@ class ungleichCLI(object):
config = Ungleich_Config(self.parser, self.parser_parents)
SSHKey(self.parser, self.parser_parents)
ungleichWeather(self.parser, self.parser_parents)
ungleichPay(self.parser, self.parser_parents)
def _init_parser(self):
self.parser = {}

36
ungleich_pay.py Normal file
View file

@ -0,0 +1,36 @@
import urllib.request
import json
UNGLEICH_PAY_SERVER_URL = "https://pay.ungleich.ch"
class ungleichPay(object):
def __init__(self, parser, parents):
self.parser = parser
self.parser['customers-list'] = self.parser['sub'].add_parser(
'customers-list',
help="List customers who have an active VM at ungleich",
parents=[parents])
self.parser['username'].add_argument('--username', required=True)
self.parser['realm'].add_argument('--realm', required=True)
self.parser['token'].add_argument(
'--token', required=True,
help="A valid token obtained from ungleich"
)
self.parser['customers-list'].set_defaults(func=self.customers_list)
def customers_list(self, args):
customers_list_endpoint = "/customers-list"
request_url = UNGLEICH_PAY_SERVER_URL + customers_list_endpoint
req = urllib.request.Request(url=request_url,
method='GET',
headers={
"username": args.username,
"realm": args.realm,
"token": args.token,
"Accept": "application/json"
})
response = urllib.request.urlopen(req)
response_json = json.loads(response.read().decode('utf-8'))
print(response_json.data)