def create_project_net_partition_mapping(self, context, project_net_partition_mapping): session = context.session p2n = project_net_partition_mapping['project_net_partition_mapping'] project = p2n['project'] net_partition_id = p2n['net_partition_id'] err = validators.validate_uuid(project) if err: raise nuage_exc.NuageBadRequest(resource='net_partition', msg=err) # Validate netpartition netpart = nuagedb.get_net_partition_by_id(session, net_partition_id) if not netpart: msg = _('Net partition {} is not a valid netpartition ' 'ID.').format(net_partition_id) raise nuage_exc.NuageBadRequest( resource='project_net_partition_mapping', msg=msg) with session.begin(subtransactions=True): existing_mapping = nuagedb.get_project_net_partition_mapping( session, project) if existing_mapping: session.delete(existing_mapping) mapping = nuagedb.add_project_net_partition_mapping( session, net_partition_id, project) return self._make_project_net_partition_mapping(context, mapping)
def get_project_net_partition_mapping(self, context, id, fields=None): mapping = nuagedb.get_project_net_partition_mapping( context.session, id) if not mapping: raise nuage_exc.NuageNotFound( resource='project_net_partition_mapping', resource_id=id) return self._make_project_net_partition_mapping( context, mapping, fields)
def delete_project_net_partition_mapping(self, context, project_id): session = context.session err = validators.validate_uuid(project_id) if err: raise nuage_exc.NuageBadRequest( resource='project_net_partition_mapping', msg=err) with session.begin(subtransactions=True): existing_mapping = nuagedb.get_project_net_partition_mapping( session, project_id) if existing_mapping: session.delete(existing_mapping) else: msg = _('Project {} does not currently ' 'have a default net-partition associated.').format( project_id) raise nuage_exc.NuageBadRequest( resource='project_net_partition_mapping', msg=msg)