base.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:openshift-restclient-python 作者: openshift 项目源码 文件源码
def get_object(self, name=None, namespace=None):
        k8s_obj = None
        method_name = 'list' if self.kind.endswith('list') else 'read'
        try:
            get_method = self.lookup_method(method_name, namespace)
            if name is None and namespace is None:
                k8s_obj = get_method()
            elif name and namespace is None:
                k8s_obj = get_method(name)
            elif namespace and not name:
                k8s_obj = get_method(namespace)
            else:
                k8s_obj = get_method(name, namespace)
        except ApiException as exc:
            if exc.status != 404:
                if self.base_model_name == 'Project'and exc.status == 403:
                    pass
                else:
                    msg = json.loads(exc.body).get('message', exc.reason) if exc.body.startswith('{') else exc.body
                    raise self.get_exception_class()(msg, status=exc.status)
        except MaxRetryError as ex:
            raise self.get_exception_class()(str(ex.reason))

        return k8s_obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号