def selector(self, sel=None):
     if not is_valid_dict(sel):
         raise SyntaxError(
             'K8sPersistentVolumeClaim: selector: [ {} ] is invalid.'.
             format(sel))
     selector = LabelSelector(sel)
     self.model.spec.selector = selector
Beispiel #2
0
 def dockerconfigjson(self, secret=None):
     if not is_valid_dict(secret):
         raise SyntaxError('Secret: .dockerconfigjson: [ {} ] is invalid.'.format(secret))
     self.type = self.K8s_TYPE_DOCKER_CONFIG
     s = json.dumps(secret)
     utf = s.encode('utf-8')
     self.data = {'.dockerconfigjson': utf}
Beispiel #3
0
 def dockerconfigjson(self, secret=None):
     if not is_valid_dict(secret):
         raise SyntaxError('Secret: .dockerconfigjson: [ {} ] is invalid.'.format(secret))
     self.type = 'kubernetes.io/.dockerconfigjson'
     s = json.dumps(secret)
     utf = s.encode('utf-8')
     self.data = {'.dockerconfigjson': utf}
 def resources(self, res=None):
     if not is_valid_dict(res):
         raise SyntaxError(
             'K8sPersistentVolumeClaim: resources: [ {} ] is invalid.'.
             format(res))
     resources = ResourceRequirements(res)
     self.model.spec.resources = resources
Beispiel #5
0
 def add_selector(self, selector=None):
     if not is_valid_dict(selector):
         raise SyntaxError('Service.add_selector() selector: [ {} ] is invalid.'.format(selector))
     s = self.spec.selector
     if s is None:
         s = {}
     s.update(selector)
     self.spec.selector = s
 def http_headers(self, headers=None):
     msg = 'HTTPGetAction: headers: [ {0} ] is invalid.'.format(headers)
     if not is_valid_list(headers, dict):
         raise SyntaxError(msg)
     for x in headers:
         if not is_valid_dict(x, ['name', 'value']):
             raise SyntaxError(msg)
     self._http_headers = headers
Beispiel #7
0
 def get_with_params(self, data=None):
     if not is_valid_dict(data):
         raise SyntaxError('K8sObject.get_with_params(): data: [ {0} ] is invalid.'.format(data))
     url = '{base}'.format(base=self.base_url)
     state = self.request(method='GET', url=url, data=data)
     items = state.get('data', None).get('items', list())
     if items is None:
         return []
     return items
Beispiel #8
0
 def get_with_params(self, data=None):
     if not is_valid_dict(data):
         raise SyntaxError('K8sObject.get_with_params(): data: [ {0} ] is invalid.'.format(data))
     url = '{base}'.format(base=self.base_url)
     state = self.request(method='GET', url=url, data=data)
     items = state.get('data', None).get('items', list())
     if items is None:
         return []
     return items
Beispiel #9
0
    def get_by_labels(config=None, labels=None):
        if config is None:
            config = K8sConfig()
        if not is_valid_dict(labels):
            raise SyntaxError(
                'K8sPod.get_by_labels(): labels: [ {} ] is invalid.'.format(
                    labels))

        pods = K8sPod(config=config, name='whatever').list(labels=labels)

        return pods
Beispiel #10
0
    def data(self, data=None):
        msg = 'Secret: data: [ {0} ] is invalid.'.format(data)

        if isinstance(data, str):
            try:
                data = json.loads(data)
            except ValueError:
                raise SyntaxError(msg)

        if not is_valid_dict(data):
            raise SyntaxError(msg)

        for k, v in data.items():
            if not is_valid_string(k) or not is_valid_string(v):
                raise SyntaxError(msg)
            self._data[k] = base64.b64encode(v)
Beispiel #11
0
    def data(self, data=None):
        msg = 'Secret: data: [ {0} ] is invalid.'.format(data)

        if isinstance(data, string_types):
            try:
                data = json.loads(data)
            except ValueError:
                raise SyntaxError(msg)

        if not is_valid_dict(data):
            raise SyntaxError(msg)

        for k, v in data.items():
            if not is_valid_string(k):
                raise SyntaxError(msg)
            if not isinstance(v, bytes):
                try:
                    v = bytearray(v, 'UTF-8')
                except:
                    raise SyntaxError('Could not convert [ {0} ] to bytes.'.format(v))
            self._data[k] = base64.b64encode(v)
Beispiel #12
0
    def data(self, data=None):
        msg = 'Secret: data: [ {0} ] is invalid.'.format(data)

        if isinstance(data, string_types):
            try:
                data = json.loads(data)
            except ValueError:
                raise SyntaxError(msg)

        if not is_valid_dict(data):
            raise SyntaxError(msg)

        for k, v in data.items():
            if not is_valid_string(k):
                raise SyntaxError(msg)
            if not isinstance(v, bytes):
                try:
                    v = bytearray(v, 'UTF-8')
                except:
                    raise SyntaxError('Could not convert [ {0} ] to bytes.'.format(v))
            self._data[k] = base64.b64encode(v)
