~niedbalski/ubuntu/vivid/neutron/fixes-1447803

« back to all changes in this revision

Viewing changes to neutron/plugins/nuage/plugin.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-10-03 18:45:23 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20141003184523-4mt6dy1q3j8n30c9
Tags: 1:2014.2~rc1-0ubuntu1
* New upstream release candidate:
  - d/p/*: Refreshed.
  - d/control: Add python-requests-mock to BD's.
  - d/control: Align versioned requirements with upstream.
* Transition linuxbridge and openvswitch plugin users to modular
  layer 2 plugin (LP: #1323729):
  - d/control: Mark removed plugin packages as transitional, depend
    on neutron-plugin-ml2, mark oldlibs/extra.
  - d/neutron-plugin-{linuxbridge,openvswitch}.install: Drop.
  - d/control: Depend on neutron-plugin-ml2 for linuxbridge
    agent package.
  - d/neutron-plugin-linuxbridge-agent.upstart: Use ml2 plugin
    configuration files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
14
 
#
15
 
# @author: Ronak Shah, Nuage Networks, Alcatel-Lucent USA Inc.
16
14
 
17
15
import copy
18
16
import re
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
51
52
 
 
53
LOG = logging.getLogger(__name__)
 
54
 
52
55
 
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()
 
80
 
 
81
    db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs(
 
82
        attributes.NETWORKS, ['_extend_network_dict_provider_nuage'])
74
83
 
75
84
    def nuageclient_init(self):
76
85
        server = cfg.CONF.RESTPROXY.server
85
94
                                                   auth_resource,
86
95
                                                   organization)
87
96
 
 
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)
 
104
        else:
 
105
            self.syncmanager.synchronize(fip_quota)
 
106
 
88
107
    def _resource_finder(self, context, for_resource, resource, user_req):
89
108
        match = re.match(attributes.UUID_PATTERN, user_req[resource])
90
109
        if match:
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(
270
290
                    updated_port,
375
395
        subnets = self.get_subnets(context, filters=filters)
376
396
        return bool(routers or subnets)
377
397
 
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,
 
399
                                            net_binding=None):
 
400
        binding = net_db.pnetbinding if net_db else net_binding
380
401
        if 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
416
437
 
417
438
    def create_network(self, context, network):
 
439
        binding = None
418
440
        (network_type, physical_network,
419
441
         vlan_id) = self._process_provider_create(context,
420
442
                                                  network['network'])
427
449
                                                          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,
 
453
                                            net['id'],
431
454
                                            network_type,
432
455
                                            physical_network, vlan_id)
433
 
            self._extend_network_dict_provider(context, net)
 
456
            self._extend_network_dict_provider_nuage(net, None, binding)
434
457
        return net
435
458
 
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)
458
481
 
459
 
    def get_network(self, context, net_id, fields=None):
460
 
        net = super(NuagePlugin, self).get_network(context,
461
 
                                                   net_id,
462
 
                                                   None)
463
 
        self._extend_network_dict_provider(context, net)
464
 
        return self._fields(net, fields)
465
 
 
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)
471
 
        for net in nets:
472
 
            self._extend_network_dict_provider(context, net)
473
 
 
474
 
        return [self._fields(net, fields) for net in nets]
475
 
 
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)
676
682
 
 
683
        filters = {'fixed_ips': {'subnet_id': [id]}}
 
684
        ports = self.get_ports(context, filters)
 
685
        for port in ports:
 
686
            if port['device_owner'] != os_constants.DEVICE_OWNER_DHCP:
 
687
                raise n_exc.SubnetInUse(subnet_id=id)
 
688
 
677
689
        subnet_l2dom = nuagedb.get_subnet_l2dom_by_id(context.session, id)
678
690
        if subnet_l2dom:
679
691
            try:
975
987
 
976
988
        super(NuagePlugin, self).delete_router(context, id)
977
989
 
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,
 
1099
                                           net_id,
 
1100
                                           neutron_fip['floating_ip_address'])
1087
1101
 
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',
1092
1106
                                   msg=msg)
1093
1107
 
1214
1228
 
1215
1229
        return neutron_fip
1216
1230
 
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):
1221
1235
            if port_id:
1222
1236
                params = {
1223
 
                    'neutron_port_id': id,
 
1237
                    'neutron_port_id': port_id,
1224
1238
                }
1225
1239
                nuage_port = self.nuageclient.get_nuage_port_by_id(params)
1226
1240
                if (nuage_port and
1230
1244
                        'nuage_fip_id': None
1231
1245
                    }
1232
1246
                    self.nuageclient.update_nuage_vm_vport(params)
1233
 
            rtr_id = fip['last_known_router_id']
1234
 
            if rtr_id:
 
1247
                    LOG.debug("Floating-ip %(fip)s is disassociated from "
 
1248
                              "vport %(vport)s",
 
1249
                              {'fip': fip_id,
 
1250
                               'vport': nuage_port['nuage_vport_id']})
 
1251
 
 
1252
                router_id = fip['router_id']
 
1253
            else:
 
1254
                router_id = fip['last_known_router_id']
 
1255
 
 
1256
            if router_id:
1235
1257
                ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
1236
1258
                    context.session,
1237
 
                    rtr_id)
 
1259
                    router_id)
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',
1242
1264
                                       msg=msg)
1243
1265
                params = {
1244
1266
                    'router_id': ent_rtr_mapping['nuage_router_id'],
1245
 
                    'fip_id': id
 
1267
                    'fip_id': fip_id
1246
1268
                }
1247
1269
                fip = self.nuageclient.get_nuage_fip_by_id(params)
1248
1270
                if fip:
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)
 
1274
 
 
1275
            super(NuagePlugin, self).delete_floatingip(context, fip_id)
1252
1276
 
1253
1277
    def delete_security_group(self, context, id):
1254
1278
        filters = {'security_group_id': [id]}