Exemple #1
0
class DaemonSetSpec(object):

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

        self._selector = LabelSelector()
        self._template = PodTemplateSpec()

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

    def _build_with_model(self, model=None):
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError(
                'DaemonSetSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

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

    def serialize(self):
        data = {}
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.template is not None:
            data['template'] = self.template.serialize()
        return data
class DaemonSetSpec(object):
    def __init__(self, model=None):
        super(DaemonSetSpec, self).__init__()

        self._selector = LabelSelector()
        self._template = PodTemplateSpec()

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

    def _build_with_model(self, model=None):
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError(
                'DaemonSetSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

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

    def serialize(self):
        data = {}
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.template is not None:
            data['template'] = self.template.serialize()
        return data
Exemple #3
0
class JobSpec(object):
    """
    http://kubernetes.io/docs/api-reference/batch/v1/definitions/#_v1_jobspec
    """

    VALID_RESTART_POLICIES = ['OnFailure', 'Never']

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

        self._parallelism = None
        self._completions = None
        self._active_deadline_seconds = None
        self._selector = None
        self._manual_selector = None
        self._template = PodTemplateSpec()

        self.template.spec.VALID_RESTART_POLICIES = JobSpec.VALID_RESTART_POLICIES
        if self.template.spec.restart_policy not in JobSpec.VALID_RESTART_POLICIES:
            self.template.spec.restart_policy = 'OnFailure'

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

    def _build_with_model(self, model=None):
        if 'parallelism' in model:
            self.parallelism = model['parallelism']
        if 'completions' in model:
            self.completions = model['completions']
        if 'activeDeadlineSeconds' in model:
            self.active_deadline_seconds = model['activeDeadlineSeconds']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'manualSelector' in model:
            self.manual_selector = model['manualSelector']
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])

    # --------------------------------------------------------------------------------- parallelism

    # .parallelism can be set to any non-negative value. If it is unspecified, it defaults to 1.
    #  If it is specified as 0, then the Job is effectively paused until it is increased.

    @property
    def parallelism(self):
        return self._parallelism

    @parallelism.setter
    def parallelism(self, p=None):
        if not isinstance(p, int) or not p >= 0:
            raise SyntaxError(
                'JobSpec: parallelism: [ {} ] is invalid.'.format(p))
        self._parallelism = p

    # --------------------------------------------------------------------------------- completions

    @property
    def completions(self):
        return self._completions

    @completions.setter
    def completions(self, c=None):
        if not isinstance(c, int) or not c >= 0:
            raise SyntaxError(
                'JobSpec: completions: [ {} ] is invalid.'.format(c))
        self._completions = c

    # --------------------------------------------------------------------------------- activeDeadlineSeconds

    @property
    def active_deadline_seconds(self):
        return self._active_deadline_seconds

    @active_deadline_seconds.setter
    def active_deadline_seconds(self, ads=None):
        if not isinstance(ads, int) or not ads >= 0:
            raise SyntaxError(
                'JobSpec: active_deadline_seconds: [ {} ] is invalid.'.format(
                    ads))
        self._active_deadline_seconds = ads

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

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

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

    # --------------------------------------------------------------------------------- manualSelector

    # Leave manualSelector unset unless you are certain of what you are doing.

    @property
    def manual_selector(self):
        return self._manual_selector

    @manual_selector.setter
    def manual_selector(self, s=False):
        if not isinstance(s, bool):
            raise SyntaxError(
                'JobSpec: manual_selector: [ {} ] is invalid.'.format(s))
        self._manual_selector = s

    # --------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError(
                'JobSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

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

    def serialize(self):
        data = {}
        if self.parallelism is not None:
            data['parallelism'] = self.parallelism
        if self.completions is not None:
            data['completions'] = self.completions
        if self.active_deadline_seconds is not None:
            data['activeDeadlineSeconds'] = self.active_deadline_seconds
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.manual_selector is not None:
            data['manualSelector'] = self.manual_selector
        if self.template is not None:
            data['template'] = self.template.serialize()
        return data
