-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetering_api.py
116 lines (77 loc) · 2.41 KB
/
metering_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import sys
import argparse
import logging
from flask import Flask, request, jsonify, json
# from flask_restful import Api
# from rabbitmq_lib import get_messages
# from ceilometer_lib import ensure_config
from pprint import pprint, pformat
from metering_lib import *
app = Flask(__name__)
NAME = 'billing_api'
def _init_logger():
logger = logging.getLogger(NAME)
logger.setLevel(logging.INFO)
_init_logger()
LOG = logging.getLogger(NAME)
CONFIG = None
@app.get('/customer/<string:customer_id>')
def get_customer(customer_id):
projects = get_projects(customer_id)
json = jsonify({'customer': customer_id,
'projects': projects})
return json
@app.get('/project/<string:project_id>')
def get_project(project_id):
json = jsonify({'project': project_id})
return json
def get_projects(source="keystone", customer=None):
"""here we would have to ask odoo or something like that. out of scope"""
return jsonify({})
def _get_servers(project):
return {}
def _get_volumes(project):
return {}
def _get_attached_volumes(server):
return {}
def _get_floating_ips(project):
return {}
def _get_images(project):
return {}
def push_json(data):
json = jsonify(data)
return True
@app.route('/post_json', methods=['POST'])
def process_json():
content_type = request.headers.get('Content-Type')
if content_type == 'application/json':
json_data = request.json
LOG.debug('%s', pformat(json_data))
data = json.loads(request.data)
for message in data:
LOG.debug('message: %s', pformat(message))
push_to_sinks(CONFIG, message)
return json_data, 202
else:
return 'Content-Type not supported!', 204
def main():
logging.info('starting the billing api server')
app.run(
port=8088,
debug=True,
)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--config', '-c',
# type=argparse.FileType('r'),
dest='config_file',
default='settings.conf',
help='The config file to use'
)
parser.add_argument('-v', '--verbose', action="store_true", help='increase output verbosity')
args = parser.parse_args()
if args.verbose:
LOG.setLevel(logging.DEBUG)
CONFIG = get_config(args)
main()