11
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
12
# License for the specific language governing permissions and limitations
13
13
# under the License.
15
# @author: Ronak Shah, Nuage Networks, Alcatel-Lucent USA Inc.
41
39
from neutron.openstack.common import excutils
42
40
from neutron.openstack.common import importutils
43
41
from neutron.openstack.common import lockutils
42
from neutron.openstack.common import log as logging
43
from neutron.openstack.common import loopingcall
44
44
from neutron.plugins.nuage.common import config
45
45
from neutron.plugins.nuage.common import constants
46
46
from neutron.plugins.nuage.common import exceptions as nuage_exc
47
47
from neutron.plugins.nuage import extensions
48
48
from neutron.plugins.nuage.extensions import netpartition
49
49
from neutron.plugins.nuage import nuagedb
50
from neutron.plugins.nuage import syncmanager
50
51
from neutron import policy
53
LOG = logging.getLogger(__name__)
53
56
class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2,
54
57
external_net_db.External_net_db_mixin,
71
74
self.nuageclient_init()
72
75
net_partition = cfg.CONF.RESTPROXY.default_net_partition_name
73
76
self._create_default_net_partition(net_partition)
77
if cfg.CONF.SYNCMANAGER.enable_sync:
78
self.syncmanager = syncmanager.SyncManager(self.nuageclient)
79
self._synchronization_thread()
81
db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
82
attributes.NETWORKS, ['_extend_network_dict_provider_nuage'])
75
84
def nuageclient_init(self):
76
85
server = cfg.CONF.RESTPROXY.server
97
def _synchronization_thread(self):
98
sync_interval = cfg.CONF.SYNCMANAGER.sync_interval
99
fip_quota = str(cfg.CONF.RESTPROXY.default_floatingip_quota)
100
if sync_interval > 0:
101
sync_loop = loopingcall.FixedIntervalLoopingCall(
102
self.syncmanager.synchronize, fip_quota)
103
sync_loop.start(interval=sync_interval)
105
self.syncmanager.synchronize(fip_quota)
88
107
def _resource_finder(self, context, for_resource, resource, user_req):
89
108
match = re.match(attributes.UUID_PATTERN, user_req[resource])
264
283
net_partition = nuagedb.get_net_partition_by_id(
265
284
session, subnet_mapping['net_partition_id'])
266
285
self._create_update_port(context, port,
267
net_partition['np_name'])
286
net_partition['name'])
287
self._check_floatingip_update(context, port)
268
288
updated_port = self._make_port_dict(port)
269
289
sg_port = self._extend_port_dict_security_group(
375
395
subnets = self.get_subnets(context, filters=filters)
376
396
return bool(routers or subnets)
378
def _extend_network_dict_provider(self, context, network):
379
binding = nuagedb.get_network_binding(context.session, network['id'])
398
def _extend_network_dict_provider_nuage(self, network, net_db,
400
binding = net_db.pnetbinding if net_db else net_binding
381
402
network[pnet.NETWORK_TYPE] = binding.network_type
382
403
network[pnet.PHYSICAL_NETWORK] = binding.physical_network
415
436
return network_type, physical_network, segmentation_id
417
438
def create_network(self, context, network):
418
440
(network_type, physical_network,
419
441
vlan_id) = self._process_provider_create(context,
420
442
network['network'])
428
450
self._process_l3_create(context, net, network['network'])
429
451
if network_type == 'vlan':
430
nuagedb.add_network_binding(context.session, net['id'],
452
binding = nuagedb.add_network_binding(context.session,
432
455
physical_network, vlan_id)
433
self._extend_network_dict_provider(context, net)
456
self._extend_network_dict_provider_nuage(net, None, binding)
436
459
def _validate_update_network(self, context, id, network):
456
479
raise n_exc.NetworkInUse(net_id=id)
457
480
return (is_external_set, subnet)
459
def get_network(self, context, net_id, fields=None):
460
net = super(NuagePlugin, self).get_network(context,
463
self._extend_network_dict_provider(context, net)
464
return self._fields(net, fields)
466
def get_networks(self, context, filters=None, fields=None,
467
sorts=None, limit=None, marker=None, page_reverse=False):
468
nets = super(NuagePlugin,
469
self).get_networks(context, filters, None, sorts,
470
limit, marker, page_reverse)
472
self._extend_network_dict_provider(context, net)
474
return [self._fields(net, fields) for net in nets]
476
482
def update_network(self, context, id, network):
477
483
pnet._raise_if_updates_provider_attributes(network['network'])
478
484
with context.session.begin(subtransactions=True):
674
680
super(NuagePlugin, self).delete_subnet(context, id)
675
681
return self._delete_nuage_sharedresource(id)
683
filters = {'fixed_ips': {'subnet_id': [id]}}
684
ports = self.get_ports(context, filters)
686
if port['device_owner'] != os_constants.DEVICE_OWNER_DHCP:
687
raise n_exc.SubnetInUse(subnet_id=id)
677
689
subnet_l2dom = nuagedb.get_subnet_l2dom_by_id(context.session, id)
976
988
super(NuagePlugin, self).delete_router(context, id)
978
nuage_zone = self.nuageclient.get_zone_by_routerid(id)
979
if nuage_zone and not self._check_router_subnet_for_tenant(
990
if not self._check_router_subnet_for_tenant(
980
991
context, neutron_router['tenant_id']):
981
992
user_id, group_id = self.nuageclient.get_usergroup(
982
993
neutron_router['tenant_id'],
1084
1095
neutron_fip, port_id):
1085
1096
rtr_id = neutron_fip['router_id']
1086
1097
net_id = neutron_fip['floating_network_id']
1098
subn = nuagedb.get_ipalloc_for_fip(context.session,
1100
neutron_fip['floating_ip_address'])
1088
fip_pool = self.nuageclient.get_nuage_fip_pool_by_id(net_id)
1102
fip_pool = self.nuageclient.get_nuage_fip_pool_by_id(subn['subnet_id'])
1089
1103
if not fip_pool:
1090
msg = _('sharedresource %s not found on VSD') % net_id
1104
msg = _('sharedresource %s not found on VSD') % subn['subnet_id']
1091
1105
raise n_exc.BadRequest(resource='floatingip',
1215
1229
return neutron_fip
1217
def delete_floatingip(self, context, id):
1218
fip = self._get_floatingip(context, id)
1231
def delete_floatingip(self, context, fip_id):
1232
fip = self._get_floatingip(context, fip_id)
1219
1233
port_id = fip['fixed_port_id']
1220
1234
with context.session.begin(subtransactions=True):
1223
'neutron_port_id': id,
1237
'neutron_port_id': port_id,
1225
1239
nuage_port = self.nuageclient.get_nuage_port_by_id(params)
1226
1240
if (nuage_port and
1230
1244
'nuage_fip_id': None
1232
1246
self.nuageclient.update_nuage_vm_vport(params)
1233
rtr_id = fip['last_known_router_id']
1247
LOG.debug("Floating-ip %(fip)s is disassociated from "
1250
'vport': nuage_port['nuage_vport_id']})
1252
router_id = fip['router_id']
1254
router_id = fip['last_known_router_id']
1235
1257
ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
1236
1258
context.session,
1238
1260
if not ent_rtr_mapping:
1239
1261
msg = _('router %s is not associated with '
1240
'any net-partition') % rtr_id
1262
'any net-partition') % router_id
1241
1263
raise n_exc.BadRequest(resource='floatingip',
1244
1266
'router_id': ent_rtr_mapping['nuage_router_id'],
1247
1269
fip = self.nuageclient.get_nuage_fip_by_id(params)
1249
1271
self.nuageclient.delete_nuage_floatingip(
1250
1272
fip['nuage_fip_id'])
1251
super(NuagePlugin, self).delete_floatingip(context, id)
1273
LOG.debug('Floating-ip %s deleted from VSD', fip_id)
1275
super(NuagePlugin, self).delete_floatingip(context, fip_id)
1253
1277
def delete_security_group(self, context, id):
1254
1278
filters = {'security_group_id': [id]}