]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Merge "Midonet to support port association at floating IP creation"
authorJenkins <jenkins@review.openstack.org>
Thu, 5 Dec 2013 14:09:51 +0000 (14:09 +0000)
committerGerrit Code Review <review@openstack.org>
Thu, 5 Dec 2013 14:09:51 +0000 (14:09 +0000)
1  2 
neutron/plugins/midonet/plugin.py
neutron/tests/unit/midonet/test_midonet_plugin.py

index 8016ef56abea8f3008694e47bd3ee65608b76d5f,1884baad78fd6f242861617a447df101cdc79df2..e4bdb995595ebe1f63cf17023416f31fac0a4738
@@@ -1044,8 -1026,42 +1044,42 @@@ class MidonetPluginV2(db_base_plugin_v2
                      "info=%r"), info)
          return info
  
+     def _assoc_fip(self, fip):
+         router = self.client.get_router(fip["router_id"])
+         link_port = self.client.get_link_port(
+             self._get_provider_router(), router.get_id())
+         self.client.add_router_route(
+             self._get_provider_router(),
+             src_network_addr='0.0.0.0',
+             src_network_length=0,
+             dst_network_addr=fip["floating_ip_address"],
+             dst_network_length=32,
+             next_hop_port=link_port.get_peer_id())
+         props = {OS_FLOATING_IP_RULE_KEY: fip['id']}
+         tenant_id = router.get_tenant_id()
+         chain_names = _nat_chain_names(router.get_id())
+         for chain_type, name in chain_names.items():
+             src_ip, target_ip = _get_nat_ips(chain_type, fip)
+             if chain_type == 'pre-routing':
+                 nat_type = 'dnat'
+             else:
+                 nat_type = 'snat'
+             self.client.add_static_nat(tenant_id, name, src_ip,
+                                        target_ip,
+                                        link_port.get_id(),
+                                        nat_type, **props)
+     def create_floatingip(self, context, floatingip):
+         session = context.session
+         with session.begin(subtransactions=True):
+             fip = super(MidonetPluginV2, self).create_floatingip(
+                 context, floatingip)
+             if fip['port_id']:
+                 self._assoc_fip(fip)
+         return fip
      def update_floatingip(self, context, id, floatingip):
 -        """Handle floating IP assocation and disassociation."""
 +        """Handle floating IP association and disassociation."""
          LOG.debug(_("MidonetPluginV2.update_floatingip called: id=%(id)s "
                      "floatingip=%(floatingip)s "),
                    {'id': id, 'floatingip': floatingip})