class StatefulSetSpec(object):
    def __init__(self, model=None):
        super(StatefulSetSpec, self).__init__()

        self._replicas = None
        self._selector = None
        self._template = None
        self._volume_claim_templates = None
        self._service_name = None

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

    def _build_with_model(self, model=None):
        if 'replicas' in model:
            self.replicas = model['replicas']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])
        if 'volumeClaimTemplates' in model:
            vcts = [
                PersistentVolumeClaim(x) for x in model['volumeClaimTemplates']
            ]
            self.volume_claim_templates = vcts
        if 'serviceName' in model:
            self.service_name = model['serviceName']

    # ------------------------------------------------------------------------------------- replicas

    @property
    def replicas(self):
        return self._replicas

    @replicas.setter
    def replicas(self, r=None):
        if not isinstance(r, int):
            raise SyntaxError(
                'StatefulSetSpec: replicas: [ {} ] is invalid.'.format(r))
        self._replicas = r

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError(
                'StatefulSetSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

    # ------------------------------------------------------------------------------------- volumeClaimTemplates

    @property
    def volume_claim_templates(self):
        return self._volume_claim_templates

    @volume_claim_templates.setter
    def volume_claim_templates(self, vcts=None):
        if not is_valid_list(vcts, PersistentVolumeClaim):
            raise SyntaxError(
                'StatefulSetSpec: volume_claim_templates: [ {} ] is invalid.'.
                format(vcts))
        self._volume_claim_templates = vcts

    # ------------------------------------------------------------------------------------- serviceName

    @property
    def service_name(self):
        return self._service_name

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

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

    def serialize(self):
        data = {}
        if self.replicas is not None:
            data['replicas'] = self.replicas
        if self.selector is not None:
            data['selector'] = self.selector
        if self.template is not None:
            data['template'] = self.template.serialize()
        if self.volume_claim_templates is not None:
            data['volumeClaimTemplates'] = [
                x.serialize() for x in self.volume_claim_templates
            ]
        if self.service_name is not None:
            data['serviceName'] = self.service_name
        return data
Exemple #5
0
class DeploymentSpec(object):
    """
    http://kubernetes.io/docs/api-reference/extensions/v1beta1/definitions/#_v1beta1_deploymentspec
    """

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

        self._replicas = 1
        self._selector = LabelSelector()
        self._template = PodTemplateSpec()
        self._strategy = DeploymentStrategy()
        self._min_ready_seconds = 0
        self._revision_history_limit = None
        self._paused = False
        self._rollback_to = None

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

    def _build_with_model(self, model=None):
        if 'replicas' in model:
            self.replicas = model['replicas']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])
        if 'strategy' in model:
            self.strategy = DeploymentStrategy(model['strategy'])
        if 'minReadySeconds' in model:
            self.min_ready_seconds = model['minReadySeconds']
        if 'revisionHistoryLimit' in model:
            self.revision_history_limit = model['revisionHistoryLimit']
        if 'paused' in model:
            self.paused = model['paused']
        if 'rollbackTo' in model:
            self.rollback_to = model['rollbackTo']

    # ------------------------------------------------------------------------------------- replicas

    @property
    def replicas(self):
        return self._replicas

    @replicas.setter
    def replicas(self, reps=None):
        if not isinstance(reps, int):
            raise SyntaxError('DeploymentSpec: replicas: [ {} ] is invalid'.format(reps))
        self._replicas = reps

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError('DeploymentSpec: template: [ {} ] is invalid'.format(t))
        self._template = t

    # ------------------------------------------------------------------------------------- strategy

    @property
    def strategy(self):
        return self._strategy

    @strategy.setter
    def strategy(self, strat=None):
        if not isinstance(strat, DeploymentStrategy):
            raise SyntaxError('DeploymentSpec: strategy: [ {} ] is invalid'.format(strat))
        self._strategy = strat

    # ------------------------------------------------------------------------------------- minReadySeconds

    @property
    def min_ready_seconds(self):
        return self._min_ready_seconds

    @min_ready_seconds.setter
    def min_ready_seconds(self, mrs=None):
        if not isinstance(mrs, int):
            raise SyntaxError('DeploymentSpec: min_ready_seconds: [ {} ] is invalid'.format(mrs))
        self._min_ready_seconds = mrs

    # ------------------------------------------------------------------------------------- revisionHistoryLimit

    @property
    def revision_history_limit(self):
        return self._revision_history_limit

    @revision_history_limit.setter
    def revision_history_limit(self, rhl=None):
        if not isinstance(rhl, int):
            raise SyntaxError('DeploymentSpec: revision_history_limit: [ {} ] is invalid'.format(rhl))
        self._revision_history_limit = rhl

    # ------------------------------------------------------------------------------------- paused

    @property
    def paused(self):
        return self._paused

    @paused.setter
    def paused(self, p=None):
        if not isinstance(p, bool):
            raise SyntaxError('DeploymentSpec: paused: [ {} ] is invalid'.format(p))
        self._paused = p

    # ------------------------------------------------------------------------------------- rollbackTo

    @property
    def rollback_to(self):
        return self._rollback_to

    @rollback_to.setter
    def rollback_to(self, rc=None):
        if not isinstance(rc, RollbackConfig):
            raise SyntaxError('DeploymentSpec: rollback_to: [ {} ] is invalid'.format(rc))
        self._rollback_to = rc

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

    def serialize(self):
        data = {}
        if self.replicas is not None:
            data['replicas'] = self.replicas
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.template is not None:
            data['template'] = self.template.serialize()
        if self.strategy is not None:
            data['strategy'] = self.strategy.serialize()
        if self.min_ready_seconds is not None:
            data['minReadySeconds'] = self.min_ready_seconds
        if self.revision_history_limit is not None:
            data['revisionHistoryLimit'] = self.revision_history_limit
        if self.paused is not None:
            data['paused'] = self.paused
        if self.rollback_to is not None:
            data['rollbackTo'] = self.rollback_to.serialize()
        return data
