forked from linode/linode_api4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbase.py
More file actions
22 lines (16 loc) · 874 Bytes
/
Copy pathdbase.py
File metadata and controls
22 lines (16 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from linode_api4.objects import Base
class DerivedBase(Base):
"""
The DerivedBase class holds information about an object who belongs to another object
(for example, a disk belongs to a linode). These objects have their own endpoints,
but they are below another object in the hierarchy (i.e. /linodes/lnde_123/disks/disk_123)
"""
derived_url_path = '' #override in child classes
parent_id_name = 'parent_id' #override in child classes
def __init__(self, client, id, parent_id, json={}):
Base.__init__(self, client, id, json=json)
self._set(type(self).parent_id_name, parent_id)
@classmethod
def _api_get_derived(cls, parent, client):
base_url = "{}/{}".format(type(parent).api_endpoint, cls.derived_url_path)
return client._get_objects(base_url, cls, model=parent, parent_id=parent.id)