Exemplo n.º 1
0
 def _build_with_model(self, model=None):
     if 'accessModes' in model:
         self.access_modes = model['accessModes']
     if 'resources' in model:
         self.resources = ResourceRequirements(model['resources'])
     if 'storageClassName' in model:
         self.storage_class_name = model['storageClassName']
     if 'selector' in model:
         self.selector = LabelSelector(model['selector'])
     if 'volumeName' in model:
         self.volume_name = model['volumeName']
 def _build_with_model(self, model=None):
     if "accessModes" in model:
         self.access_modes = model["accessModes"]
     if "resources" in model:
         self.resources = ResourceRequirements(model["resources"])
     if "storageClassName" in model:
         self.storage_class_name = model["storageClassName"]
     if "selector" in model:
         self.selector = LabelSelector(model["selector"])
     if "volumeName" in model:
         self.volume_name = model["volumeName"]
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def __init__(self, model=None):
        super(Container, self).__init__()

        self._args = None
        self._command = None
        self._env = []
        self._image = None
        self._image_pull_policy = 'IfNotPresent'
        self._liveness_probe = None
        self._name = None
        self._ports = None
        self._readiness_probe = None
        self._resources = ResourceRequirements()
        self._security_context = SecurityContext()
        self._volume_mounts = []
        self._working_dir = None

        self.resources.requests = {
            'cpu': '100m',
            'memory': '32M'
        }

        if model is not None:
            m = filter_model(model)
            self._build_with_model(m)
Exemplo n.º 5
0
    def __init__(self, model=None):
        super(PersistentVolumeClaimSpec, self).__init__()

        self._access_modes = []
        self._selector = LabelSelector()
        self._resources = ResourceRequirements()
        self._volume_name = None
        self._storage_class_name = ""

        self.access_modes = ['ReadWriteOnce']
        self.resources.requests = {'storage': '10Gi'}

        if model is not None:
            self._build_with_model(model)
Exemplo n.º 6
0
 def _build_with_model(self, model=None):
     if "args" in model:
         self.args = model["args"]
     if "command" in model:
         self.command = model["command"]
     if "env" in model:
         envs = []
         for e in model["env"]:
             env = EnvVar(e)
             envs.append(env)
         self.env = envs
     if "image" in model:
         self.image = model["image"]
     if "imagePullPolicy" in model:
         self.image_pull_policy = model["imagePullPolicy"]
     if "livenessProbe" in model:
         self.liveness_probe = Probe(model["livenessProbe"])
     if "name" in model:
         self.name = model["name"]
     if "ports" in model:
         ports = []
         for p in model["ports"]:
             port = ContainerPort(p)
             ports.append(port)
         self.ports = ports
     if "readinessProbe" in model:
         self.readiness_probe = Probe(model["readinessProbe"])
     if "resources" in model:
         r = ResourceRequirements(model["resources"])
         self.resources = r
     if "securityContext" in model:
         self.security_context = SecurityContext(model["securityContext"])
     if "terminationMessagePath" in model:
         self.termination_message_path = model["terminationMessagePath"]
     if "volumeMounts" in model:
         mounts = []
         for v in model["volumeMounts"]:
             mount = VolumeMount(v)
             mounts.append(mount)
         self.volume_mounts = mounts
     if "workingDir" in model:
         self.working_dir = model["workingDir"]
Exemplo n.º 7
0
 def _build_with_model(self, model=None):
     if 'args' in model:
         self.args = model['args']
     if 'command' in model:
         self.command = model['command']
     if 'env' in model:
         envs = []
         for e in model['env']:
             env = EnvVar(e)
             envs.append(env)
         self.env = envs
     if 'image' in model:
         self.image = model['image']
     if 'imagePullPolicy' in model:
         self.image_pull_policy = model['imagePullPolicy']
     if 'livenessProbe' in model:
         self.liveness_probe = Probe(model['livenessProbe'])
     if 'name' in model:
         self.name = model['name']
     if 'ports' in model:
         ports = []
         for p in model['ports']:
             port = ContainerPort(p)
             ports.append(port)
         self.ports = ports
     if 'readinessProbe' in model:
         self.readiness_probe = Probe(model['readinessProbe'])
     if 'resources' in model:
         r = ResourceRequirements(model['resources'])
         self.resources = r
     if 'securityContext' in model:
         self.security_context = SecurityContext(model['securityContext'])
     if 'terminationMessagePath' in model:
         self.termination_message_path = model['terminationMessagePath']
     if 'volumeMounts' in model:
         mounts = []
         for v in model['volumeMounts']:
             mount = VolumeMount(v)
             mounts.append(mount)
         self.volume_mounts = mounts
     if 'workingDir' in model:
         self.working_dir = model['workingDir']