Exemple #6
0
class ReplicaSetSpec(object):
    """
    http://kubernetes.io/docs/api-reference/extensions/v1beta1/definitions/#_v1beta1_replicasetspec
    """

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

        self._replicas = 0
        self._selector = LabelSelector()
        self._template = PodTemplateSpec()

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

    def _build_with_model(self, model=None):
        if 'replicas' in model:
            self.replicas = model['replicas']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])

    # ------------------------------------------------------------------------------------- replicas

    @property
    def replicas(self):
        return self._replicas

    @replicas.setter
    def replicas(self, reps=None):
        if not isinstance(reps, int):
            raise SyntaxError('ReplicaSetSpec: replicas: [ {} ] is invalid.'.format(reps))
        self._replicas = reps

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError('ReplicaSetSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

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

    def serialize(self):
        data = {}
        if self.replicas is not None:
            data['replicas'] = self.replicas
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.template is not None:
            data['template'] = self.template.serialize()
        return data
class StatefulSetSpec(object):

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

        self._replicas = None
        self._selector = None
        self._template = None
        self._volume_claim_templates = None
        self._service_name = None

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

    def _build_with_model(self, model=None):
        if 'replicas' in model:
            self.replicas = model['replicas']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])
        if 'volumeClaimTemplates' in model:
            vcts = [PersistentVolumeClaim(x) for x in model['volumeClaimTemplates']]
            self.volume_claim_templates = vcts
        if 'serviceName' in model:
            self.service_name = model['serviceName']

    # ------------------------------------------------------------------------------------- replicas

    @property
    def replicas(self):
        return self._replicas

    @replicas.setter
    def replicas(self, r=None):
        if not isinstance(r, int):
            raise SyntaxError('StatefulSetSpec: replicas: [ {} ] is invalid.'.format(r))
        self._replicas = r

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError('StatefulSetSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

    # ------------------------------------------------------------------------------------- volumeClaimTemplates

    @property
    def volume_claim_templates(self):
        return self._volume_claim_templates

    @volume_claim_templates.setter
    def volume_claim_templates(self, vcts=None):
        if not is_valid_list(vcts, PersistentVolumeClaim):
            raise SyntaxError('StatefulSetSpec: volume_claim_templates: [ {} ] is invalid.'.format(vcts))
        self._volume_claim_templates = vcts

    # ------------------------------------------------------------------------------------- serviceName

    @property
    def service_name(self):
        return self._service_name

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

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

    def serialize(self):
        data = {}
        if self.replicas is not None:
            data['replicas'] = self.replicas
        if self.selector is not None:
            data['selector'] = self.selector
        if self.template is not None:
            data['template'] = self.template.serialize()
        if self.volume_claim_templates is not None:
            data['volumeClaimTemplates'] = [x.serialize() for x in self.volume_claim_templates]
        if self.service_name is not None:
            data['serviceName'] = self.service_name
        return data
Exemple #8
0
class PetSetSpec(object):
    """
    http://kubernetes.io/docs/api-reference/apps/v1alpha1/definitions/#_v1alpha1_petsetspec
    """

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

        self._replicas = 1
        self._selector = LabelSelector()
        self._template = PodTemplateSpec()
        self._volume_claim_templates = []
        self._service_name = None

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

    def _build_with_model(self, model=None):
        if 'replicas' in model:
            self.replicas = model['replicas']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])
        if 'volumeClaimTemplates' in model:
            claims = []
            for x in model['volumeClaimTemplates']:
                claim = PersistentVolumeClaim(x)
                claims.append(claim)
            self.volume_claim_templates = claims
        if 'serviceName' in model:
            self.service_name = model['serviceName']

    # ------------------------------------------------------------------------------------- replicas

    @property
    def replicas(self):
        return self._replicas

    @replicas.setter
    def replicas(self, r=None):
        if not isinstance(r, int):
            raise SyntaxError('PetSetSpec: replicas: [ {} ] is invalid.'.format(r))
        self._replicas = r

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

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

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

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError('PetSetSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

    # ------------------------------------------------------------------------------------- volumeClaimTemplates

    @property
    def volume_claim_templates(self):
        return self._volume_claim_templates

    @volume_claim_templates.setter
    def volume_claim_templates(self, t=None):
        if not is_valid_list(t, PersistentVolumeClaim):
            raise SyntaxError('PetSetSpec: volume_claim_templates: [ {} ] is invalid.'.format(t))
        self._volume_claim_templates = t

    # ------------------------------------------------------------------------------------- serviceName

    @property
    def service_name(self):
        return self._service_name

    @service_name.setter
    def service_name(self, sn=None):
        if not is_valid_string(sn):
            raise SyntaxError('PetSetSpec: service_name: [ {} ] is invalid.'.format(sn))
        self._service_name = sn

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

    def serialize(self):
        data = {}
        if self.replicas is not None:
            data['replicas'] = self.replicas
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.template is not None:
            data['template'] = self.template.serialize()
        if self.volume_claim_templates is not None:
            data['volumeClaimTemplates'] = [x.serialize() for x in self.volume_claim_templates]
        if self.service_name is not None:
            data['serviceName'] = self.service_name
        return data
Exemple #9
0
class ReplicationControllerSpec(object):
    """
    http://kubernetes.io/docs/api-reference/v1/definitions/#_v1_replicationcontrollerspec
    """

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

        self._replicas = 0
        self._selector = {}
        self._template = PodTemplateSpec()

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

    def _build_with_model(self, model=None):
        if 'replicas' in model:
            self.replicas = model['replicas']
        if 'selector' in model:
            self.selector = model['selector']
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])

    # ------------------------------------------------------------------------------------- template

    @property
    def replicas(self):
        return self._replicas

    @replicas.setter
    def replicas(self, replicas=None):
        if not isinstance(replicas, int) or not replicas >= 0:
            raise SyntaxError('ReplicationControllerSpec: replicas: [ {0} ] is invalid.'.format(replicas))
        self._replicas = replicas

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

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

    @selector.setter
    def selector(self, selector=None):
        if not is_valid_dict(selector):
            raise SyntaxError('ReplicationControllerSpec: selector: [ {0} ] is invalid.'.format(selector))
        self._selector = selector

    # ------------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, template=None):
        if not isinstance(template, PodTemplateSpec):
            raise SyntaxError('ReplicationControllerSpec: template: [ {} ] is invalid.'.format(template))
        self._template = template

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

    def serialize(self):
        data = {}
        if self.replicas is not None:
            data['replicas'] = self.replicas
        if self.selector is not None:
            data['selector'] = self.selector
        if self.template is not None:
            data['template'] = self.template.serialize()
        return data
