def main(): import docopt from model import Customer opt = docopt.docopt(__doc__) tenant_id = opt["--tenant"] customer_id = opt["--customer"] if customer_id: try: customer_id = int(customer_id) customer = Customer.get_by_id(customer_id) except ValueError: customer = Customer.get_by_email(customer_id) if not customer: logbook.warning("Customer {} not found", customer_id) return else: tenant_id = customer.tenant.tenant_id start = opt["--start"] end = opt["--end"] now = arrow.utcnow().date() start = arrow.get(start) if start else now - timedelta(minutes=15) end = arrow.get(end) if end else now metric = opt["--metric"] service = opt["--service"] if service: service_mapping = {data["service"]: name for name, data in conf.fitter.collection.meter_mappings.items()} if service not in service_mapping: logbook.warning("Service {} not found", service) return metric = service_mapping[service] samples = openstack.get_tenant_usage(tenant_id, metric, start, end, limit=int(opt["--limit"])) logbook.info("Found {} samples", len(samples)) for s in samples: pprint(s._info)