Exemplo n.º 8
0
 def resources(self, res=None):
     r = ResourceRequirements(res)
     self.model.resources = r
Exemplo n.º 9
0
class PersistentVolumeClaimSpec(object):
    """
    http://kubernetes.io/docs/api-reference/v1/definitions/#_v1_persistentvolumeclaimspec
    """

    VALID_RESOURCES = ['storage']

    def __init__(self, model=None):
        super(PersistentVolumeClaimSpec, self).__init__()

        self._access_modes = []
        self._selector = LabelSelector()
        self._resources = ResourceRequirements()
        self._volume_name = None
        self._storage_class_name = ""

        self.access_modes = ['ReadWriteOnce']
        self.resources.requests = {'storage': '10Gi'}

        if model is not None:
            self._build_with_model(model)

    def _build_with_model(self, model=None):
        if 'accessModes' in model:
            self.access_modes = model['accessModes']
        if 'resources' in model:
            self.resources = ResourceRequirements(model['resources'])
        if 'storageClassName' in model:
            self.storage_class_name = model['storageClassName']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'volumeName' in model:
            self.volume_name = model['volumeName']

    # ------------------------------------------------------------------------------------- accessModes

    @property
    def access_modes(self):
        return self._access_modes

    @access_modes.setter
    def access_modes(self, modes=None):
        if not is_valid_list(modes, str):
            raise SyntaxError(
                'PersistentVolumeClaimSpec: access_modes: [ {} ] is invalid.'.
                format(modes))
        filtered = list(
            filter(lambda x: x in PersistentVolumeSpec.VALID_ACCESS_MODES,
                   modes))
        self._access_modes = filtered

    # ------------------------------------------------------------------------------------- resources

    @property
    def resources(self):
        return self._resources

    @resources.setter
    def resources(self, res=None):
        if not isinstance(res, ResourceRequirements):
            raise SyntaxError(
                'PersistentVolumeClaimSpec: resources: [ {} ] is invalid.'.
                format(res))
        self._resources = res

    # ------------------------------------------------------------------------------------- selector

    @property
    def selector(self):
        return self._selector

    @selector.setter
    def selector(self, sel=None):
        if not isinstance(sel, LabelSelector):
            raise SyntaxError(
                'PersistentVolumeClaimSpec: selector: [ {} ] is invalid.'.
                format(sel))
        self._selector = sel

    # ------------------------------------------------------------------------------------- storage_class_name

    @property
    def storage_class_name(self):
        return self._storage_class_name

    @storage_class_name.setter
    def storage_class_name(self, name=None):
        if not is_valid_string(name):
            raise SyntaxError(
                'PersistentVolumeClaimSpec: storage_class_name: [ {} ] is invalid.'
                .format(name))
        self._storage_class_name = name

    # ------------------------------------------------------------------------------------- volumeName

    @property
    def volume_name(self):
        return self._volume_name

    @volume_name.setter
    def volume_name(self, name=None):
        if not is_valid_string(name):
            raise SyntaxError(
                'PersistentVolumeClaimSpec: volume_name: [ {} ] is invalid.'.
                format(name))
        self._volume_name = name

    # ------------------------------------------------------------------------------------- serialize

    def serialize(self):
        data = {}
        if self.access_modes is not None:
            data['accessModes'] = self.access_modes
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.storage_class_name is not None:
            data['storageClassName'] = self.storage_class_name
        if self.resources is not None:
            data['resources'] = self.resources.serialize()
        if self.volume_name is not None:
            data['volumeName'] = self.volume_name
        return data