diff --git a/ungleich b/ungleich index dc99669..5433491 100755 --- a/ungleich +++ b/ungleich @@ -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 = {} diff --git a/ungleich_pay.py b/ungleich_pay.py new file mode 100644 index 0000000..623880e --- /dev/null +++ b/ungleich_pay.py @@ -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)