Esempio n. 1
0
    def destroy_portgroup(self, portgroup_id):
        def portgroup_not_empty(session):
            """Checks whether the portgroup does not have ports."""

            query = model_query(models.Port)
            query = add_port_filter_by_portgroup(query, portgroup_id)

            return query.count() != 0

        with _session_for_write() as session:
            if portgroup_not_empty(session):
                raise exception.PortgroupNotEmpty(portgroup=portgroup_id)

            query = model_query(models.Portgroup, session=session)
            query = add_identity_filter(query, portgroup_id)

            count = query.delete()
            if count == 0:
                raise exception.PortgroupNotFound(portgroup=portgroup_id)
Esempio n. 2
0
    def update_portgroup(self, portgroup_id, values):
        if 'uuid' in values:
            msg = _("Cannot overwrite UUID for an existing portgroup.")
            raise exception.InvalidParameterValue(err=msg)

        with _session_for_write() as session:
            try:
                query = model_query(models.Portgroup)
                query = add_portgroup_filter(query, portgroup_id)
                ref = query.one()
                ref.update(values)
                session.flush()
            except NoResultFound:
                raise exception.PortgroupNotFound(portgroup=portgroup_id)
            except db_exc.DBDuplicateEntry as exc:
                if 'name' in exc.columns:
                    raise exception.PortgroupDuplicateName(name=values['name'])
                elif 'address' in exc.columns:
                    raise exception.PortgroupMACAlreadyExists(
                        mac=values['address'])
                else:
                    raise
            return ref
Esempio n. 3
0
 def get_portgroup_by_address(self, address):
     query = model_query(models.Portgroup).filter_by(address=address)
     try:
         return query.one()
     except NoResultFound:
         raise exception.PortgroupNotFound(portgroup=address)
Esempio n. 4
0
 def get_portgroup_by_name(self, name):
     query = model_query(models.Portgroup).filter_by(name=name)
     try:
         return query.one()
     except NoResultFound:
         raise exception.PortgroupNotFound(portgroup=name)
Esempio n. 5
0
 def get_portgroup_by_uuid(self, portgroup_uuid):
     query = model_query(models.Portgroup).filter_by(uuid=portgroup_uuid)
     try:
         return query.one()
     except NoResultFound:
         raise exception.PortgroupNotFound(portgroup=portgroup_uuid)