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 (
34+ data ["project" ]["href" ], type = "GET"
35+ )
36+ self .project = Project (project_data , self .manager )
37+ except (KeyError , IndexError ):
38+ self .attached_to = None
39+
40+ # endpoint is not working yet
41+ #try:
42+ # facility_data = self.manager.call_api(
43+ # data["facility"]["href"], type="GET"
44+ # )
45+ # self.project = Facility(facility_data, self.manager)
46+ #except (KeyError, IndexError):
47+ # self.attached_to = None
48+
49+ try :
50+ device_data = self .manager .call_api (
51+ data ["device" ]["href" ], type = "GET"
52+ )
53+ self .device = Device (device_data , self .manager )
54+ except (KeyError , IndexError ):
55+ self .attached_to = None
56+
57+ def __str__ (self ):
58+ return "%s" % self .id
59+
60+ def __repr__ (self ):
61+ return "{}: {}" .format (self .__class__ .__name__ , self .id )
62+
63+ def __getitem__ (self , item ):
64+ return getattr (self , item )
0 commit comments