def test_vlan_id_pool(self): session = db.get_session() vlan_ids = set() for x in xrange(VLAN_MIN, VLAN_MAX + 1): vlan_id = ovs_db_v2.reserve_vlan_id(db.get_session()) self.assertGreaterEqual(vlan_id, VLAN_MIN) self.assertLessEqual(vlan_id, VLAN_MAX) vlan_ids.add(vlan_id) with self.assertRaises(q_exc.NoNetworkAvailable): vlan_id = ovs_db_v2.reserve_vlan_id(session) for vlan_id in vlan_ids: ovs_db_v2.release_vlan_id(vlan_id)
def get_device_details(self, rpc_context, **kwargs): """Agent requests device details.""" agent_id = kwargs.get('agent_id') device = kwargs.get('device') LOG.debug(_("Device %(device)s details requested from %(agent_id)s"), { 'device': device, 'agent_id': agent_id }) port = self.get_port_from_device(device) if port: binding = db.get_network_binding(db_api.get_session(), port['network_id']) (network_type, segmentation_id) = constants.interpret_vlan_id(binding.vlan_id) entry = { 'device': device, 'network_type': network_type, 'physical_network': binding.physical_network, 'segmentation_id': segmentation_id, 'network_id': port['network_id'], 'port_id': port['id'], 'admin_state_up': port['admin_state_up'] } if cfg.CONF.AGENT.rpc_support_old_agents: entry['vlan_id'] = binding.vlan_id new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up'] else q_const.PORT_STATUS_DOWN) if port['status'] != new_status: db.set_port_status(port['id'], new_status) else: entry = {'device': device} LOG.debug(_("%s can not be found in database"), device) return entry
def sync_vlan_allocations(self, network_vlan_ranges): """Synchronize vlan_allocations table with configured VLAN ranges.""" session = db_api.get_session() with session.begin(): # get existing allocations for all physical networks allocations = dict() allocs_q = session.query(hyperv_model.VlanAllocation) for alloc in allocs_q: allocations.setdefault(alloc.physical_network, set()).add(alloc) # process vlan ranges for each configured physical network for physical_network, vlan_ranges in network_vlan_ranges.items(): # determine current configured allocatable vlans for this # physical network vlan_ids = set() for vlan_range in vlan_ranges: vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1)) # remove from table unallocated vlans not currently allocatable self._remove_non_allocatable_vlans(session, physical_network, vlan_ids, allocations) # add missing allocatable vlans to table self._add_missing_allocatable_vlans(session, vlan_ids, physical_network) # remove from table unallocated vlans for any unconfigured physical # networks self._remove_unconfigured_vlans(session, allocations)
def get_device_details(self, rpc_context, **kwargs): """Agent requests device details""" agent_id = kwargs.get('agent_id') device = kwargs.get('device') LOG.debug(_("Device %(device)s details requested from %(agent_id)s"), locals()) port = self.get_port_from_device(device) if port: binding = db.get_network_binding(db_api.get_session(), port['network_id']) entry = {'device': device, 'physical_network': binding.physical_network, 'network_type': binding.network_type, 'vlan_id': binding.vlan_id, 'network_id': port['network_id'], 'port_id': port['id'], 'admin_state_up': port['admin_state_up']} new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up'] else q_const.PORT_STATUS_DOWN) if port['status'] != new_status: db.set_port_status(port['id'], new_status) else: entry = {'device': device} LOG.debug(_("%s can not be found in database"), device) return entry
def test_key_allocation(self): tunnel_key = db_api_v2.TunnelKey() session = db.get_session() with nested(self.network('network-0'), self.network('network-1') ) as (network_0, network_1): network_id0 = network_0['network']['id'] key0 = tunnel_key.allocate(session, network_id0) network_id1 = network_1['network']['id'] key1 = tunnel_key.allocate(session, network_id1) key_list = tunnel_key.all_list() self.assertEqual(len(key_list), 2) expected_list = [(network_id0, key0), (network_id1, key1)] self.assertEqual(self._tunnel_key_sort(key_list), expected_list) tunnel_key.delete(session, network_id0) key_list = tunnel_key.all_list() self.assertEqual(self._tunnel_key_sort(key_list), [(network_id1, key1)]) tunnel_key.delete(session, network_id1) self.assertEqual(tunnel_key.all_list(), [])
def get_port_properties(portid): session = db.get_session() try: port = session.query(neuca_models.port_properties).filter_by(port_id=portid).one() except exc.NoResultFound: pass return port
def get_device_details(self, rpc_context, **kwargs): """Agent requests device details.""" agent_id = kwargs.get('agent_id') device = kwargs.get('device') LOG.debug(_("Device %(device)s details requested from %(agent_id)s"), {'device': device, 'agent_id': agent_id}) port = self.get_port_from_device(device) if port: binding = db.get_network_binding(db_api.get_session(), port['network_id']) (network_type, segmentation_id) = constants.interpret_vlan_id(binding.vlan_id) entry = {'device': device, 'network_type': network_type, 'physical_network': binding.physical_network, 'segmentation_id': segmentation_id, 'network_id': port['network_id'], 'port_id': port['id'], 'admin_state_up': port['admin_state_up']} if cfg.CONF.AGENT.rpc_support_old_agents: entry['vlan_id'] = binding.vlan_id new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up'] else q_const.PORT_STATUS_DOWN) if port['status'] != new_status: db.set_port_status(port['id'], new_status) else: entry = {'device': device} LOG.debug(_("%s can not be found in database"), device) return entry
def sync_network_states(network_vlan_ranges): """Synchronize network_states table with current configured VLAN ranges.""" session = db.get_session() with session.begin(): # get existing allocations for all physical networks allocations = dict() states = (session.query(l2network_models_v2.NetworkState).all()) for state in states: if state.physical_network not in allocations: allocations[state.physical_network] = set() allocations[state.physical_network].add(state) # process vlan ranges for each configured physical network for physical_network, vlan_ranges in network_vlan_ranges.iteritems(): # determine current configured allocatable vlans for this # physical network vlan_ids = set() for vlan_range in vlan_ranges: vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1)) # remove from table unallocated vlans not currently allocatable if physical_network in allocations: for state in allocations[physical_network]: try: # see if vlan is allocatable vlan_ids.remove(state.vlan_id) except KeyError: # it's not allocatable, so check if its allocated if not state.allocated: # it's not, so remove it from table LOG.debug( _("Removing vlan %(vlan_id)s on " "physical network %(physical_network)s" " from pool"), { 'vlan_id': state.vlan_id, 'physical_network': physical_network }) session.delete(state) del allocations[physical_network] # add missing allocatable vlans to table for vlan_id in sorted(vlan_ids): state = l2network_models_v2.NetworkState( physical_network, vlan_id) session.add(state) # remove from table unallocated vlans for any unconfigured physical # networks for states in allocations.itervalues(): for state in states: if not state.allocated: LOG.debug( _("Removing vlan %(vlan_id)s on physical " "network %(physical_network)s" " from pool"), { 'vlan_id': state.vlan_id, 'physical_network': physical_network }) session.delete(state)
def get_port(port_id): session = db.get_session() try: port = session.query(models_v2.Port).filter_by(id=port_id).one() except exc.NoResultFound: port = None return port
def get_vlans(): session = db.get_session() try: bindings = (session.query(ovs_models_v2.VlanBinding).all()) except exc.NoResultFound: return [] return [(binding.vlan_id, binding.network_id) for binding in bindings]
def create_vlanids(): """Prepopulates the vlan_bindings table""" LOG.debug("create_vlanids() called") session = db.get_session() start = CONF.VLANS.vlan_start end = CONF.VLANS.vlan_end try: vlanid = session.query(l2network_models.VlanID).one() except exc.MultipleResultsFound: """ TODO (Sumit): Salvatore rightly points out that this will not handle change in VLAN ID range across server reboots. This is currently not a supported feature. This logic will need to change if this feature has to be supported. Per Dan's suggestion we just throw a server exception for now. """ current_start = (int( session.query(func.min(l2network_models.VlanID.vlan_id)).one()[0])) current_end = (int( session.query(func.max(l2network_models.VlanID.vlan_id)).one()[0])) if current_start != start or current_end != end: LOG.debug("Old VLAN range %s-%s" % (current_start, current_end)) LOG.debug("New VLAN range %s-%s" % (start, end)) raise c_exc.UnableToChangeVlanRange(range_start=current_start, range_end=current_end) except exc.NoResultFound: LOG.debug("Setting VLAN range to %s-%s" % (start, end)) while start <= end: vlanid = l2network_models.VlanID(start) session.add(vlanid) start += 1 session.flush() return
def get_port_and_sgs(port_id): """Get port from database with security group info.""" LOG.debug(_("get_port_and_sgs() called for port_id %s"), port_id) session = db_api.get_session() sg_binding_port = sg_db.SecurityGroupPortBinding.port_id with session.begin(subtransactions=True): query = session.query(models_v2.Port, sg_db.SecurityGroupPortBinding.security_group_id) query = query.outerjoin(sg_db.SecurityGroupPortBinding, models_v2.Port.id == sg_binding_port) query = query.filter(models_v2.Port.id.startswith(port_id)) port_and_sgs = query.all() if not port_and_sgs: return port = port_and_sgs[0][0] plugin = manager.QuantumManager.get_plugin() port_dict = plugin._make_port_dict(port) port_dict['security_groups'] = [ sg_id for port_, sg_id in port_and_sgs if sg_id ] port_dict['security_group_rules'] = [] port_dict['security_group_source_groups'] = [] port_dict['fixed_ips'] = [ip['ip_address'] for ip in port['fixed_ips']] return port_dict
def sync_tunnel_allocations(tunnel_id_ranges): """Synchronize tunnel_allocations table with configured tunnel ranges""" # determine current configured allocatable tunnels tunnel_ids = set() for tunnel_id_range in tunnel_id_ranges: tun_min, tun_max = tunnel_id_range if tun_max + 1 - tun_min > 1000000: LOG.error(_("Skipping unreasonable tunnel ID range " "%(tun_min)s:%(tun_max)s"), locals()) else: tunnel_ids |= set(xrange(tun_min, tun_max + 1)) session = db.get_session() with session.begin(): # remove from table unallocated tunnels not currently allocatable allocs = (session.query(ovs_models_v2.TunnelAllocation). all()) for alloc in allocs: try: # see if tunnel is allocatable tunnel_ids.remove(alloc.tunnel_id) except KeyError: # it's not allocatable, so check if its allocated if not alloc.allocated: # it's not, so remove it from table LOG.debug(_("Removing tunnel %s from pool"), alloc.tunnel_id) session.delete(alloc) # add missing allocatable tunnels to table for tunnel_id in sorted(tunnel_ids): alloc = ovs_models_v2.TunnelAllocation(tunnel_id) session.add(alloc)
def get_port_from_device(device): """Get port from database.""" LOG.debug(_("get_port_from_device() called")) session = db.get_session() sg_binding_port = sg_db.SecurityGroupPortBinding.port_id query = session.query(models_v2.Port, sg_db.SecurityGroupPortBinding.security_group_id) query = query.outerjoin(sg_db.SecurityGroupPortBinding, models_v2.Port.id == sg_binding_port) query = query.filter(models_v2.Port.id.startswith(device)) port_and_sgs = query.all() if not port_and_sgs: return port = port_and_sgs[0][0] plugin = manager.QuantumManager.get_plugin() port_dict = plugin._make_port_dict(port) port_dict['security_groups'] = [] for port_in_db, sg_id in port_and_sgs: if sg_id: port_dict['security_groups'].append(sg_id) port_dict['security_group_rules'] = [] port_dict['security_group_source_groups'] = [] port_dict['fixed_ips'] = [ip['ip_address'] for ip in port['fixed_ips']] return port_dict
def port_binding_get(port_id, net_id): session = db.get_session() session.query(models_v2.Port).filter( models_v2.Port.network_id == net_id).filter( models_v2.Port.id == port_id).one() # confirm port exists return session.query(ryu_models_v2.PortBinding).filter_by( network_id=net_id).filter_by(port_id=port_id).one()
def update_portbinding(port_id, blade_intf_dn=None, portprofile_name=None, vlan_name=None, vlan_id=None, qos=None, tenant_id=None, instance_id=None, vif_id=None): """Updates port binding""" LOG.debug("db update_portbinding() called") session = db.get_session() try: port_binding = (session.query(ucs_models.PortBinding). filter_by(port_id=port_id).one()) if blade_intf_dn: port_binding.blade_intf_dn = blade_intf_dn if portprofile_name: port_binding.portprofile_name = portprofile_name if vlan_name: port_binding.vlan_name = vlan_name if vlan_name: port_binding.vlan_id = vlan_id if qos: port_binding.qos = qos if tenant_id: port_binding.tenant_id = tenant_id if instance_id: port_binding.instance_id = instance_id if vif_id: port_binding.vif_id = vif_id session.merge(port_binding) session.flush() return port_binding except exc.NoResultFound: raise c_exc.PortVnicNotFound(port_id=port_id)
def get_network_state(physical_network, segmentation_id): """Get entry of specified network.""" session = db.get_session() qry = session.query(mlnx_models_v2.SegmentationIdAllocation) qry = qry.filter_by(physical_network=physical_network, segmentation_id=segmentation_id) return qry.first()
def update_vlan_id_pool(): """Update vlan_ids based on current configuration.""" # determine current dynamically-allocated range vlans = set(xrange(cfg.CONF.OVS.vlan_min, cfg.CONF.OVS.vlan_max + 1)) session = db.get_session() with session.begin(subtransactions=True): # remove unused vlan_ids outside current range try: records = (session.query(ovs_models_v2.VlanID). all()) for record in records: try: vlans.remove(record.vlan_id) except KeyError: if not record.vlan_used: LOG.debug("removing vlan %s from pool" % record.vlan_id) session.delete(record) except exc.NoResultFound: pass # add missing vlan_ids for vlan in vlans: record = ovs_models_v2.VlanID(vlan) session.add(record)
def sync_tunnel_allocations(tunnel_id_ranges): """Synchronize tunnel_allocations table with configured tunnel ranges""" # determine current configured allocatable tunnels tunnel_ids = set() for tunnel_id_range in tunnel_id_ranges: tun_min, tun_max = tunnel_id_range if tun_max + 1 - tun_min > 1000000: LOG.error("Skipping unreasonable tunnel ID range %s:%s" % tunnel_id_range) else: tunnel_ids |= set(xrange(tun_min, tun_max + 1)) session = db.get_session() with session.begin(): # remove from table unallocated tunnels not currently allocatable allocs = (session.query(ovs_models_v2.TunnelAllocation).all()) for alloc in allocs: try: # see if tunnel is allocatable tunnel_ids.remove(alloc.tunnel_id) except KeyError: # it's not allocatable, so check if its allocated if not alloc.allocated: # it's not, so remove it from table LOG.debug("removing tunnel %s from pool" % alloc.tunnel_id) session.delete(alloc) # add missing allocatable tunnels to table for tunnel_id in sorted(tunnel_ids): alloc = ovs_models_v2.TunnelAllocation(tunnel_id) session.add(alloc)
def test_ofp_server(self): session = db.get_session() servers = session.query(ryu_models_v2.OFPServer).all() print servers self.assertEqual(len(servers), 2) for s in servers: self.assertTrue((s.address, s.host_type) in self.hosts)
def ofp_has_servers(): session = db.get_session() try: session.query(models.OFPServers).first() return True except exc.NoResultFound: return False
def get_plugged_port(interface_id): session = db.get_session() try: return session.query(models.Port).\ filter_by(interface_id=interface_id).one() except exc.NoResultFound: return None
def create_vlanids(): """Prepopulates the vlan_bindings table""" LOG.debug("create_vlanids() called") session = db.get_session() start = CONF.VLANS.vlan_start end = CONF.VLANS.vlan_end try: vlanid = session.query(L2_MODEL.VlanID).one() except exc.MultipleResultsFound: """ TODO (Sumit): Salvatore rightly points out that this will not handle change in VLAN ID range across server reboots. This is currently not a supported feature. This logic will need to change if this feature has to be supported. Per Dan's suggestion we just throw a server exception for now. """ current_start = ( int(session.query(func.min(L2_MODEL.VlanID.vlan_id)). one()[0])) current_end = ( int(session.query(func.max(L2_MODEL.VlanID.vlan_id)). one()[0])) if current_start != start or current_end != end: LOG.debug("Old VLAN range %s-%s" % (current_start, current_end)) LOG.debug("New VLAN range %s-%s" % (start, end)) raise c_exc.UnableToChangeVlanRange(range_start=current_start, range_end=current_end) except exc.NoResultFound: LOG.debug("Setting VLAN range to %s-%s" % (start, end)) while start <= end: vlanid = L2_MODEL.VlanID(start) session.add(vlanid) start += 1 session.flush() return
def sync_network_states(network_vlan_ranges): """Synchronize network_states table with current configured VLAN ranges.""" session = db.get_session() with session.begin(): # get existing allocations for all physical networks allocations = dict() entries = (session.query( mlnx_models_v2.SegmentationIdAllocation).all()) for entry in entries: allocations.setdefault(entry.physical_network, set()).add(entry) # process vlan ranges for each configured physical network for physical_network, vlan_ranges in network_vlan_ranges.iteritems(): # determine current configured allocatable vlans for this # physical network vlan_ids = set() for vlan_range in vlan_ranges: vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1)) # remove from table unallocated vlans not currently allocatable _remove_non_allocatable_vlans(session, allocations, physical_network, vlan_ids) # add missing allocatable vlans to table _add_missing_allocatable_vlans(session, physical_network, vlan_ids) # remove from table unallocated vlans for any unconfigured physical # networks _remove_unconfigured_vlans(session, allocations)
def reserve_vlanid(): """Reserves the first unused vlanid""" LOG.debug("reserve_vlanid() called") session = db.get_session() try: rvlan = (session.query(L2_MODEL.VlanID). first()) if not rvlan: create_vlanids() rvlan = (session.query(L2_MODEL.VlanID). filter_by(vlan_used=False). first()) if not rvlan: raise c_exc.VlanIDNotAvailable() rvlanid = (session.query(L2_MODEL.VlanID). filter_by(vlan_id=rvlan["vlan_id"]). one()) rvlanid["vlan_used"] = True session.merge(rvlanid) session.flush() return rvlan["vlan_id"] except exc.NoResultFound: raise c_exc.VlanIDNotAvailable()
def set_ofp_servers(hosts): session = db.get_session() session.query(models.OFPServer).delete() for (host_address, host_type) in hosts: host = models.OFPServer(host_address, host_type) session.add(host) session.flush()
def sync_vlan_allocations(self, network_vlan_ranges): """Synchronize vlan_allocations table with configured VLAN ranges""" session = db_api.get_session() with session.begin(): # get existing allocations for all physical networks allocations = dict() allocs_q = session.query(hyperv_model.VlanAllocation) for alloc in allocs_q.all(): allocations.setdefault(alloc.physical_network, set()).add(alloc) # process vlan ranges for each configured physical network for physical_network, vlan_ranges in network_vlan_ranges.items(): # determine current configured allocatable vlans for this # physical network vlan_ids = set() for vlan_range in vlan_ranges: vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1)) # remove from table unallocated vlans not currently allocatable self._remove_non_allocatable_vlans(session, physical_network, vlan_ids, allocations) # add missing allocatable vlans to table self._add_missing_allocatable_vlans(session, vlan_ids, physical_network) # remove from table unallocated vlans for any unconfigured physical # networks self._remove_unconfigured_vlans(session, allocations)
def sync_network_states(network_vlan_ranges): """Synchronize network_states table with current configured VLAN ranges.""" session = db.get_session() with session.begin(): # get existing allocations for all physical networks allocations = dict() entries = session.query(mlnx_models_v2.SegmentationIdAllocation).all() for entry in entries: allocations.setdefault(entry.physical_network, set()).add(entry) # process vlan ranges for each configured physical network for physical_network, vlan_ranges in network_vlan_ranges.iteritems(): # determine current configured allocatable vlans for this # physical network vlan_ids = set() for vlan_range in vlan_ranges: vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1)) # remove from table unallocated vlans not currently allocatable _remove_non_allocatable_vlans(session, allocations, physical_network, vlan_ids) # add missing allocatable vlans to table _add_missing_allocatable_vlans(session, physical_network, vlan_ids) # remove from table unallocated vlans for any unconfigured physical # networks _remove_unconfigured_vlans(session, allocations)
def test_invalid_specific_vlan_id(self): session = db.get_session() with self.assertRaises(q_exc.InvalidInput): vlan_id = ovs_db_v2.reserve_specific_vlan_id(0, session) with self.assertRaises(q_exc.InvalidInput): vlan_id = ovs_db_v2.reserve_specific_vlan_id(4095, session)
def get_port_from_device(device): """Get port from database""" LOG.debug(_("get_port_from_device() called")) session = db.get_session() sg_binding_port = sg_db.SecurityGroupPortBinding.port_id query = session.query(models_v2.Port, sg_db.SecurityGroupPortBinding.security_group_id) query = query.outerjoin(sg_db.SecurityGroupPortBinding, models_v2.Port.id == sg_binding_port) query = query.filter(models_v2.Port.id.startswith(device)) port_and_sgs = query.all() if not port_and_sgs: return port = port_and_sgs[0][0] plugin = manager.QuantumManager.get_plugin() port_dict = plugin._make_port_dict(port) port_dict['security_groups'] = [] for port_in_db, sg_id in port_and_sgs: if sg_id: port_dict['security_groups'].append(sg_id) port_dict['security_group_rules'] = [] port_dict['security_group_source_groups'] = [] port_dict['fixed_ips'] = [ip['ip_address'] for ip in port['fixed_ips']] return port_dict
def _sync_vlan_allocations(self): session = db_api.get_session() with session.begin(subtransactions=True): # get existing allocations for all physical networks allocations = dict() allocs = (session.query(VlanAllocation). with_lockmode('update')) for alloc in allocs: if alloc.physical_network not in allocations: allocations[alloc.physical_network] = set() allocations[alloc.physical_network].add(alloc) # process vlan ranges for each configured physical network for (physical_network, vlan_ranges) in self.network_vlan_ranges.iteritems(): # determine current configured allocatable vlans for # this physical network vlan_ids = set() for vlan_min, vlan_max in vlan_ranges: vlan_ids |= set(xrange(vlan_min, vlan_max + 1)) # remove from table unallocated vlans not currently # allocatable if physical_network in allocations: for alloc in allocations[physical_network]: try: # see if vlan is allocatable vlan_ids.remove(alloc.vlan_id) except KeyError: # it's not allocatable, so check if its allocated if not alloc.allocated: # it's not, so remove it from table LOG.debug(_("Removing vlan %(vlan_id)s on " "physical network " "%(physical_network)s from pool"), {'vlan_id': alloc.vlan_id, 'physical_network': physical_network}) session.delete(alloc) del allocations[physical_network] # add missing allocatable vlans to table for vlan_id in sorted(vlan_ids): alloc = VlanAllocation(physical_network=physical_network, vlan_id=vlan_id, allocated=False) session.add(alloc) # remove from table unallocated vlans for any unconfigured # physical networks for allocs in allocations.itervalues(): for alloc in allocs: if not alloc.allocated: LOG.debug(_("Removing vlan %(vlan_id)s on physical " "network %(physical_network)s from pool"), {'vlan_id': alloc.vlan_id, 'physical_network': alloc.physical_network}) session.delete(alloc)
def find_ofc_item(model, quantum_id): session = db.get_session() try: return (session.query(model). filter_by(quantum_id=quantum_id). one()) except sa.orm.exc.NoResultFound: return None
def add_nexusport_binding(port_id, vlan_id): """Adds a nexusport binding""" LOG.debug("add_nexusport_binding() called") session = db.get_session() binding = nexus_models_v2.NexusPortBinding(port_id, vlan_id) session.add(binding) session.flush() return binding
def get_tunnel_allocation(tunnel_id): session = db.get_session() try: alloc = (session.query(ovs_models_v2.TunnelAllocation).filter_by( tunnel_id=tunnel_id).one()) return alloc except exc.NoResultFound: return
def get_port_from_device(device): """Get port from database.""" LOG.debug(_("get_port_from_device() called")) session = db.get_session() ports = session.query(models_v2.Port).all() for port in ports: if port['id'].startswith(device): return port
def get_vlan_allocation(physical_network, vlan_id): session = db.get_session() try: alloc = (session.query(ovs_models_v2.VlanAllocation).filter_by( physical_network=physical_network, vlan_id=vlan_id).one()) return alloc except exc.NoResultFound: return
def get_port_from_device(device): """Get port from database.""" LOG.debug(_("get_port_from_device() called")) session = db.get_session() ports = session.query(models_v2.Port).all() for port in ports: if port["id"].startswith(device): return port
def get_vlans(): session = db.get_session() try: bindings = (session.query(ovs_models_v2.VlanBinding). all()) except exc.NoResultFound: return [] return [(binding.vlan_id, binding.network_id) for binding in bindings]
def get_ovs_vlans(): session = db.get_session() try: bindings = (session.query( ovs_models_v2.VlanAllocation).filter_by(allocated=True).all()) except exc.NoResultFound: return [] return [binding.vlan_id for binding in bindings]
def get_network_binding_by_vlanid(session, vlan_id): session = session or db.get_session() try: binding = (session.query( nicira_models.NvpNetworkBinding).filter_by(vlan_id=vlan_id).one()) return binding except exc.NoResultFound: return
def get_network_bindings(session=None): session = session or db.get_session() try: binding = dict((bind.network_id, bind) for bind in session.query(rgos_models.RuijieNetworkBinding).all()) return binding except exc.NoResultFound: return None
def _create_all_tenant_network(self): for net in db_api_v2.network_all_tenant_list(): self.client.update_network(net.id) for tun in self.tunnel_key.all_list(): self.tun_client.update_tunnel_key(tun.network_id, tun.tunnel_key) session = db.get_session() for port in session.query(models_v2.Port): self.iface_client.update_network_id(port.id, port.network_id)
def get_network_binding(session, network_id): session = session or db.get_session() try: binding = (session.query(ovs_models_v2.NetworkBinding).filter_by( network_id=network_id).one()) return binding except exc.NoResultFound: return
def get_tunnel_endpoints(): session = db.get_session() try: tunnels = session.query(ovs_models_v2.TunnelEndpoint).all() except exc.NoResultFound: return [] return [{'id': tunnel.id, 'ip_address': tunnel.ip_address} for tunnel in tunnels]
def get_flavor_by_network(net_id): session = db.get_session() try: binding = (session.query( meta_models_v2.NetworkFlavor).filter_by(network_id=net_id).one()) except exc.NoResultFound: return None return binding.flavor
def get_flavor_by_router(router_id): session = db.get_session() try: binding = (session.query( meta_models_v2.RouterFlavor).filter_by(router_id=router_id).one()) except exc.NoResultFound: return None return binding.flavor
def get_portinfo(id): session = db.get_session() try: return (session.query(nmodels.PortInfo). filter_by(id=id). one()) except sa.orm.exc.NoResultFound: return None
def get_ofc_item(model, id): session = db.get_session() try: return (session.query(model). filter_by(id=id). one()) except sa.orm.exc.NoResultFound: return None
def get_network_binding(self, session, network_id): session = session or db_api.get_session() try: binding_q = session.query(hyperv_model.NetworkBinding) binding_q = binding_q.filter_by(network_id=network_id) return binding_q.one() except exc.NoResultFound: return
def get_tunnel_endpoints(): session = db.get_session() tunnels = session.query(ovs_models_v2.TunnelEndpoint) return [{ 'id': tunnel.id, 'ip_address': tunnel.ip_address } for tunnel in tunnels]
def get_all_nexusport_bindings(): """Lists all the nexusport bindings""" LOG.debug(_("get_all_nexusport_bindings() called")) session = db.get_session() try: bindings = session.query(nexus_models_v2.NexusPortBinding).all() return bindings except exc.NoResultFound: return []