]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add device_owner attribute to port
authorNachi Ueno <nachi@nttmcl.com>
Mon, 13 Aug 2012 08:13:20 +0000 (08:13 +0000)
committerNachi Ueno <nachi@nttmcl.com>
Mon, 13 Aug 2012 21:28:36 +0000 (21:28 +0000)
in order for firewall logic to be able to poke a hole allowing traffic to/from a DHCP server,
we need to expose the IP being used for DHCP in a subnet to external entities.
This commit adds device_owner attribute, then dhcp-agent will update the device_owner value
of port to dhcp-agent.

Implement blueprint expose-dhcp-server-ip
Change-Id: I11283485bff8a3a3cf0b1a2716763ad32e43028a

quantum/agent/dhcp_agent.py
quantum/api/v2/attributes.py
quantum/db/db_base_plugin_v2.py
quantum/db/models_v2.py
quantum/tests/unit/test_api_v2.py
quantum/tests/unit/test_db_plugin.py

index 0643acbf57605e1fdbff2cbde438edbdb5bad7b7..5c4409cbc419ca4b12776d2e5701070a58e6964d 100644 (file)
@@ -182,7 +182,9 @@ class DhcpAgent(object):
             driver = self.dhcp_driver_cls(self.conf,
                                           network,
                                           self.conf.root_helper,
-                                          DeviceManager(self.conf, self.db))
+                                          DeviceManager(self.conf,
+                                                        self.db,
+                                                        'network:dhcp'))
             getattr(driver, action)()
 
         except Exception, e:
@@ -210,9 +212,10 @@ class DeviceManager(object):
                    help="The driver used to manage the virtual interface.")
     ]
 
-    def __init__(self, conf, db):
+    def __init__(self, conf, db, device_owner=''):
         self.conf = conf
         self.db = db
+        self.device_owner = device_owner
         if not conf.interface_driver:
             LOG.error(_('You must specify an interface driver'))
         self.driver = importutils.import_object(conf.interface_driver, conf)
@@ -294,6 +297,7 @@ class DeviceManager(object):
         body = dict(port=dict(
             admin_state_up=True,
             device_id=self.get_device_id(network),
+            device_owner=self.device_owner,
             network_id=network.id,
             tenant_id=network.tenant_id,
             fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
index c55caab12b0475b7e1f6c98bd1e26915af1c85ba..51d666967d9a6f36d4b522dea87d1b9c22281be5 100644 (file)
@@ -208,6 +208,9 @@ RESOURCE_ATTRIBUTE_MAP = {
         'device_id': {'allow_post': True, 'allow_put': True,
                       'default': '',
                       'is_visible': True},
+        'device_owner': {'allow_post': True, 'allow_put': True,
+                         'default': '',
+                         'is_visible': True},
         'tenant_id': {'allow_post': True, 'allow_put': False,
                       'required_by_policy': True,
                       'is_visible': True},
index 2f27bf2f59ba613f6f58cd003719e0140dc36145..3523c48ac16afed9b66a9e753d05ddbc57bb2b80 100644 (file)
@@ -679,7 +679,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                "fixed_ips": [{'subnet_id': ip["subnet_id"],
                               'ip_address': ip["ip_address"]}
                              for ip in port["fixed_ips"]],
-               "device_id": port["device_id"]}
+               "device_id": port["device_id"],
+               "device_owner": port["device_owner"]}
         return self._fields(res, fields)
 
     def _create_bulk(self, resource, context, request_items):
@@ -849,7 +850,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
                                   mac_address=p['mac_address'],
                                   admin_state_up=p['admin_state_up'],
                                   status="ACTIVE",
-                                  device_id=p['device_id'])
+                                  device_id=p['device_id'],
+                                  device_owner=p['device_owner'])
             context.session.add(port)
 
         # Update the allocated IP's
index b727e488137cf921be26b142863c5db26edc8b9d..32605af27e0ac3981322bbb015caa4ad2231d03b 100644 (file)
@@ -96,6 +96,7 @@ class Port(model_base.BASEV2, HasId, HasTenant):
     admin_state_up = sa.Column(sa.Boolean(), nullable=False)
     status = sa.Column(sa.String(16), nullable=False)
     device_id = sa.Column(sa.String(255), nullable=False)
+    device_owner = sa.Column(sa.String(255), nullable=False)
 
 
 class Subnet(model_base.BASEV2, HasId, HasTenant):
index 0c7360b8c75fc1a700bcbe2d8ee75fe684ef87de..055e7eec2f11d7e5e296b05136666560e83c950a 100644 (file)
@@ -600,13 +600,15 @@ class JSONV2TestCase(APIv2TestBase):
         full_input = {'port': {'admin_state_up': True,
                                'mac_address': attributes.ATTR_NOT_SPECIFIED,
                                'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
+                               'device_owner': '',
                                'host_routes': attributes.ATTR_NOT_SPECIFIED}}
         full_input['port'].update(initial_input['port'])
         return_value = {'id': _uuid(), 'status': 'ACTIVE',
                         'admin_state_up': True,
                         'mac_address': 'ca:fe:de:ad:be:ef',
                         'host_routes': [],
-                        'device_id': device_id}
+                        'device_id': device_id,
+                        'device_owner': ''}
         return_value.update(initial_input['port'])
 
         instance = self.plugin.return_value
index 24c1895275b45ebdf43d8ea53785b02b12aa89b8..897c3bd7f88aae0450b679eecd77fd20921d94f8 100644 (file)
@@ -215,9 +215,10 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
         content_type = 'application/' + fmt
         data = {'port': {'network_id': net_id,
                          'tenant_id': self._tenant_id}}
+
         for arg in ('admin_state_up', 'device_id',
-                    'mac_address', 'fixed_ips',
-                    'name', 'tenant_id'):
+                    'mac_address', 'name', 'fixed_ips',
+                    'tenant_id', 'device_owner'):
             # Arg must be present and not empty
             if arg in kwargs and kwargs[arg]:
                 data['port'][arg] = kwargs[arg]
@@ -494,6 +495,7 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
                              'tenant_id': 'bad_tenant_id',
                              'admin_state_up': True,
                              'device_id': 'fake_device',
+                             'device_owner': 'fake_owner',
                              'fixed_ips': []}}
 
             port_req = self.new_create_request('ports', data)