【发布时间】:2021-04-04 11:08:14
【问题描述】:
我有类方法wait_for_operation,我想从中调用类属性并生成一个我想与类方法一起使用的新客户端。
def get_new_bearer_token():
return "new_token"
class MyClass(object):
def __init__(self, json):
self.json = json
@property
def client(self):
k8_loader = kube_config.KubeConfigLoader(self.json)
call_config = type.__call__(Configuration)
k8_loader.load_and_set(call_config)
Configuration.set_default(call_config)
return client
@classmethod
def wait_for_operation(self, kube_config, cloud):
while True:
if cloud == "AWS":
kube_config['users'][0]['user']['token'] = get_new_bearer_token()
self.json = kube_config
#call class property to generate a new client with token and use it
if __name__ == '__main__':
kube_config = {}
my_client = MyClass(json=kube_config)
my_client.client.CoreV1Api().list_namespace(watch=False)
result = MyClass.wait_for_operation(kube_config=kube_config,cloud='AWS')
【问题讨论】:
标签: python-3.x oop kubernetes