Ejemplo n.º 1
0
def get_nexusvlan_binding(vlan_id, switch_ip):
    """Lists a vlan and switch binding."""
    LOG.debug(_("get_nexusvlan_binding() called"))
    session = db.get_session()

    filters = dict(vlan_id=vlan_id, switch_ip=switch_ip)
    bindings = (session.query(
        nexus_models_v2.NexusPortBinding).filter_by(**filters).all())
    if not bindings:
        raise c_exc.NexusPortBindingNotFound(**filters)

    return bindings
Ejemplo n.º 2
0
def get_nexussvi_bindings():
    """Lists nexus svi bindings."""
    LOG.debug(_("get_nexussvi_bindings() called"))
    session = db.get_session()

    filters = {'port_id': 'router'}
    bindings = (session.query(
        nexus_models_v2.NexusPortBinding).filter_by(**filters).all())
    if not bindings:
        raise c_exc.NexusPortBindingNotFound(**filters)

    return bindings
Ejemplo n.º 3
0
def get_nexusvm_binding(vlan_id, instance_id):
    """Lists nexusvm bindings."""
    LOG.debug(_("get_nexusvm_binding() called"))
    session = db.get_session()

    filters = dict(instance_id=instance_id, vlan_id=vlan_id)
    binding = (session.query(
        nexus_models_v2.NexusPortBinding).filter_by(**filters).first())
    if not binding:
        raise c_exc.NexusPortBindingNotFound(**filters)

    return binding
Ejemplo n.º 4
0
def update_nexusport_binding(port_id, new_vlan_id):
    """Updates nexusport binding."""
    LOG.debug(_("update_nexusport_binding called"))
    session = db.get_session()
    try:
        binding = (session.query(
            nexus_models_v2.NexusPortBinding).filter_by(port_id=port_id).one())
        if new_vlan_id:
            binding["vlan_id"] = new_vlan_id
        session.merge(binding)
        session.flush()
        return binding
    except exc.NoResultFound:
        raise c_exc.NexusPortBindingNotFound(port_id=port_id)
Ejemplo n.º 5
0
def get_nexusport_binding(port_id, vlan_id, switch_ip, instance_id):
    """Lists a nexusport binding."""
    LOG.debug(_("get_nexusport_binding() called"))
    session = db.get_session()

    filters = dict(port_id=port_id,
                   vlan_id=vlan_id,
                   switch_ip=switch_ip,
                   instance_id=instance_id)
    bindings = (session.query(
        nexus_models_v2.NexusPortBinding).filter_by(**filters).all())
    if not bindings:
        raise c_exc.NexusPortBindingNotFound(**filters)

    return bindings
Ejemplo n.º 6
0
def _lookup_nexus_bindings(query_type, session=None, **bfilter):
    """Look up 'query_type' Nexus bindings matching the filter.

    :param query_type: 'all', 'one' or 'first'
    :param session: db session
    :param bfilter: filter for bindings query
    :return: bindings if query gave a result, else
             raise NexusPortBindingNotFound.
    """
    if session is None:
        session = db.get_session()
    query_method = getattr(
        session.query(nexus_models_v2.NexusPortBinding).filter_by(**bfilter),
        query_type)
    try:
        bindings = query_method()
        if bindings:
            return bindings
    except sa_exc.NoResultFound:
        pass
    raise c_exc.NexusPortBindingNotFound(**bfilter)