Add device_owner attribute to port

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
This commit is contained in:
Nachi Ueno 2012-08-13 08:13:20 +00:00
parent 91330cffc9
commit ea17206811
6 changed files with 21 additions and 7 deletions

View 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]))

View 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},

View 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

View 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):

View 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

View 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)