Skip to content

Enable usages API #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packet/Manager.py
Original file line number Diff line number Diff line change
@@ -93,6 +93,14 @@ def list_hardware_reservations(self, project_id, params={}):
hardware_reservation = HardwareReservation(jsoned, self)
hardware_reservations.append(hardware_reservation)
return hardware_reservations

def list_project_usage(self, project_id, params={}):
data = self.call_api("projects/%s/usages" % project_id, params=params)
usages = list()
for jsoned in data["usages"]:
device = Usage(jsoned, self)
usages.append(device)
return usages

def get_hardware_reservation(self, hardware_reservation_id):
data = self.call_api("hardware-reservations/%s" % hardware_reservation_id)
22 changes: 22 additions & 0 deletions packet/Usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: LGPL-3.0-only

class Usage:
def __init__(self, data, manager):
self.manager = manager

self.facility = data.get("facility")
self.type = data.get("type")
self.name = data.get("name")
self.plan = data.get("plan")
self.plan_version = data.get("plan_version")
self.quantity = data.get("quantity")
self.unit = data.get("unit")
self.price = data.get("price")
self.total = data.get("total")

def __str__(self):
return "%s" % self.code

def __repr__(self):
return "{}: {}".format(self.__class__.__name__, self.type)