Esempio n. 1
0
    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()
Esempio n. 2
0
    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()
Esempio n. 3
0
 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'])
Esempio n. 4
0
File: flavor.py Progetto: sapcc/nova
 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'])
Esempio n. 5
0
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)
Esempio n. 6
0
 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'])
Esempio n. 7
0
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)
Esempio n. 8
0
 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')