-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path__resource.py
More file actions
28 lines (21 loc) · 817 Bytes
/
__resource.py
File metadata and controls
28 lines (21 loc) · 817 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
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 api(self, tmpl, *args):
"""Return a fully-qualified Kubernetes API URL from a string template with args."""
return "/{}/{}".format(self.api_prefix, self.api_version) + tmpl.format(*args)