def save(self, context): updates = self.obj_get_changes() projects = updates.pop('projects', None) extra_specs = updates.pop('extra_specs', None) if updates: raise exception.ObjectActionError( action='save', reason='read-only fields were changed') if extra_specs: db.flavor_extra_specs_update_or_create(context, self.flavorid, extra_specs) # NOTE(danms): This could be much simpler and more efficient # with a smarter flavor_access_update() method in db_api. if projects is not None: current_projects = [x['project_id'] for x in db.flavor_access_get_by_flavor_id( context, self.flavorid)] for project_id in projects: if project_id not in current_projects: db.flavor_access_add(context, self.flavorid, project_id) else: current_projects.remove(project_id) for condemned_project_id in current_projects: db.flavor_access_remove(context, self.flavorid, condemned_project_id) self.obj_reset_changes()
def save_projects(self, to_add=None, to_delete=None): """Add or delete projects. :param:to_add: A list of projects to add :param:to_delete: A list of projects to remove """ to_add = to_add if to_add is not None else [] to_delete = to_delete if to_delete is not None else [] for project_id in to_add: db.flavor_access_add(self._context, self.flavorid, project_id) for project_id in to_delete: db.flavor_access_remove(self._context, self.flavorid, project_id) self.obj_reset_changes(['projects'])
def _remove_access(self, project_id): if self.in_api: self._flavor_del_project(self._context, self.id, project_id) else: db.flavor_access_remove(self._context, self.flavorid, project_id)
def remove_flavor_access(flavorid, projectid, ctxt=None): """Remove flavor access for project.""" if ctxt is None: ctxt = context.get_admin_context() return db.flavor_access_remove(ctxt, flavorid, projectid)
def remove_access(self, project_id): if 'projects' in self.obj_what_changed(): raise exception.ObjectActionError(action='remove_access', reason='projects modified') db.flavor_access_remove(self._context, self.flavorid, project_id) self._load_projects()
def remove_access(self, context, project_id): if 'projects' in self.obj_what_changed(): raise exception.ObjectActionError(action='remove_access', reason='projects modified') db.flavor_access_remove(context, self.flavorid, project_id) self._load_projects(context)