79
80
def get_bridge_name(self, network_id):
81
LOG.warning("Invalid Network ID, will lead to incorrect bridge"
82
LOG.warning(_("Invalid Network ID, will lead to incorrect bridge"
83
84
bridge_name = BRIDGE_NAME_PREFIX + network_id[0:11]
86
87
def get_subinterface_name(self, physical_interface, vlan_id):
88
LOG.warning("Invalid VLAN ID, will lead to incorrect "
89
LOG.warning(_("Invalid VLAN ID, will lead to incorrect "
90
91
subinterface_name = '%s.%s' % (physical_interface, vlan_id)
91
92
return subinterface_name
93
94
def get_tap_device_name(self, interface_id):
94
95
if not interface_id:
95
LOG.warning("Invalid Interface ID, will lead to incorrect "
96
LOG.warning(_("Invalid Interface ID, will lead to incorrect "
97
98
tap_device_name = TAP_INTERFACE_PREFIX + interface_id[0:11]
98
99
return tap_device_name
187
188
"""Create a vlan unless it already exists."""
188
189
interface = self.get_subinterface_name(physical_interface, vlan_id)
189
190
if not self.device_exists(interface):
190
LOG.debug("Creating subinterface %s for VLAN %s on interface %s" %
191
(interface, vlan_id, physical_interface))
191
LOG.debug(_("Creating subinterface %(interface)s for "
192
"VLAN %(vlan_id)s on interface "
193
"%(physical_interface)s"),
192
195
if utils.execute(['ip', 'link', 'add', 'link',
193
196
physical_interface,
194
197
'name', interface, 'type', 'vlan', 'id',
343
347
if interface.startswith(physical_interface):
344
348
self.delete_vlan(interface)
346
LOG.debug("Deleting bridge %s" % bridge_name)
350
LOG.debug(_("Deleting bridge %s"), bridge_name)
347
351
if utils.execute(['ip', 'link', 'set', bridge_name, 'down'],
348
352
root_helper=self.root_helper):
350
354
if utils.execute(['brctl', 'delbr', bridge_name],
351
355
root_helper=self.root_helper):
353
LOG.debug("Done deleting bridge %s" % bridge_name)
357
LOG.debug(_("Done deleting bridge %s"), bridge_name)
356
LOG.error("Cannot delete bridge %s, does not exist" % bridge_name)
360
LOG.error(_("Cannot delete bridge %s, does not exist"),
358
363
def remove_interface(self, bridge_name, interface_name):
359
364
if self.device_exists(bridge_name):
360
365
if not self.is_device_on_bridge(interface_name):
362
LOG.debug("Removing device %s from bridge %s" %
363
(interface_name, bridge_name))
367
LOG.debug(_("Removing device %(interface_name)s from bridge "
368
"%(bridge_name)s"), locals())
364
369
if utils.execute(['brctl', 'delif', bridge_name, interface_name],
365
370
root_helper=self.root_helper):
367
LOG.debug("Done removing device %s from bridge %s" %
368
(interface_name, bridge_name))
372
LOG.debug(_("Done removing device %(interface_name)s from bridge "
373
"%(bridge_name)s"), locals())
371
LOG.debug("Cannot remove device %s, bridge %s does not exist" %
372
(interface_name, bridge_name))
376
LOG.debug(_("Cannot remove device %(interface_name)s bridge "
377
"%(bridge_name)s does not exist"), locals())
375
380
def delete_vlan(self, interface):
376
381
if self.device_exists(interface):
377
LOG.debug("Deleting subinterface %s for vlan" % interface)
382
LOG.debug(_("Deleting subinterface %s for vlan"), interface)
378
383
if utils.execute(['ip', 'link', 'set', interface, 'down'],
379
384
root_helper=self.root_helper):
381
386
if utils.execute(['ip', 'link', 'delete', interface],
382
387
root_helper=self.root_helper):
384
LOG.debug("Done deleting subinterface %s" % interface)
387
class LinuxBridgeRpcCallbacks():
389
LOG.debug(_("Done deleting subinterface %s"), interface)
392
class LinuxBridgeRpcCallbacks(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
389
394
# Set RPC API version to 1.0 by default.
390
RPC_API_VERSION = '1.0'
396
# 1.1 Support Security Group RPC
397
RPC_API_VERSION = '1.1'
392
def __init__(self, context, linux_br):
399
def __init__(self, context, agent):
393
400
self.context = context
394
self.linux_br = linux_br
402
self.linux_br = agent.linux_br
396
404
def network_delete(self, context, **kwargs):
397
LOG.debug("network_delete received")
405
LOG.debug(_("network_delete received"))
398
406
network_id = kwargs.get('network_id')
399
407
bridge_name = self.linux_br.get_bridge_name(network_id)
400
LOG.debug("Delete %s", bridge_name)
408
LOG.debug(_("Delete %s"), bridge_name)
401
409
self.linux_br.delete_vlan_bridge(bridge_name)
403
411
def port_update(self, context, **kwargs):
404
LOG.debug("port_update received")
412
LOG.debug(_("port_update received"))
405
413
port = kwargs.get('port')
414
if 'security_groups' in port:
415
self.agent.refresh_firewall()
406
417
if port['admin_state_up']:
407
418
vlan_id = kwargs.get('vlan_id')
408
419
physical_network = kwargs.get('physical_network')
443
460
mac = utils.get_interface_mac(devices[0].name)
445
LOG.error("Unable to obtain MAC address for unique ID. "
462
LOG.error(_("Unable to obtain MAC address for unique ID. "
463
"Agent terminated!"))
448
465
self.agent_id = '%s%s' % ('lb', (mac.replace(":", "")))
449
LOG.info("RPC agent_id: %s" % self.agent_id)
466
LOG.info(_("RPC agent_id: %s"), self.agent_id)
451
468
self.topic = topics.AGENT
452
self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN)
469
self.plugin_rpc = LinuxBridgePluginApi(topics.PLUGIN)
454
471
# RPC network init
455
472
self.context = context.get_admin_context_without_session()
456
473
# Handle updates from service
457
474
self.callbacks = LinuxBridgeRpcCallbacks(self.context,
459
476
self.dispatcher = self.callbacks.create_rpc_dispatcher()
460
477
# Define the listening consumers for the agent
461
478
consumers = [[topics.PORT, topics.UPDATE],
462
[topics.NETWORK, topics.DELETE]]
479
[topics.NETWORK, topics.DELETE],
480
[topics.SECURITY_GROUP, topics.UPDATE]]
463
481
self.connection = agent_rpc.create_consumers(self.dispatcher,
512
530
def treat_devices_added(self, devices):
532
self.prepare_devices_filter(devices)
514
533
for device in devices:
515
LOG.debug("Port %s added", device)
534
LOG.debug(_("Port %s added"), device)
517
536
details = self.plugin_rpc.get_device_details(self.context,
520
539
except Exception as e:
521
LOG.debug("Unable to get port details for %s: %s", device, e)
540
LOG.debug(_("Unable to get port details for "
541
"%(device)s: %(e)s"), locals())
524
544
if 'port_id' in details:
525
LOG.info("Port %s updated. Details: %s", device, details)
545
LOG.info(_("Port %(device)s updated. Details: %(details)s"),
526
547
if details['admin_state_up']:
527
548
# create the networking for the port
528
549
self.linux_br.add_interface(details['network_id'],
533
554
self.remove_port_binding(details['network_id'],
534
555
details['port_id'])
536
LOG.info("Device %s not defined on plugin", device)
557
LOG.info(_("Device %s not defined on plugin"), device)
539
560
def treat_devices_removed(self, devices):
562
self.remove_devices_filter(devices)
541
563
for device in devices:
542
LOG.info("Attachment %s removed", device)
564
LOG.info(_("Attachment %s removed"), device)
544
566
details = self.plugin_rpc.update_device_down(self.context,
547
569
except Exception as e:
548
LOG.debug("port_removed failed for %s: %s", device, e)
570
LOG.debug(_("port_removed failed for %(device)s: %(e)s"),
550
573
if details['exists']:
551
LOG.info("Port %s updated.", device)
574
LOG.info(_("Port %s updated."), device)
552
575
# Nothing to do regarding local networking
554
LOG.debug("Device %s not defined on plugin", device)
577
LOG.debug(_("Device %s not defined on plugin"), device)
557
580
def daemon_loop(self):
561
LOG.info("LinuxBridge Agent RPC Daemon Started!")
584
LOG.info(_("LinuxBridge Agent RPC Daemon Started!"))
564
587
start = time.time()
566
LOG.info("Agent out of sync with plugin!")
589
LOG.info(_("Agent out of sync with plugin!"))
581
604
if (elapsed < self.polling_interval):
582
605
time.sleep(self.polling_interval - elapsed)
584
LOG.debug("Loop iteration exceeded interval (%s vs. %s)!",
585
self.polling_interval, elapsed)
607
LOG.debug(_("Loop iteration exceeded interval "
608
"(%(polling_interval)s vs. %(elapsed)s)!"),
609
{'polling_interval': self.polling_interval,
589
614
eventlet.monkey_patch()
590
615
cfg.CONF(args=sys.argv, project='quantum')
592
# (TODO) gary - swap with common logging
593
616
logging_config.setup_logging(cfg.CONF)
596
618
interface_mappings = q_utils.parse_mappings(
597
619
cfg.CONF.LINUX_BRIDGE.physical_interface_mappings)