**** CubicPower OpenStack Study ****
def find_network_with_name_label(session, name_label):
    networks = session.call_xenapi('network.get_by_name_label', name_label)
    if len(networks) == 1:
        return networks[0]
    elif len(networks) > 1:
        raise Exception(_('Found non-unique network for name_label %s') %
                        name_label)
    else:
        return None
**** CubicPower OpenStack Study ****
def find_network_with_bridge(session, bridge):
    """Return the network on which the bridge is attached, if found.
    The bridge is defined in the nova db and can be found either in the
    'bridge' or 'name_label' fields of the XenAPI network record.
    """
    expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
            (bridge, bridge))
    networks = session.call_xenapi('network.get_all_records_where', expr)
    if len(networks) == 1:
        return networks.keys()[0]
    elif len(networks) > 1:
        raise Exception(_('Found non-unique network for bridge %s') % bridge)
    else:
        raise Exception(_('Found no network for bridge %s') % bridge)