Exemple #10
0
class JobSpec(object):
    """
    http://kubernetes.io/docs/api-reference/batch/v1/definitions/#_v1_jobspec
    """

    VALID_RESTART_POLICIES = ['OnFailure', 'Never']

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

        self._parallelism = None
        self._completions = None
        self._active_deadline_seconds = None
        self._selector = None
        self._manual_selector = None
        self._template = PodTemplateSpec()

        self.template.spec.VALID_RESTART_POLICIES = JobSpec.VALID_RESTART_POLICIES
        if self.template.spec.restart_policy not in JobSpec.VALID_RESTART_POLICIES:
            self.template.spec.restart_policy = 'OnFailure'

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

    def _build_with_model(self, model=None):
        if 'parallelism' in model:
            self.parallelism = model['parallelism']
        if 'completions' in model:
            self.completions = model['completions']
        if 'activeDeadlineSeconds' in model:
            self.active_deadline_seconds = model['activeDeadlineSeconds']
        if 'selector' in model:
            self.selector = LabelSelector(model['selector'])
        if 'manualSelector' in model:
            self.manual_selector = model['manualSelector']
        if 'template' in model:
            self.template = PodTemplateSpec(model['template'])

    # --------------------------------------------------------------------------------- parallelism

    # .parallelism can be set to any non-negative value. If it is unspecified, it defaults to 1.
    #  If it is specified as 0, then the Job is effectively paused until it is increased.

    @property
    def parallelism(self):
        return self._parallelism

    @parallelism.setter
    def parallelism(self, p=None):
        if not isinstance(p, int) or not p >= 0:
            raise SyntaxError('JobSpec: parallelism: [ {} ] is invalid.'.format(p))
        self._parallelism = p

    # --------------------------------------------------------------------------------- completions

    @property
    def completions(self):
        return self._completions

    @completions.setter
    def completions(self, c=None):
        if not isinstance(c, int) or not c >= 0:
            raise SyntaxError('JobSpec: completions: [ {} ] is invalid.'.format(c))
        self._completions = c

    # --------------------------------------------------------------------------------- activeDeadlineSeconds

    @property
    def active_deadline_seconds(self):
        return self._active_deadline_seconds

    @active_deadline_seconds.setter
    def active_deadline_seconds(self, ads=None):
        if not isinstance(ads, int) or not ads >= 0:
            raise SyntaxError('JobSpec: active_deadline_seconds: [ {} ] is invalid.'.format(ads))
        self._active_deadline_seconds = ads

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

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

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

    # --------------------------------------------------------------------------------- manualSelector

    # Leave manualSelector unset unless you are certain of what you are doing.

    @property
    def manual_selector(self):
        return self._manual_selector

    @manual_selector.setter
    def manual_selector(self, s=False):
        if not isinstance(s, bool):
            raise SyntaxError('JobSpec: manual_selector: [ {} ] is invalid.'.format(s))
        self._manual_selector = s

    # --------------------------------------------------------------------------------- template

    @property
    def template(self):
        return self._template

    @template.setter
    def template(self, t=None):
        if not isinstance(t, PodTemplateSpec):
            raise SyntaxError('JobSpec: template: [ {} ] is invalid.'.format(t))
        self._template = t

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

    def serialize(self):
        data = {}
        if self.parallelism is not None:
            data['parallelism'] = self.parallelism
        if self.completions is not None:
            data['completions'] = self.completions
        if self.active_deadline_seconds is not None:
            data['activeDeadlineSeconds'] = self.active_deadline_seconds
        if self.selector is not None:
            data['selector'] = self.selector.serialize()
        if self.manual_selector is not None:
            data['manualSelector'] = self.manual_selector
        if self.template is not None:
            data['template'] = self.template.serialize()
        return data