def _flavor_create(context, values): specs = values.get('extra_specs') db_specs = [] if specs: for k, v in specs.items(): db_spec = api_models.FlavorExtraSpecs() db_spec['key'] = k db_spec['value'] = v db_specs.append(db_spec) projects = values.get('projects') db_projects = [] if projects: for project in set(projects): db_project = api_models.FlavorProjects() db_project['project_id'] = project db_projects.append(db_project) values['extra_specs'] = db_specs values['projects'] = db_projects db_flavor = api_models.Flavors() db_flavor.update(values) try: db_flavor.save(context.session) except db_exc.DBDuplicateEntry as e: if 'flavorid' in e.columns: raise exception.FlavorIdExists(flavor_id=values['flavorid']) raise exception.FlavorExists(name=values['name']) except Exception as e: raise db_exc.DBError(e) return _dict_with_extra_specs(db_flavor)
def _flavor_add_project(context, flavor_id, project_id): project = api_models.FlavorProjects() project.update({'flavor_id': flavor_id, 'project_id': project_id}) try: project.save(context.session) except db_exc.DBDuplicateEntry: raise exception.FlavorAccessExists(flavor_id=flavor_id, project_id=project_id)
def test_tables_flavor_instance_type_projects(self): flavor_projects = api_models.FlavorProjects() instance_types_projects = models.InstanceTypeProjects() columns_flavor_projects = self._get_columns_list(flavor_projects) columns_instance_type_projects = self._get_columns_list( instance_types_projects) columns_flavor_projects.remove('flavor_id') columns_instance_type_projects.remove('instance_type_id') self.assertTrue( self._check_column_list(columns_flavor_projects, columns_instance_type_projects))