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(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 _load_projects(self): try: self.projects = self._get_projects_from_db(self._context, self.flavorid) except exception.FlavorNotFound: self.projects = [x['project_id'] for x in db.flavor_access_get_by_flavor_id(self._context, self.flavorid)] self.obj_reset_changes(['projects'])
def _load_projects(self): try: self.projects = self._get_projects_from_db(self._context, self.flavorid) except exception.FlavorNotFound: self.projects = [x['project_id'] for x in db.flavor_access_get_by_flavor_id(self._context, self.flavorid)] self.obj_reset_changes(['projects'])
def get_flavor_access_by_flavor_id(flavorid, ctxt=None): """Retrieve flavor access list by flavor id.""" if ctxt is None: ctxt = context.get_admin_context() return db.flavor_access_get_by_flavor_id(ctxt, flavorid)
def _load_projects(self): self.projects = [ x['project_id'] for x in db.flavor_access_get_by_flavor_id( self._context, self.flavorid) ] self.obj_reset_changes(['projects'])
def get_flavor_access_by_flavor_id(flavorid, ctxt=None): """Retrieve flavor access list by flavor id.""" if ctxt is None: ctxt = context.get_admin_context() return db.flavor_access_get_by_flavor_id(ctxt, flavorid)
def _load_projects(self, context): self.projects = [x['project_id'] for x in db.flavor_access_get_by_flavor_id(context, self.flavorid)] self.obj_reset_changes('projects')