Beispiel #13
0
    def get_by_labels(config=None, labels=None):
        if config is None:
            config = K8sConfig()
        if not is_valid_dict(labels):
            raise SyntaxError(
                'K8sPod.get_by_labels(): labels: [ {} ] is invalid.'.format(labels))

        pod_list = []
        selector = ",".join(['%s=%s' % (key, value) for (key, value) in labels.items()])
        data = {'labelSelector': selector}
        p = K8sPod(config=config, name="")
        pods = p.get_with_params(data=data)

        for pod in pods:
            try:
                p = Pod(pod)
                k8s_pod = K8sPod(config=config, name=p.metadata.name).get()
                pod_list.append(k8s_pod)
            except NotFoundException:
                pass

        return pod_list
Beispiel #14
0
    def get_by_labels(config=None, labels=None):
        if config is None:
            config = K8sConfig()
        if not is_valid_dict(labels):
            raise SyntaxError(
                'K8sPod.get_by_labels(): labels: [ {} ] is invalid.'.format(
                    labels))

        pod_list = []
        selector = ",".join(
            ['%s=%s' % (key, value) for (key, value) in labels.items()])
        data = {'labelSelector': selector}
        p = K8sPod(config=config, name=labels['name'])
        pods = p.get_with_params(data=data)

        for pod in pods:
            try:
                p = Pod(pod)
                k8s_pod = K8sPod(config=config, name=p.metadata.name).get()
                pod_list.append(k8s_pod)
            except NotFoundException:
                pass

        return pod_list
Beispiel #15
0
 def labels(self, labels=None):
     if not is_valid_dict(labels):
         raise SyntaxError('Secret: labels: [ {0} ] is invalid.'.format(labels))
     self.metadata.labels = labels
Beispiel #16
0
 def selector(self, selector=None):
     if not is_valid_dict(selector):
         raise SyntaxError('ReplicationControllerSpec: selector: [ {0} ] is invalid.'.format(selector))
     self._selector = selector
 def capacity(self, c=None):
     if not is_valid_dict(c):
         raise SyntaxError('PersistentVolumeClaimStatus: capacity: [ {} ] is invalid.'.format(c))
     self._capacity = c
 def updated_annotations(self, anns=None):
     if not is_valid_dict(anns):
         raise SyntaxError('DeploymentRollback: updated_annotations: [ {} ] is invalid.'.format(anns))
     self._updated_annotations = anns
 def capacity(self, c=None):
     if not is_valid_dict(c, PersistentVolumeSpec.VALID_CAPACITY_PARAMS):
         raise SyntaxError(
             'PersistentVolumeSpec: capacity: [ {} ] is invalid.'.format(c))
     self._capacity = c
Beispiel #20
0
    def match_labels(self, ml=None):
        if not is_valid_dict(ml):
            raise SyntaxError(
                'LabelSelector: match_labels: [ {} ] is invalid.'.format(ml))

        self._match_labels = ml
Beispiel #21
0
 def string_data(self, data=None):
     if not is_valid_dict(data):
         raise SyntaxError('Secret: string_data: [ {0} ] is invalid.'.format(data))
     self._string_data = data
Beispiel #22
0
 def labels(self, labels=None):
     if not is_valid_dict(labels, type=str):
         raise SyntaxError('ObjectMeta: labels: [ {0} ] is invalid.'.format(labels))
     self._labels = labels
Beispiel #23
0
 def labels(self, labels=None):
     if not is_valid_dict(labels):
         raise SyntaxError('Secret: labels: [ {0} ] is invalid.'.format(labels))
     self.metadata.labels = labels
Beispiel #24
0
 def parameters(self, p=None):
     if not is_valid_dict(p):
         raise SyntaxError(
             'StorageClass: parameters: [ {} ] is invalid.'.format(p))
     self._parameters = p
Beispiel #25
0
 def string_data(self, data=None):
     if not is_valid_dict(data):
         raise SyntaxError('Secret: string_data: [ {0} ] is invalid.'.format(data))
     self._string_data = data
Beispiel #26
0
 def parameters(self, p=None):
     if not is_valid_dict(p):
         raise SyntaxError('StorageClass: parameters: [ {} ] is invalid.'.format(p))
     self._parameters = p
Beispiel #27
0
 def annotations(self, anns=None):
     if not is_valid_dict(anns, str):
         raise SyntaxError('ObjectMeta: annotations: [ {0} ] is invalid.'.format(anns))
     self._annotations = anns
Beispiel #28
0
    def match_labels(self, ml=None):
        if not is_valid_dict(ml):
            raise SyntaxError(
                'LabelSelector: match_labels: [ {} ] is invalid.'.format(ml))

        self._match_labels = ml
 def capacity(self, c=None):
     if not is_valid_dict(c):
         raise SyntaxError(
             'PersistentVolumeClaimStatus: capacity: [ {} ] is invalid.'.
             format(c))
     self._capacity = c
Beispiel #30
0
 def selector(self, sel=None):
     if not is_valid_dict(sel):
         raise SyntaxError(
             'ServiceSpec: selector: [ {0} ] is invalid.'.format(sel))
     self._selector = sel
 def capacity(self, c=None):
     if not is_valid_dict(c, PersistentVolumeSpec.VALID_CAPACITY_PARAMS):
         raise SyntaxError('PersistentVolumeSpec: capacity: [ {} ] is invalid.'.format(c))
     self._capacity = c
Beispiel #32
0
 def updated_annotations(self, anns=None):
     if not is_valid_dict(anns):
         raise SyntaxError('DeploymentRollback: updated_annotations: [ {} ] is invalid.'.format(anns))
     self._updated_annotations = anns