本文整理汇总了Python中neutron.plugins.ml2.db.add_network_segment函数的典型用法代码示例。如果您正苦于以下问题:Python add_network_segment函数的具体用法?Python add_network_segment怎么用?Python add_network_segment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_network_segment函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _bind_segment_to_vif_type
def _bind_segment_to_vif_type(self, context, agent=None):
mappings = {}
if agent:
mappings = agent['configurations'].get('bridge_mappings', {})
for res in self.resource_groups:
if agent and res['ResourceGroupName'] not in mappings:
continue
if res['device_owner'] != context._port['device_owner']:
continue
network_id = context.network.current['id']
dummy_segment = db.get_dynamic_segment(
context.network._plugin_context.session,
network_id, physical_network=res['ResourceGroupName'])
LOG.debug("1st: dummy segment is %s", dummy_segment)
if not dummy_segment:
dummy_segment = {
api.PHYSICAL_NETWORK: res['ResourceGroupName'],
api.NETWORK_TYPE: plugin_const.TYPE_VLAN,
api.SEGMENTATION_ID: 0
}
db.add_network_segment(
context.network._plugin_context.session,
network_id, dummy_segment, is_dynamic=True)
LOG.debug("2nd: dummy segment is %s", dummy_segment)
context.set_binding(dummy_segment[api.ID],
self.vif_type,
{portbindings.CAP_PORT_FILTER: True,
portbindings.OVS_HYBRID_PLUG: True})
return True
return False
示例2: create_network
def create_network(self, context, network):
net_data = network['network']
segments = self._process_provider_create(net_data)
tenant_id = self._get_tenant_id_for_create(context, net_data)
session = context.session
with session.begin(subtransactions=True):
self._ensure_default_security_group(context, tenant_id)
result = super(Ml2Plugin, self).create_network(context, network)
network_id = result['id']
self._process_l3_create(context, result, net_data)
# REVISIT(rkukura): Consider moving all segment management
# to TypeManager.
if segments:
for segment in segments:
self.type_manager.reserve_provider_segment(session,
segment)
db.add_network_segment(session, network_id, segment)
else:
segment = self.type_manager.allocate_tenant_segment(session)
db.add_network_segment(session, network_id, segment)
self._extend_network_dict_provider(context, result)
mech_context = driver_context.NetworkContext(self, context,
result)
self.mechanism_manager.create_network_precommit(mech_context)
try:
self.mechanism_manager.create_network_postcommit(mech_context)
except ml2_exc.MechanismDriverError:
with excutils.save_and_reraise_exception():
LOG.error(_("mechanism_manager.create_network_postcommit "
"failed, deleting network '%s'"), result['id'])
self.delete_network(context, result['id'])
return result
示例3: _create_segments
def _create_segments(self, segments, is_seg_dynamic=False, network_id="foo-network-id"):
self._setup_neutron_network(network_id)
for segment in segments:
ml2_db.add_network_segment(self.ctx.session, network_id, segment, is_dynamic=is_seg_dynamic)
net_segments = ml2_db.get_network_segments(self.ctx.session, network_id, filter_dynamic=is_seg_dynamic)
for segment_index, segment in enumerate(segments):
self.assertEqual(segment, net_segments[segment_index])
return net_segments
示例4: allocate_dynamic_segment
def allocate_dynamic_segment(self, session, network_id, segment):
"""Allocate a dynamic segment using a partial or full segment dict."""
dynamic_segment = db.get_dynamic_segment(
session, network_id, segment.get(api.PHYSICAL_NETWORK), segment.get(api.SEGMENTATION_ID)
)
if dynamic_segment:
return dynamic_segment
driver = self.drivers.get(segment.get(api.NETWORK_TYPE))
dynamic_segment = driver.obj.reserve_provider_segment(session, segment)
db.add_network_segment(session, network_id, dynamic_segment, is_dynamic=True)
return dynamic_segment
示例5: create_network_segments
def create_network_segments(self, context, network, tenant_id):
"""Call type drivers to create network segments."""
segments = self._process_provider_create(network)#验证参数以及创建网络segments
session = context.session
with session.begin(subtransactions=True):
network_id = network['id']
if segments:
for segment in segments:
segment = self.reserve_provider_segment(
session, segment)
db.add_network_segment(session, network_id, segment)
else:
segment = self.allocate_tenant_segment(session)
db.add_network_segment(session, network_id, segment)
示例6: create_network_segments
def create_network_segments(self, context, network, tenant_id):
"""Call type drivers to create network segments."""
segments = self._process_provider_create(network)
session = context.session
mtu = []
with session.begin(subtransactions=True):
network_id = network['id']
if segments:
for segment_index, segment in enumerate(segments):
segment = self.reserve_provider_segment(
session, segment)
db.add_network_segment(session, network_id,
segment, segment_index)
if segment.get(api.MTU) > 0:
mtu.append(segment[api.MTU])
else:
segment = self.allocate_tenant_segment(session)
db.add_network_segment(session, network_id, segment)
if segment.get(api.MTU) > 0:
mtu.append(segment[api.MTU])
network[api.MTU] = min(mtu) if mtu else 0
示例7: create_network
def create_network(self, context, network):
attrs = network['network']
segment = self._process_provider_create(context, attrs)
tenant_id = self._get_tenant_id_for_create(context, attrs)
session = context.session
with session.begin(subtransactions=True):
self._ensure_default_security_group(context, tenant_id)
if segment:
self.type_manager.reserve_provider_segment(session, segment)
else:
segment = self.type_manager.allocate_tenant_segment(session)
result = super(Ml2Plugin, self).create_network(context, network)
id = result['id']
self._process_l3_create(context, result, attrs)
# REVISIT(rkukura): Consider moving all segment management
# to TypeManager.
db.add_network_segment(session, id, segment)
self._extend_network_dict_provider(context, result)
return result
示例8: _bind_segment_to_vif_type
def _bind_segment_to_vif_type(self, context, physical_network):
if self.multi_dc:
return
network_id = context.network.current['id']
session = context.network._plugin_context.session
dummy_segment = db.get_dynamic_segment(
session, network_id, physical_network=physical_network)
LOG.debug("1st: dummy segment is %s", dummy_segment)
if not dummy_segment:
dummy_segment = {
api.PHYSICAL_NETWORK: physical_network,
api.NETWORK_TYPE: plugin_const.TYPE_VLAN,
api.SEGMENTATION_ID: 0
}
db.add_network_segment(
session, network_id, dummy_segment, is_dynamic=True)
LOG.debug("2nd: dummy segment is %s", dummy_segment)
context.set_binding(dummy_segment[api.ID],
self.vif_type,
{portbindings.CAP_PORT_FILTER: True,
portbindings.OVS_HYBRID_PLUG: True})
示例9: _add_network_segment
def _add_network_segment(self, session, network_id, segment, mtu,
segment_index=0):
db.add_network_segment(session, network_id, segment, segment_index)
if segment.get(api.MTU, 0) > 0:
mtu.append(segment[api.MTU])