|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# SPDX-License-Identifier: LGPL-3.0-only |
| 3 | + |
| 4 | +from .Plan import Plan |
| 5 | +from .Project import Project |
| 6 | +from .Device import Device |
| 7 | + |
| 8 | + |
| 9 | +class HardwareReservation: |
| 10 | + def __init__(self, data, manager): |
| 11 | + self.manager = manager |
| 12 | + |
| 13 | + self.id = data.get("id") |
| 14 | + self.created_at = data.get("created_at") |
| 15 | + self.billing_cycle = data.get("billing_cycle") |
| 16 | + self.created_at = data.get("created_at") |
| 17 | + self.short_id = data.get("short_id") |
| 18 | + self.intervals = data.get("intervals") |
| 19 | + self.current_period = data.get("current_period") |
| 20 | + self.started_at = data.get("started_at") |
| 21 | + self.custom_rate = data.get("custom_rate") |
| 22 | + self.remove_at = data.get("remove_at") |
| 23 | + self.project = data.get("project") |
| 24 | + # self.facility = data.get("facility") |
| 25 | + self.device = data.get("device") |
| 26 | + self.provisionable = data.get("provisionable") |
| 27 | + self.spare = data.get("spare") |
| 28 | + self.need_of_service = data.get("need_of_service") |
| 29 | + self.plan = Plan(data.get("plan")) |
| 30 | + self.switch_uuid = data.get("switch_uuid") |
| 31 | + |
| 32 | + try: |
| 33 | + project_data = self.manager.call_api(data["project"]["href"], type="GET") |
| 34 | + self.project = Project(project_data, self.manager) |
| 35 | + except (KeyError, IndexError): |
| 36 | + self.attached_to = None |
| 37 | + |
| 38 | + # endpoint is not working yet |
| 39 | + # try: |
| 40 | + # facility_data = self.manager.call_api( |
| 41 | + # data["facility"]["href"], type="GET" |
| 42 | + # ) |
| 43 | + # self.project = Facility(facility_data, self.manager) |
| 44 | + # except (KeyError, IndexError): |
| 45 | + # self.attached_to = None |
| 46 | + |
| 47 | + try: |
| 48 | + device_data = self.manager.call_api(data["device"]["href"], type="GET") |
| 49 | + self.device = Device(device_data, self.manager) |
| 50 | + except (KeyError, IndexError): |
| 51 | + self.attached_to = None |
| 52 | + |
| 53 | + def __str__(self): |
| 54 | + return "%s" % self.id |
| 55 | + |
| 56 | + def __repr__(self): |
| 57 | + return "{}: {}".format(self.__class__.__name__, self.id) |
| 58 | + |
| 59 | + def __getitem__(self, item): |
| 60 | + return getattr(self, item) |
0 commit comments