added basic python client and a basic commandline tool.
This commit is contained in:
30
client/client.py
Normal file
30
client/client.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class Client(object):
|
||||||
|
|
||||||
|
def __init__(self, endpoint, **kwargs):
|
||||||
|
self.endpoint = endpoint
|
||||||
|
self.auth_token = kwargs.get('token')
|
||||||
|
|
||||||
|
def usage(self, tenants):
|
||||||
|
url = self.endpoint + "usage"
|
||||||
|
data = {"tenants": tenants}
|
||||||
|
response = requests.post(url,
|
||||||
|
headers={"Content-Type": "application/json",
|
||||||
|
"token": self.auth_token},
|
||||||
|
data=data)
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise AttributeError("Usage cycle failed: " + response.text +
|
||||||
|
" code: " + str(response.status_code))
|
||||||
|
|
||||||
|
def sales_order(self, tenants):
|
||||||
|
url = self.endpoint + "sales_order"
|
||||||
|
data = {"tenants": tenants}
|
||||||
|
response = requests.post(url,
|
||||||
|
headers={"Content-Type": "application/json",
|
||||||
|
"token": self.auth_token},
|
||||||
|
data=data)
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise AttributeError("Sales order cycle failed: " + response.text +
|
||||||
|
" code: " + str(response.status_code))
|
||||||
52
client/shell.py
Normal file
52
client/shell.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# import sys
|
||||||
|
from client import Client
|
||||||
|
|
||||||
|
# import yaml
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
subparsers = parser.add_subparsers(help='commands', dest='command')
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-c", "--config", dest="config",
|
||||||
|
help="Config file",
|
||||||
|
default="/etc/artifice/conf.yaml")
|
||||||
|
|
||||||
|
usage_parser = subparsers.add_parser('usage', help=('process usage' +
|
||||||
|
' for given tenants'))
|
||||||
|
usage_parser.add_argument(
|
||||||
|
"-t", "--tenant", dest="tenants",
|
||||||
|
help='Tenants to process usage for.',
|
||||||
|
action="append", default=[])
|
||||||
|
|
||||||
|
sales_parser = subparsers.add_parser('sales-order',
|
||||||
|
help=('create sales orders for '
|
||||||
|
'given tenants'))
|
||||||
|
sales_parser.add_argument(
|
||||||
|
"-t", "--tenant", dest="tenants",
|
||||||
|
help='Tenants to create sales orders for.',
|
||||||
|
action="append", default=[])
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
conf = {'api': {'endpoint': 'http://0.0.0.0/',
|
||||||
|
'token': 'sah324sdf5wad4dh839uhjuUH'}}
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# conf = yaml.load(open(args.config).read())
|
||||||
|
# except IOError:
|
||||||
|
# print "couldn't load %s " % args.config
|
||||||
|
# sys.exit(1)
|
||||||
|
|
||||||
|
client = Client(conf["api"]["endpoint"],
|
||||||
|
token=conf["api"]["token"])
|
||||||
|
|
||||||
|
if args.command == 'usage':
|
||||||
|
client.usage(args.tenants)
|
||||||
|
|
||||||
|
if args.command == 'sales-order':
|
||||||
|
client.sales_order(args.tenants)
|
||||||
Reference in New Issue
Block a user