コード例 #1
0
    def __init__(self, config=None, obj_type=None, name=None):
        super(K8sObject, self).__init__()

        if config is not None and not isinstance(config, K8sConfig):
            raise SyntaxError(
                'K8sObject: config: [ {0} ] must be of type K8sConfig.'.format(
                    config.__class__.__name__))
        if config is None:
            config = K8sConfig()
        self.config = config

        if obj_type not in VALID_K8s_OBJS:
            valid = ", ".join(VALID_K8s_OBJS)
            raise InvalidObjectException(
                'K8sObject: obj_type: [ {0} ] must be in: [ {1} ]'.format(
                    obj_type, valid))
        self.obj_type = obj_type

        self.model = str_to_class(obj_type)
        self.name = name

        try:
            urls = BaseUrls(api=self.config.version,
                            namespace=self.config.namespace)
            self.base_url = urls.get_base_url(object_type=obj_type)
        except Exception as err:
            raise Exception(
                'Could not set BaseUrl for type: [ {0} ]'.format(obj_type))
コード例 #2
0
ファイル: K8sObject.py プロジェクト: froch/kubernetes-py
    def __init__(self, config=None, obj_type=None, name=None):
        super(K8sObject, self).__init__()

        if config is not None and not isinstance(config, K8sConfig):
            raise SyntaxError('K8sObject: config: [ {0} ] must be of type K8sConfig.'.format(config.__class__.__name__))
        if config is None:
            config = K8sConfig()
        self.config = config

        if obj_type not in VALID_K8s_OBJS:
            valid = ", ".join(VALID_K8s_OBJS)
            raise InvalidObjectException('K8sObject: obj_type: [ {0} ] must be in: [ {1} ]'.format(obj_type, valid))
        self.obj_type = obj_type

        self.model = str_to_class(obj_type)
        self.name = name

        try:
            urls = BaseUrls(api=self.config.version, namespace=self.config.namespace)
            self.base_url = urls.get_base_url(object_type=obj_type)
        except Exception as err:
            raise Exception('Could not set BaseUrl for type: [ {0} ]'.format(obj_type))