def __init__(self, **kwargs): BaseModel.__init__(self) model = kwargs.get('model', None) handler = kwargs.get('handler', None) initial_delay_s = kwargs.get('initial_delay_s', 1) timeout_s = kwargs.get('timeout_s', 3) period_s = kwargs.get('period_s', 15) success_threshold = kwargs.get('success_threshold', 1) failure_threshold = kwargs.get('failure_threshold', 2) self.valid_handlers = ['exec', 'httpGet', 'tcpSocket'] if model is not None: assert isinstance(model, dict) self.model = model if 'status' in self.model.keys(): self.model.pop('status', None) for h in self.valid_handlers: if h in self.model.keys(): self.handler = h break else: self.model = dict() self.handler = handler self.set_handler(**kwargs) self.model['initialDelaySeconds'] = initial_delay_s self.model['timeoutSeconds'] = timeout_s self.model['periodSeconds'] = period_s self.model['successThreshold'] = success_threshold self.model['failureThreshold'] = failure_threshold
def __init__(self, name=None, image=None, model=None): BaseModel.__init__(self) self.readiness_probe = None self.liveness_probe = None if model is not None: assert isinstance(model, dict) self.model = model if 'status' in self.model.keys(): self.model.pop('status', None) if 'livenessProbe' in self.model.keys(): self.liveness_probe = Probe(model=self.model['livenessProbe']) if 'readinessProbe' in self.model.keys(): self.readiness_probe = Probe(model=self.model['readinessProbe']) if 'privileged' not in self.model.keys(): self.model['privileged'] = False if 'hostNetwork' not in self.model.keys(): self.model['hostNetwork'] = False else: if name is None or image is None: raise SyntaxError("name: [ {0} ] and image: [ {1} ] cannot be None.".format(name, image)) self.model = { "name": name, "image": image, "imagePullPolicy": 'IfNotPresent', "privileged": False, "hostNetwork": False, "terminationMessagePath": "/dev/termination-log", "resources": { "requests": { "cpu": "100m", "memory": "32M" } } }
def __init__(self, name=None, image=None, model=None, pull_secret=None): BaseModel.__init__(self) self.containers = list() if model is not None: assert isinstance(model, dict) if 'status' in self.model.keys(): self.model.pop('status', None) self.model = model for c in self.model['containers']: self.containers.append(Container(model=c)) if 'volumes' not in self.model.keys(): self.model['volumes'] = [] else: self.model = { "containers": [], "dnsPolicy": "Default", "volumes": [] } if name is not None and not isinstance(name, str): raise SyntaxError('PodSpec: Name should be a string.') if image is not None and not isinstance(image, str): self.containers.append(Container(name=name, image=image)) if pull_secret is not None: assert isinstance(pull_secret, str) self.add_image_pull_secrets(name=pull_secret) self._update_model()
def __init__(self, name=None, namespace='default', model=None, del_server_attr=True): BaseModel.__init__(self) if model is not None: self.model = model if del_server_attr: self.del_server_generated_meta_attr() else: self.model = dict(name=name, namespace=namespace, labels=dict(name=name))
def __init__(self, kind, grace_period_seconds=30, model=None): BaseModel.__init__(self) if model is not None: assert isinstance(model, dict) self.model = model else: if kind is None or not isinstance(kind, str): raise SyntaxError('kind must be a string') self.model = dict(kind=kind, apiVersion='v1', gracePeriodSeconds=grace_period_seconds)
def __init__(self, name=None, namespace='default', model=None): BaseModel.__init__(self) if model is not None: assert isinstance(model, dict) if 'status' in self.model.keys(): self.model.pop('status', None) self.model = model self.secret_metadata = ObjectMeta(model=self.model['metadata']) else: if name is None or not isinstance(name, str): raise SyntaxError('name must be a string.') self.model = dict(kind='Secret', apiVersion='v1') self.secret_metadata = ObjectMeta(name=name, namespace=namespace) self._update_model()
def __init__(self, **kwargs): BaseModel.__init__(self) model = kwargs.get('model', None) if model is not None: filtered = filter(lambda x: x in Probe.VALID_HANDLERS, model.keys()) else: filtered = filter(lambda x: x in Probe.VALID_HANDLERS, kwargs) if not filtered: raise SyntaxError('Probe: Valid handler not found. (eg. {0} )'.format(Probe.VALID_HANDLERS)) if len(filtered) > 1: raise SyntaxError('Probe: More than one handler found: [ {0} ]'.format(filtered)) handler = filtered[0] # there can be only one. if model is not None: initial_delay_s = model.get('initialDelaySeconds', 1) timeout_s = model.get('timeoutSeconds', 3) period_s = model.get('periodSeconds', 15) success_threshold = model.get('successThreshold', 1) failure_threshold = model.get('failureThreshold', 2) else: initial_delay_s = kwargs.get('initialDelaySeconds', 1) timeout_s = kwargs.get('timeoutSeconds', 3) period_s = kwargs.get('periodSeconds', 15) success_threshold = kwargs.get('successThreshold', 1) failure_threshold = kwargs.get('failureThreshold', 2) if model is not None: assert isinstance(model, dict) self.model = model if 'status' in self.model.keys(): self.model.pop('status', None) for h in Probe.VALID_HANDLERS: if h in self.model.keys(): self.handler = h break else: self.model = dict() self.handler = handler handler_dict = kwargs[handler] self.set_handler(handler_dict) self.model['initialDelaySeconds'] = initial_delay_s self.model['timeoutSeconds'] = timeout_s self.model['periodSeconds'] = period_s self.model['successThreshold'] = success_threshold self.model['failureThreshold'] = failure_threshold
def __init__(self, name=None, namespace='default', port_name=None, port=0, target_port=None, selector=None, session_affinity='None', model=None): BaseModel.__init__(self) if model is not None: assert isinstance(model, dict) self.model = model if 'status' in self.model.keys(): self.model.pop('status', None) self.svc_metadata = ObjectMeta(model=self.model['metadata'], del_server_attr=False) else: self.model = dict(kind='Service', apiVersion='v1') self.svc_metadata = ObjectMeta(name=name, namespace=namespace) self.model['spec'] = dict(ports=[], selector=dict(), sessionAffinity=session_affinity, type='ClusterIP') if port_name is not None and port > 0 and target_port is not None: self.add_port(port=port, target_port=target_port, name=port_name) if selector is not None: self.add_selector(selector=selector) self._update_model()
def __init__(self, name=None, namespace='default', model=None): BaseModel.__init__(self) if name is None: raise SyntaxError('Secret: name: [ {0} ] cannot be None.'.format(name)) if not isinstance(name, str): raise SyntaxError('Secret: name: [ {0} ] must be a string.'.format(name)) if model is not None and not isinstance(model, dict): raise SyntaxError('Secret: model: [ {0} ] must be a dict.'.format(model)) if model is not None: if 'status' in self.model: self.model.pop('status', None) self.model = model self.secret_metadata = ObjectMeta(model=self.model['metadata']) else: self.model = dict(kind='Secret', apiVersion='v1') self.secret_metadata = ObjectMeta(name=name, namespace=namespace) self._update_model()
def __init__(self, name=None, image=None, model=None, pull_secret=None): BaseModel.__init__(self) self.containers = list() if model is not None: if not isinstance(model, dict): raise SyntaxError('PodSpec: model: [ {0} ] must be a dict.'.format(model.__class__.__name__)) if 'status' in self.model: self.model.pop('status', None) self.model = model for c in self.model['containers']: self.containers.append(Container(model=c)) if 'volumes' not in self.model: self.model['volumes'] = [] else: self.model = { "containers": [], "dnsPolicy": "Default", "volumes": [] } if name is not None and not isinstance(name, str): raise SyntaxError('PodSpec: name: [ {0} ] must be a string.'.format(name.__class__.__name__)) if image is not None and not isinstance(image, str): self.containers.append(Container(name=name, image=image)) if pull_secret is not None: if not isinstance(pull_secret, str): raise SyntaxError('PodSpec: pull_secret: [ {0} ] must be a string.'.format(pull_secret.__class__.__name__)) self.add_image_pull_secrets(name=pull_secret) self._update_model()
def __init__(self): BaseModel.__init__(self) self.pod_spec = PodSpec() self.pod_metadata = ObjectMeta() self.pod_status = None
def __init__(self, model=None): BaseModel.__init__(self) if model is not None: assert isinstance(model, dict) self.model = model