def get(cls, name, safe=True, from_cache=True): resp = None if from_cache: resp = cache_client.get("project_" + name) if resp is None: core_api = client.CoreV1Api() try: resp = core_api.read_namespace("sandwich-" + name).to_dict() if resp is None: return None if resp['metadata']['labels'] is None: return None if PROJECT_LABEL not in resp['metadata']['labels']: return None o = cls(resp) if o.state != 'Terminating': # Only cache if not terminating cache_client.set('project_' + o.name, o._raw) except ApiException as e: if e.status == 404: cache_client.delete('project_' + name) if safe: return None raise else: o = cls(resp) return o
def get(cls, project, name, safe=True, from_cache=True): resp = None if from_cache: resp = cache_client.get(cls.name_plural() + "_" + project.name + "_" + name) if resp is None: crd_api = client.CustomObjectsApi() try: resp = crd_api.get_namespaced_custom_object( GROUP, cls.version(), "sandwich-" + project.name, cls.name_plural(), name) if resp is None: return None o = cls(resp) cache_client.set( cls.name_plural() + "_" + o.project_name + "_" + o.name, o._raw) except ApiException as e: if e.status == 404: cache_client.delete(cls.name_plural() + "_" + project.name + "_" + name) if safe: return None raise else: o = cls(resp) return o
def save(self): core_api = client.CoreV1Api() try: self._raw = core_api.replace_namespace( self._raw['metadata']['name'], self._raw) cache_client.set('project_' + self.name, self._raw) except ApiException: cache_client.delete('project_' + self.name) raise
def create(self): if self.project_name is None: raise ValueError("Project must be set to create {0}".format( self.__class__.__name__)) crd_api = client.CustomObjectsApi() self._raw = crd_api.create_namespaced_custom_object( GROUP, self.version(), "sandwich-" + self.project_name, self.name_plural(), self._raw) cache_client.set( self.name_plural() + "_" + self.project_name + "_" + self.name, self._raw)
def save(self, ignore=False): crd_api = client.CustomObjectsApi() try: self.updated_at = arrow.now('UTC') self._raw = crd_api.replace_cluster_custom_object( GROUP, self.version(), self.name_plural(), self.name, self._raw) cache_client.set(self.name_plural() + "_" + self.name, self._raw) except ApiException as e: cache_client.delete(self.name_plural() + "_" + self.name) if e.status == 409: if ignore: return raise e
def create(self): crd_api = client.CustomObjectsApi() self._raw = crd_api.create_cluster_custom_object( GROUP, self.version(), self.name_plural(), self._raw) cache_client.set(self.name_plural() + "_" + self.name, self._raw)
def create(self): core_api = client.CoreV1Api() self._raw = core_api.create_namespace(self._raw).to_dict() cache_client.set('project_' + self.name, self._raw)