def update_image(self, image: Image) -> Image: with self._session(): i = self._get_sql_object_by_id(self.images, image.id) if i is None: raise NonExistingImageError(image) update_attrs(i, **SImage.get_kwargs(image)) return image
def delete_image(self, image: Image): if self.data.get_instances_by_image_id(image.id): raise ImageWithInstancesError(image) if image.id is None: raise NonExistingImageError(image) self.data.remove_image(image.id) self.save() image.unbind_meta_repo()
def update_image(self, image: Image) -> Image: self._validate_image(image) existing_model = self.get_model_by_id(image.model_id) if existing_model is None: raise NonExistingModelError(image.model_id) existing_image = self.get_image_by_id(image.id) if existing_image is None: raise NonExistingImageError(image) self.data.remove_image(image.id) self.data.add_image(copy.deepcopy(image)) self.save() return image
def update_image(self, image: Image) -> Image: self._validate_image(image) existing_task = self.get_task_by_id(image.task_id) if existing_task is None: raise NonExistingTaskError(image.task_id) existing_image = self.get_image_by_id(image.id) if existing_image is None: raise NonExistingImageError(image) self.data.remove_image(image.id) self.data.add_image(copy.deepcopy(image)) self.save() return image
def create_instance(self, instance: RuntimeInstance) -> RuntimeInstance: self._validate_instance(instance) image = self.get_image_by_id(instance.image_id) if image is None: raise NonExistingImageError(instance.image_id) environment = self.get_environment_by_id(instance.environment_id) if environment is None: raise NonExistingEnvironmentError(instance.environment_id) if self.get_instance_by_name(instance.name, image, environment) is not None: raise ExistingInstanceError(instance) instance._id = self.data.get_and_increment('next_instance_id') self.data.add_instance(copy.deepcopy(instance)) self.save() return instance
def delete_image(self, image: Image): if image.id is None: raise NonExistingImageError(image) self.data.remove_image(image.id) self.save() image.unbind_meta_repo()
def create_instance(self, instance: RuntimeInstance) -> RuntimeInstance: self._validate_instance(instance) if self._get_sql_object_by_id(self.images, instance.image_id) is None: raise NonExistingImageError(instance.image_id) return self._create_object(self.instances, instance, ExistingInstanceError)