本文整理汇总了Python中quantum.db.api.get_session函数的典型用法代码示例。如果您正苦于以下问题:Python get_session函数的具体用法?Python get_session怎么用?Python get_session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_vlan_id_pool
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)
示例2: ofp_has_servers
def ofp_has_servers():
session = db.get_session()
try:
session.query(models.OFPServers).first()
return True
except exc.NoResultFound:
return False
示例3: get_plugged_port
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
示例4: get_port_properties
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
示例5: sync_vlan_allocations
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)
示例6: test_key_allocation
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(), [])
示例7: get_device_details
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
示例8: update_vlan_id_pool
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)
示例9: update_portbinding
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)
示例10: get_port
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
示例11: port_binding_get
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()
示例12: create_vlanids
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
示例13: set_ofp_servers
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()
示例14: test_invalid_specific_vlan_id
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)
示例15: reserve_vlanid
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()