-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path__resource.py
More file actions
34 lines (26 loc) · 994 Bytes
/
__resource.py
File metadata and controls
34 lines (26 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from urllib.parse import urljoin
from django.conf import settings
from .. import KubeHTTPClient
class ResourceRegistry(type):
"""
A registry of all Resources subclassed
"""
def __init__(cls, name, bases, nmspc):
super().__init__(name, bases, nmspc)
if not hasattr(cls, 'registry'):
cls.registry = set()
cls.registry.add(cls)
cls.registry -= set(bases) # Remove base classes
# Meta methods, called on class objects:
def __iter__(cls):
return iter(cls.registry)
class Resource(KubeHTTPClient, metaclass=ResourceRegistry):
api_version = 'v1'
api_prefix = 'api'
short_name = None
def __init__(self):
super().__init__(settings.SCHEDULER_URL)
def api(self, tmpl, *args):
"""Return a fully-qualified Kubernetes API URL from a string template with args."""
url = "/{}/{}".format(self.api_prefix, self.api_version) + tmpl.format(*args)
return urljoin(self.url, url)