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'])
def _build_with_model(self, model=None): if 'labelSelector' in model: self.label_selector = LabelSelector(model['labelSelector']) if 'namespaces' in model: self.namespaces = model['namespaces'] if 'topologyKey' in model: self.topology_key = model['topologyKey']
def _build_with_model(self, model=None): if 'accessModes' in model: self.access_modes = model['accessModes'] if 'selector' in model: self.selector = LabelSelector(model['selector']) if 'resources' in model: self.resources = ResourceRequirements(model['resources']) if 'volumeName' in model: self.volume_name = model['volumeName']
def __init__(self, config=None, name=None): super(K8sDaemonSet, self).__init__(config=config, name=name, obj_type='DaemonSet') self.model.spec.template.metadata.labels = self.model.metadata.labels sel = LabelSelector() sel.match_labels = {'name': name} self.selector = sel
def __init__(self, config=None, name=None): super(K8sDaemonSet, self).__init__( config=config, name=name, obj_type='DaemonSet' ) self.model.spec.template.metadata.labels = self.model.metadata.labels sel = LabelSelector() sel.match_labels = {'name': name} self.selector = sel
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
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 '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']
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 __init__(self, config=None, name=None, image=None, replicas=0): super(K8sDeployment, self).__init__(config=config, obj_type='Deployment', name=name) self.desired_replicas = replicas labels = {'name': name} sel = LabelSelector() sel.match_labels = labels self.selector = sel self.labels = labels self.pod_labels = labels if image is not None: container = K8sContainer(name=name, image=image) self.add_container(container) if self.config.pull_secret is not None: self.add_image_pull_secrets(self.config.pull_secret)
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
def __init__(self, model=None): super(PersistentVolumeClaimSpec, self).__init__() self._access_modes = [] self._selector = LabelSelector() self._resources = ResourceRequirements() self._volume_name = None 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 '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'])
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']
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 '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']
def __init__(self, config=None, name=None, image=None, replicas=0): super(K8sDeployment, self).__init__( config=config, obj_type='Deployment', name=name ) self.desired_replicas = replicas labels = {'name': name} sel = LabelSelector() sel.match_labels = labels self.selector = sel self.labels = labels self.pod_labels = labels if image is not None: container = K8sContainer(name=name, image=image) self.add_container(container) if self.config.pull_secret is not None: self.add_image_pull_secrets(self.config.pull_secret)
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 PodAffinityTerm(object): def __init__(self, model=None): super(PodAffinityTerm, self).__init__() self._label_selector = None self._namespaces = [] self._topology_key = None if model is not None: self._build_with_model(model) def _build_with_model(self, model=None): if 'labelSelector' in model: self.label_selector = LabelSelector(model['labelSelector']) if 'namespaces' in model: self.namespaces = model['namespaces'] if 'topologyKey' in model: self.topology_key = model['topologyKey'] # ------------------------------------------------------------------------------------- labelSelector @property def label_selector(self): return self._label_selector @label_selector.setter def label_selector(self, s=None): if not isinstance(s, LabelSelector): raise SyntaxError( 'PodAffinityTerm: label_selector: [ {} ] is invalid.'.format( s)) self._label_selector = s # ------------------------------------------------------------------------------------- namespaces @property def namespaces(self): return self._namespaces @namespaces.setter def namespaces(self, n=None): if not is_valid_list(convert(n), str): raise SyntaxError( 'PodAffinityTerm: namespaces: [ {} ] is invalid.'.format(n)) self._namespaces = n # ------------------------------------------------------------------------------------- topologyKey @property def topology_key(self): return self._topology_key @topology_key.setter def topology_key(self, t=None): if not is_valid_string(t): raise SyntaxError( 'PodAffinityTerm: topology_key: [ {} ] is invalid.'.format(t)) self._topology_key = t # ------------------------------------------------------------------------------------- serialize def serialize(self): data = {} if self.label_selector is not None: data['labelSelector'] = self.label_selector.serialize() if self.namespaces: data['namespaces'] = self.namespaces if self.topology_key is not None: data['topologyKey'] = self.topology_key return data
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'])
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
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.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 'selector' in model: self.selector = LabelSelector(model['selector']) if 'resources' in model: self.resources = ResourceRequirements(model['resources']) 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 # ------------------------------------------------------------------------------------- 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 # ------------------------------------------------------------------------------------- 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 # ------------------------------------------------------------------------------------- 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.resources is not None: data['resources'] = self.resources.serialize() if self.volume_name is not None: data['volumeName'] = self.volume_name return data
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
class PodAffinityTerm(object): def __init__(self, model=None): super(PodAffinityTerm, self).__init__() self._label_selector = None self._namespaces = [] self._topology_key = None if model is not None: self._build_with_model(model) def _build_with_model(self, model=None): if 'labelSelector' in model: self.label_selector = LabelSelector(model['labelSelector']) if 'namespaces' in model: self.namespaces = model['namespaces'] if 'topologyKey' in model: self.topology_key = model['topologyKey'] # ------------------------------------------------------------------------------------- labelSelector @property def label_selector(self): return self._label_selector @label_selector.setter def label_selector(self, s=None): if not isinstance(s, LabelSelector): raise SyntaxError('PodAffinityTerm: label_selector: [ {} ] is invalid.'.format(s)) self._label_selector = s # ------------------------------------------------------------------------------------- namespaces @property def namespaces(self): return self._namespaces @namespaces.setter def namespaces(self, n=None): if not is_valid_list(convert(n), str): raise SyntaxError('PodAffinityTerm: namespaces: [ {} ] is invalid.'.format(n)) self._namespaces = n # ------------------------------------------------------------------------------------- topologyKey @property def topology_key(self): return self._topology_key @topology_key.setter def topology_key(self, t=None): if not is_valid_string(t): raise SyntaxError('PodAffinityTerm: topology_key: [ {} ] is invalid.'.format(t)) self._topology_key = t # ------------------------------------------------------------------------------------- serialize def serialize(self): data = {} if self.label_selector is not None: data['labelSelector'] = self.label_selector.serialize() if self.namespaces: data['namespaces'] = self.namespaces if self.topology_key is not None: data['topologyKey'] = self.topology_key return data
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
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 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