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:
parent
635c5bd48d
commit
80f35da022
@ -182,7 +182,9 @@ class DhcpAgent(object):
|
|||||||
driver = self.dhcp_driver_cls(self.conf,
|
driver = self.dhcp_driver_cls(self.conf,
|
||||||
network,
|
network,
|
||||||
self.conf.root_helper,
|
self.conf.root_helper,
|
||||||
DeviceManager(self.conf, self.db))
|
DeviceManager(self.conf,
|
||||||
|
self.db,
|
||||||
|
'network:dhcp'))
|
||||||
getattr(driver, action)()
|
getattr(driver, action)()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@ -210,9 +212,10 @@ class DeviceManager(object):
|
|||||||
help="The driver used to manage the virtual interface.")
|
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.conf = conf
|
||||||
self.db = db
|
self.db = db
|
||||||
|
self.device_owner = device_owner
|
||||||
if not conf.interface_driver:
|
if not conf.interface_driver:
|
||||||
LOG.error(_('You must specify an interface driver'))
|
LOG.error(_('You must specify an interface driver'))
|
||||||
self.driver = importutils.import_object(conf.interface_driver, conf)
|
self.driver = importutils.import_object(conf.interface_driver, conf)
|
||||||
@ -294,6 +297,7 @@ class DeviceManager(object):
|
|||||||
body = dict(port=dict(
|
body = dict(port=dict(
|
||||||
admin_state_up=True,
|
admin_state_up=True,
|
||||||
device_id=self.get_device_id(network),
|
device_id=self.get_device_id(network),
|
||||||
|
device_owner=self.device_owner,
|
||||||
network_id=network.id,
|
network_id=network.id,
|
||||||
tenant_id=network.tenant_id,
|
tenant_id=network.tenant_id,
|
||||||
fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
|
fixed_ips=[dict(subnet_id=s.id) for s in network.subnets]))
|
||||||
|
@ -208,6 +208,9 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||||||
'device_id': {'allow_post': True, 'allow_put': True,
|
'device_id': {'allow_post': True, 'allow_put': True,
|
||||||
'default': '',
|
'default': '',
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
|
'device_owner': {'allow_post': True, 'allow_put': True,
|
||||||
|
'default': '',
|
||||||
|
'is_visible': True},
|
||||||
'tenant_id': {'allow_post': True, 'allow_put': False,
|
'tenant_id': {'allow_post': True, 'allow_put': False,
|
||||||
'required_by_policy': True,
|
'required_by_policy': True,
|
||||||
'is_visible': True},
|
'is_visible': True},
|
||||||
|
@ -679,7 +679,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
"fixed_ips": [{'subnet_id': ip["subnet_id"],
|
"fixed_ips": [{'subnet_id': ip["subnet_id"],
|
||||||
'ip_address': ip["ip_address"]}
|
'ip_address': ip["ip_address"]}
|
||||||
for ip in port["fixed_ips"]],
|
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)
|
return self._fields(res, fields)
|
||||||
|
|
||||||
def _create_bulk(self, resource, context, request_items):
|
def _create_bulk(self, resource, context, request_items):
|
||||||
@ -849,7 +850,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
|||||||
mac_address=p['mac_address'],
|
mac_address=p['mac_address'],
|
||||||
admin_state_up=p['admin_state_up'],
|
admin_state_up=p['admin_state_up'],
|
||||||
status="ACTIVE",
|
status="ACTIVE",
|
||||||
device_id=p['device_id'])
|
device_id=p['device_id'],
|
||||||
|
device_owner=p['device_owner'])
|
||||||
context.session.add(port)
|
context.session.add(port)
|
||||||
|
|
||||||
# Update the allocated IP's
|
# Update the allocated IP's
|
||||||
|
@ -96,6 +96,7 @@ class Port(model_base.BASEV2, HasId, HasTenant):
|
|||||||
admin_state_up = sa.Column(sa.Boolean(), nullable=False)
|
admin_state_up = sa.Column(sa.Boolean(), nullable=False)
|
||||||
status = sa.Column(sa.String(16), nullable=False)
|
status = sa.Column(sa.String(16), nullable=False)
|
||||||
device_id = sa.Column(sa.String(255), 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):
|
class Subnet(model_base.BASEV2, HasId, HasTenant):
|
||||||
|
@ -600,13 +600,15 @@ class JSONV2TestCase(APIv2TestBase):
|
|||||||
full_input = {'port': {'admin_state_up': True,
|
full_input = {'port': {'admin_state_up': True,
|
||||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||||
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
|
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
|
||||||
|
'device_owner': '',
|
||||||
'host_routes': attributes.ATTR_NOT_SPECIFIED}}
|
'host_routes': attributes.ATTR_NOT_SPECIFIED}}
|
||||||
full_input['port'].update(initial_input['port'])
|
full_input['port'].update(initial_input['port'])
|
||||||
return_value = {'id': _uuid(), 'status': 'ACTIVE',
|
return_value = {'id': _uuid(), 'status': 'ACTIVE',
|
||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'mac_address': 'ca:fe:de:ad:be:ef',
|
'mac_address': 'ca:fe:de:ad:be:ef',
|
||||||
'host_routes': [],
|
'host_routes': [],
|
||||||
'device_id': device_id}
|
'device_id': device_id,
|
||||||
|
'device_owner': ''}
|
||||||
return_value.update(initial_input['port'])
|
return_value.update(initial_input['port'])
|
||||||
|
|
||||||
instance = self.plugin.return_value
|
instance = self.plugin.return_value
|
||||||
|
@ -215,9 +215,10 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
|
|||||||
content_type = 'application/' + fmt
|
content_type = 'application/' + fmt
|
||||||
data = {'port': {'network_id': net_id,
|
data = {'port': {'network_id': net_id,
|
||||||
'tenant_id': self._tenant_id}}
|
'tenant_id': self._tenant_id}}
|
||||||
|
|
||||||
for arg in ('admin_state_up', 'device_id',
|
for arg in ('admin_state_up', 'device_id',
|
||||||
'mac_address', 'fixed_ips',
|
'mac_address', 'name', 'fixed_ips',
|
||||||
'name', 'tenant_id'):
|
'tenant_id', 'device_owner'):
|
||||||
# Arg must be present and not empty
|
# Arg must be present and not empty
|
||||||
if arg in kwargs and kwargs[arg]:
|
if arg in kwargs and kwargs[arg]:
|
||||||
data['port'][arg] = kwargs[arg]
|
data['port'][arg] = kwargs[arg]
|
||||||
@ -494,6 +495,7 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
|
|||||||
'tenant_id': 'bad_tenant_id',
|
'tenant_id': 'bad_tenant_id',
|
||||||
'admin_state_up': True,
|
'admin_state_up': True,
|
||||||
'device_id': 'fake_device',
|
'device_id': 'fake_device',
|
||||||
|
'device_owner': 'fake_owner',
|
||||||
'fixed_ips': []}}
|
'fixed_ips': []}}
|
||||||
|
|
||||||
port_req = self.new_create_request('ports', data)
|
port_req = self.new_create_request('ports', data)
|
||||||
|
Loading…
Reference in New Issue
Block a user