from neutron import context
from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
+from neutron.openstack.common.gettextutils import _LE, _LI, _LW
from neutron.plugins.common import constants as p_const
from neutron.plugins.openvswitch.common import constants
self.use_call = False
self.agent_state.pop('start_flag', None)
except Exception:
- LOG.exception(_("Failed reporting state!"))
+ LOG.exception(_LE("Failed reporting state!"))
def setup_rpc(self):
self.agent_id = 'ovs-agent-%s' % cfg.CONF.host
return network_id
def network_delete(self, context, **kwargs):
- LOG.debug(_("network_delete received"))
+ LOG.debug("network_delete received")
network_id = kwargs.get('network_id')
- LOG.debug(_("Delete %s"), network_id)
+ LOG.debug("Delete %s", network_id)
# The network may not be defined on this agent
lvm = self.local_vlan_map.get(network_id)
if lvm:
self.reclaim_local_vlan(network_id)
else:
- LOG.debug(_("Network %s not used on agent."), network_id)
+ LOG.debug("Network %s not used on agent.", network_id)
def port_update(self, context, **kwargs):
port = kwargs.get('port')
# they are not used since there is no guarantee the notifications
# are processed in the same order as the relevant API requests
self.updated_ports.add(port['id'])
- LOG.debug(_("port_update message processed for port %s"), port['id'])
+ LOG.debug("port_update message processed for port %s", port['id'])
def tunnel_update(self, context, **kwargs):
- LOG.debug(_("tunnel_update received"))
+ LOG.debug("tunnel_update received")
if not self.enable_tunneling:
return
tunnel_ip = kwargs.get('tunnel_ip')
return
tunnel_type = kwargs.get('tunnel_type')
if not tunnel_type:
- LOG.error(_("No tunnel_type specified, cannot create tunnels"))
+ LOG.error(_LE("No tunnel_type specified, cannot create tunnels"))
return
if tunnel_type not in self.tunnel_types:
- LOG.error(_("tunnel_type %s not supported by agent"), tunnel_type)
+ LOG.error(_LE("tunnel_type %s not supported by agent"),
+ tunnel_type)
return
if tunnel_ip == self.local_ip:
return
dl_vlan=local_vid,
nw_dst='%s' % ip)
else:
- LOG.warning(_('Action %s not supported'), action)
+ LOG.warning(_LW('Action %s not supported'), action)
def provision_local_vlan(self, net_uuid, network_type, physical_network,
segmentation_id):
lvid = lvm.vlan
else:
if not self.available_local_vlans:
- LOG.error(_("No local VLAN available for net-id=%s"), net_uuid)
+ LOG.error(_LE("No local VLAN available for net-id=%s"),
+ net_uuid)
return
lvid = self.available_local_vlans.pop()
self.local_vlan_map[net_uuid] = LocalVLANMapping(lvid,
physical_network,
segmentation_id)
- LOG.info(_("Assigning %(vlan_id)s as local vlan for "
- "net-id=%(net_uuid)s"),
+ LOG.info(_LI("Assigning %(vlan_id)s as local vlan for "
+ "net-id=%(net_uuid)s"),
{'vlan_id': lvid, 'net_uuid': net_uuid})
if network_type in constants.TUNNEL_NETWORK_TYPES:
(lvid, constants.LEARN_FROM_TUN))
else:
- LOG.error(_("Cannot provision %(network_type)s network for "
- "net-id=%(net_uuid)s - tunneling disabled"),
+ LOG.error(_LE("Cannot provision %(network_type)s network for "
+ "net-id=%(net_uuid)s - tunneling disabled"),
{'network_type': network_type,
'net_uuid': net_uuid})
elif network_type == p_const.TYPE_FLAT:
dl_vlan=0xffff,
actions="mod_vlan_vid:%s,normal" % lvid)
else:
- LOG.error(_("Cannot provision flat network for "
- "net-id=%(net_uuid)s - no bridge for "
- "physical_network %(physical_network)s"),
+ LOG.error(_LE("Cannot provision flat network for "
+ "net-id=%(net_uuid)s - no bridge for "
+ "physical_network %(physical_network)s"),
{'net_uuid': net_uuid,
'physical_network': physical_network})
elif network_type == p_const.TYPE_VLAN:
dl_vlan=segmentation_id,
actions="mod_vlan_vid:%s,normal" % lvid)
else:
- LOG.error(_("Cannot provision VLAN network for "
- "net-id=%(net_uuid)s - no bridge for "
- "physical_network %(physical_network)s"),
+ LOG.error(_LE("Cannot provision VLAN network for "
+ "net-id=%(net_uuid)s - no bridge for "
+ "physical_network %(physical_network)s"),
{'net_uuid': net_uuid,
'physical_network': physical_network})
elif network_type == p_const.TYPE_LOCAL:
# no flows needed for local networks
pass
else:
- LOG.error(_("Cannot provision unknown network type "
- "%(network_type)s for net-id=%(net_uuid)s"),
+ LOG.error(_LE("Cannot provision unknown network type "
+ "%(network_type)s for net-id=%(net_uuid)s"),
{'network_type': network_type,
'net_uuid': net_uuid})
'''
lvm = self.local_vlan_map.pop(net_uuid, None)
if lvm is None:
- LOG.debug(_("Network %s not used on agent."), net_uuid)
+ LOG.debug("Network %s not used on agent.", net_uuid)
return
- LOG.info(_("Reclaiming vlan = %(vlan_id)s from net-id = %(net_uuid)s"),
- {'vlan_id': lvm.vlan,
- 'net_uuid': net_uuid})
+ LOG.info(_LI("Reclaiming vlan = %(vlan_id)s from "
+ "net-id = %(net_uuid)s"),
+ {'vlan_id': lvm.vlan, 'net_uuid': net_uuid})
if lvm.network_type in constants.TUNNEL_NETWORK_TYPES:
if self.enable_tunneling:
# no flows needed for local networks
pass
else:
- LOG.error(_("Cannot reclaim unknown network type "
- "%(network_type)s for net-id=%(net_uuid)s"),
+ LOG.error(_LE("Cannot reclaim unknown network type "
+ "%(network_type)s for net-id=%(net_uuid)s"),
{'network_type': lvm.network_type,
'net_uuid': net_uuid})
net_uuid = self.get_net_uuid(vif_id)
if not self.local_vlan_map.get(net_uuid):
- LOG.info(_('port_unbound(): net_uuid %s not in local_vlan_map'),
+ LOG.info(_LI('port_unbound(): net_uuid %s not in local_vlan_map'),
net_uuid)
return
ancillary_bridges = []
for bridge in ovs_bridges:
br = ovs_lib.OVSBridge(bridge, self.root_helper)
- LOG.info(_('Adding %s to list of bridges.'), bridge)
+ LOG.info(_LI('Adding %s to list of bridges.'), bridge)
ancillary_bridges.append(br)
return ancillary_bridges
self.patch_int_ofport = self.tun_br.add_patch_port(
cfg.CONF.OVS.tun_peer_patch_port, cfg.CONF.OVS.int_peer_patch_port)
if int(self.patch_tun_ofport) < 0 or int(self.patch_int_ofport) < 0:
- LOG.error(_("Failed to create OVS patch port. Cannot have "
- "tunneling enabled on this agent, since this version "
- "of OVS does not support tunnels or patch ports. "
- "Agent terminated!"))
+ LOG.error(_LE("Failed to create OVS patch port. Cannot have "
+ "tunneling enabled on this agent, since this "
+ "version of OVS does not support tunnels or "
+ "patch ports. Agent terminated!"))
exit(1)
self.tun_br.remove_all_flows()
new_name = ('%(prefix)s%(truncated)s%(hash)s' %
{'prefix': prefix, 'truncated': name[0:namelen],
'hash': hashlib.sha1(name).hexdigest()[0:hashlen]})
- LOG.warning(_("Creating an interface named %(name)s exceeds the "
- "%(limit)d character limitation. It was shortened to "
- "%(new_name)s to fit."),
+ LOG.warning(_LW("Creating an interface named %(name)s exceeds the "
+ "%(limit)d character limitation. It was shortened to "
+ "%(new_name)s to fit."),
{'name': name, 'limit': q_const.DEVICE_NAME_MAX_LEN,
'new_name': new_name})
return new_name
ip_wrapper = ip_lib.IPWrapper(self.root_helper)
ovs_bridges = ovs_lib.get_bridges(self.root_helper)
for physical_network, bridge in bridge_mappings.iteritems():
- LOG.info(_("Mapping physical network %(physical_network)s to "
- "bridge %(bridge)s"),
+ LOG.info(_LI("Mapping physical network %(physical_network)s to "
+ "bridge %(bridge)s"),
{'physical_network': physical_network,
'bridge': bridge})
# setup physical bridge
if bridge not in ovs_bridges:
- LOG.error(_("Bridge %(bridge)s for physical network "
- "%(physical_network)s does not exist. Agent "
- "terminated!"),
+ LOG.error(_LE("Bridge %(bridge)s for physical network "
+ "%(physical_network)s does not exist. Agent "
+ "terminated!"),
{'physical_network': physical_network,
'bridge': bridge})
sys.exit(1)
and port_tags[lvm.vif_ports[port].port_name] != lvm.vlan
):
LOG.info(
- _("Port '%(port_name)s' has lost "
+ _LI("Port '%(port_name)s' has lost "
"its vlan tag '%(vlan_tag)d'!"),
{'port_name': lvm.vif_ports[port].port_name,
'vlan_tag': lvm.vlan}
# for being treated. If that does not happen, it is a potential
# error condition of which operators should be aware
if not vif_port.ofport:
- LOG.warn(_("VIF port: %s has no ofport configured, and might not "
- "be able to transmit"), vif_port.vif_id)
+ LOG.warn(_LW("VIF port: %s has no ofport configured, "
+ "and might not be able to transmit"), vif_port.vif_id)
if vif_port:
if admin_state_up:
self.port_bound(vif_port, network_id, network_type,
else:
self.port_dead(vif_port)
else:
- LOG.debug(_("No VIF port for port %s defined on agent."), port_id)
+ LOG.debug("No VIF port for port %s defined on agent.", port_id)
def _setup_tunnel_port(self, br, port_name, remote_ip, tunnel_type):
ofport = br.add_tunnel_port(port_name,
try:
ofport_int = int(ofport)
except (TypeError, ValueError):
- LOG.exception(_("ofport should have a value that can be "
- "interpreted as an integer"))
+ LOG.exception(_LE("ofport should have a value that can be "
+ "interpreted as an integer"))
if ofport_int < 0:
- LOG.error(_("Failed to set-up %(type)s tunnel port to %(ip)s"),
+ LOG.error(_LE("Failed to set-up %(type)s tunnel port to %(ip)s"),
{'type': tunnel_type, 'ip': remote_ip})
return 0
port = self.int_br.get_vif_port_by_id(device)
if not port:
# The port disappeared and cannot be processed
- LOG.info(_("Port %s was not found on the integration bridge "
- "and will therefore not be processed"), device)
+ LOG.info(_LI("Port %s was not found on the integration bridge "
+ "and will therefore not be processed"), device)
skipped_devices.append(device)
continue
if 'port_id' in details:
- LOG.info(_("Port %(device)s updated. Details: %(details)s"),
+ LOG.info(_LI("Port %(device)s updated. Details: %(details)s"),
{'device': device, 'details': details})
self.treat_vif_port(port, details['port_id'],
details['network_id'],
# neutron server from sending network-vif-* events to the nova
# API server, thus possibly preventing instance spawn.
if details.get('admin_state_up'):
- LOG.debug(_("Setting status for %s to UP"), device)
+ LOG.debug("Setting status for %s to UP", device)
self.plugin_rpc.update_device_up(
self.context, device, self.agent_id, cfg.CONF.host)
else:
- LOG.debug(_("Setting status for %s to DOWN"), device)
+ LOG.debug("Setting status for %s to DOWN", device)
self.plugin_rpc.update_device_down(
self.context, device, self.agent_id, cfg.CONF.host)
- LOG.info(_("Configuration for device %s completed."), device)
+ LOG.info(_LI("Configuration for device %s completed."), device)
else:
- LOG.warn(_("Device %s not defined on plugin"), device)
+ LOG.warn(_LW("Device %s not defined on plugin"), device)
if (port and port.ofport != -1):
self.port_dead(port)
return skipped_devices
for details in devices_details_list:
device = details['device']
- LOG.info(_("Ancillary Port %s added"), device)
+ LOG.info(_LI("Ancillary Port %s added"), device)
# update plugin about port status
self.plugin_rpc.update_device_up(self.context,
resync = False
self.sg_agent.remove_devices_filter(devices)
for device in devices:
- LOG.info(_("Attachment %s removed"), device)
+ LOG.info(_LI("Attachment %s removed"), device)
try:
self.plugin_rpc.update_device_down(self.context,
device,
self.agent_id,
cfg.CONF.host)
except Exception as e:
- LOG.debug(_("port_removed failed for %(device)s: %(e)s"),
+ LOG.debug("port_removed failed for %(device)s: %(e)s",
{'device': device, 'e': e})
resync = True
continue
def treat_ancillary_devices_removed(self, devices):
resync = False
for device in devices:
- LOG.info(_("Attachment %s removed"), device)
+ LOG.info(_LI("Attachment %s removed"), device)
try:
details = self.plugin_rpc.update_device_down(self.context,
device,
self.agent_id,
cfg.CONF.host)
except Exception as e:
- LOG.debug(_("port_removed failed for %(device)s: %(e)s"),
+ LOG.debug("port_removed failed for %(device)s: %(e)s",
{'device': device, 'e': e})
resync = True
continue
if details['exists']:
- LOG.info(_("Port %s updated."), device)
+ LOG.info(_LI("Port %s updated."), device)
# Nothing to do regarding local networking
else:
- LOG.debug(_("Device %s not defined on plugin"), device)
+ LOG.debug("Device %s not defined on plugin", device)
return resync
def process_network_ports(self, port_info, ovs_restarted):
try:
skipped_devices = self.treat_devices_added_or_updated(
devices_added_updated, ovs_restarted)
- LOG.debug(_("process_network_ports - iteration:%(iter_num)d -"
- "treat_devices_added_or_updated completed. "
- "Skipped %(num_skipped)d devices of "
- "%(num_current)d devices currently available. "
- "Time elapsed: %(elapsed).3f"),
+ LOG.debug("process_network_ports - iteration:%(iter_num)d -"
+ "treat_devices_added_or_updated completed. "
+ "Skipped %(num_skipped)d devices of "
+ "%(num_current)d devices currently available. "
+ "Time elapsed: %(elapsed).3f",
{'iter_num': self.iter_num,
'num_skipped': len(skipped_devices),
'num_current': len(port_info['current']),
except DeviceListRetrievalError:
# Need to resync as there was an error with server
# communication.
- LOG.exception(_("process_network_ports - iteration:%d - "
- "failure while retrieving port details "
- "from server"), self.iter_num)
+ LOG.exception(_LE("process_network_ports - iteration:%d - "
+ "failure while retrieving port details "
+ "from server"), self.iter_num)
resync_a = True
if 'removed' in port_info:
start = time.time()
resync_b = self.treat_devices_removed(port_info['removed'])
- LOG.debug(_("process_network_ports - iteration:%(iter_num)d -"
- "treat_devices_removed completed in %(elapsed).3f"),
+ LOG.debug("process_network_ports - iteration:%(iter_num)d -"
+ "treat_devices_removed completed in %(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
# If one of the above operations fails => resync with plugin
start = time.time()
try:
self.treat_ancillary_devices_added(port_info['added'])
- LOG.debug(_("process_ancillary_network_ports - iteration: "
- "%(iter_num)d - treat_ancillary_devices_added "
- "completed in %(elapsed).3f"),
+ LOG.debug("process_ancillary_network_ports - iteration: "
+ "%(iter_num)d - treat_ancillary_devices_added "
+ "completed in %(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
except DeviceListRetrievalError:
# Need to resync as there was an error with server
# communication.
- LOG.exception(_("process_ancillary_network_ports - "
- "iteration:%d - failure while retrieving "
- "port details from server"), self.iter_num)
+ LOG.exception(_LE("process_ancillary_network_ports - "
+ "iteration:%d - failure while retrieving "
+ "port details from server"), self.iter_num)
resync_a = True
if 'removed' in port_info:
start = time.time()
resync_b = self.treat_ancillary_devices_removed(
port_info['removed'])
- LOG.debug(_("process_ancillary_network_ports - iteration: "
- "%(iter_num)d - treat_ancillary_devices_removed "
- "completed in %(elapsed).3f"),
+ LOG.debug("process_ancillary_network_ports - iteration: "
+ "%(iter_num)d - treat_ancillary_devices_removed "
+ "completed in %(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
try:
return '%08x' % netaddr.IPAddress(ip_address, version=4)
except Exception:
- LOG.warn(_("Unable to create tunnel port. Invalid remote IP: %s"),
- ip_address)
+ LOG.warn(_LW("Unable to create tunnel port. "
+ "Invalid remote IP: %s"), ip_address)
return
def tunnel_sync(self):
tunnel['ip_address'],
tunnel_type)
except Exception as e:
- LOG.debug(_("Unable to sync tunnel IP %(local_ip)s: %(e)s"),
+ LOG.debug("Unable to sync tunnel IP %(local_ip)s: %(e)s",
{'local_ip': self.local_ip, 'e': e})
return True
return False
'removed': 0},
'ancillary': {'added': 0,
'removed': 0}}
- LOG.debug(_("Agent rpc_loop - iteration:%d started"),
+ LOG.debug("Agent rpc_loop - iteration:%d started",
self.iter_num)
if sync:
- LOG.info(_("Agent out of sync with plugin!"))
+ LOG.info(_LI("Agent out of sync with plugin!"))
ports.clear()
ancillary_ports.clear()
sync = False
self.dvr_agent.setup_dvr_flows_on_integ_tun_br()
# Notify the plugin of tunnel IP
if self.enable_tunneling and tunnel_sync:
- LOG.info(_("Agent tunnel out of sync with plugin!"))
+ LOG.info(_LI("Agent tunnel out of sync with plugin!"))
try:
tunnel_sync = self.tunnel_sync()
except Exception:
- LOG.exception(_("Error while synchronizing tunnels"))
+ LOG.exception(_LE("Error while synchronizing tunnels"))
tunnel_sync = True
if self._agent_has_updates(polling_manager) or ovs_restarted:
try:
- LOG.debug(_("Agent rpc_loop - iteration:%(iter_num)d - "
- "starting polling. Elapsed:%(elapsed).3f"),
+ LOG.debug("Agent rpc_loop - iteration:%(iter_num)d - "
+ "starting polling. Elapsed:%(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
# Save updated ports dict to perform rollback in
self.updated_ports = set()
reg_ports = (set() if ovs_restarted else ports)
port_info = self.scan_ports(reg_ports, updated_ports_copy)
- LOG.debug(_("Agent rpc_loop - iteration:%(iter_num)d - "
- "port information retrieved. "
- "Elapsed:%(elapsed).3f"),
+ LOG.debug("Agent rpc_loop - iteration:%(iter_num)d - "
+ "port information retrieved. "
+ "Elapsed:%(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
# Secure and wire/unwire VIFs and update their status
if (self._port_info_has_changes(port_info) or
self.sg_agent.firewall_refresh_needed() or
ovs_restarted):
- LOG.debug(_("Starting to process devices in:%s"),
+ LOG.debug("Starting to process devices in:%s",
port_info)
# If treat devices fails - must resync with plugin
sync = self.process_network_ports(port_info,
ovs_restarted)
- LOG.debug(_("Agent rpc_loop - iteration:%(iter_num)d -"
- "ports processed. Elapsed:%(elapsed).3f"),
+ LOG.debug("Agent rpc_loop - iteration:%(iter_num)d -"
+ "ports processed. Elapsed:%(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
port_stats['regular']['added'] = (
if self.ancillary_brs:
port_info = self.update_ancillary_ports(
ancillary_ports)
- LOG.debug(_("Agent rpc_loop - iteration:%(iter_num)d -"
- "ancillary port info retrieved. "
- "Elapsed:%(elapsed).3f"),
+ LOG.debug("Agent rpc_loop - iteration:%(iter_num)d -"
+ "ancillary port info retrieved. "
+ "Elapsed:%(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
if port_info:
rc = self.process_ancillary_network_ports(
port_info)
- LOG.debug(_("Agent rpc_loop - iteration:"
- "%(iter_num)d - ancillary ports "
- "processed. Elapsed:%(elapsed).3f"),
+ LOG.debug("Agent rpc_loop - iteration:"
+ "%(iter_num)d - ancillary ports "
+ "processed. Elapsed:%(elapsed).3f",
{'iter_num': self.iter_num,
'elapsed': time.time() - start})
ancillary_ports = port_info['current']
polling_manager.polling_completed()
except Exception:
- LOG.exception(_("Error while processing VIF ports"))
+ LOG.exception(_LE("Error while processing VIF ports"))
# Put the ports back in self.updated_port
self.updated_ports |= updated_ports_copy
sync = True
# sleep till end of polling interval
elapsed = (time.time() - start)
- LOG.debug(_("Agent rpc_loop - iteration:%(iter_num)d "
- "completed. Processed ports statistics: "
- "%(port_stats)s. Elapsed:%(elapsed).3f"),
+ LOG.debug("Agent rpc_loop - iteration:%(iter_num)d "
+ "completed. Processed ports statistics: "
+ "%(port_stats)s. Elapsed:%(elapsed).3f",
{'iter_num': self.iter_num,
'port_stats': port_stats,
'elapsed': elapsed})
if (elapsed < self.polling_interval):
time.sleep(self.polling_interval - elapsed)
else:
- LOG.debug(_("Loop iteration exceeded interval "
- "(%(polling_interval)s vs. %(elapsed)s)!"),
+ LOG.debug("Loop iteration exceeded interval "
+ "(%(polling_interval)s vs. %(elapsed)s)!",
{'polling_interval': self.polling_interval,
'elapsed': elapsed})
self.iter_num = self.iter_num + 1
try:
agent_config = create_agent_config_map(cfg.CONF)
except ValueError as e:
- LOG.error(_('%s Agent terminated!'), e)
+ LOG.error(_LE('%s Agent terminated!'), e)
sys.exit(1)
is_xen_compute_host = 'rootwrap-xen-dom0' in agent_config['root_helper']
signal.signal(signal.SIGTERM, agent._handle_sigterm)
# Start everything.
- LOG.info(_("Agent initialized successfully, now running... "))
+ LOG.info(_LI("Agent initialized successfully, now running... "))
agent.daemon_loop()