# customer could have used UPPERCASE for MAC
self.ipcmd.link_set_hwaddress(macvlan_ifacename, mac)
hwaddress.append(mac)
- self.ipcmd.addr_add_multiple(ifaceobj, macvlan_ifacename, ips,
- purge_existing)
+ self.ipcmd.addr_add_multiple(
+ ifaceobj,
+ macvlan_ifacename,
+ ips,
+ purge_existing,
+ metric=self.ipcmd.get_default_ip_metric() if self.ipcmd.addr_metric_support() else None
+ )
# If link existed before, flap the link
if not link_created:
netlink.link_set_updown(macvlan_ifacename, "up")
else:
try:
- self.ipcmd.fix_ipv6_route_metric(ifaceobj, macvlan_ifacename, ips)
+ if not self.ipcmd.addr_metric_support():
+ # if the system doesn't support ip addr set METRIC
+ # we need to do manually check the ordering of the ip6 routes
+ self.ipcmd.fix_ipv6_route_metric(ifaceobj, macvlan_ifacename, ips)
except Exception as e:
self.logger.debug('fix_vrf_slave_ipv6_route_metric: failed: %s' % e)
bridge_utils_is_installed = os.path.exists(utils.brctl_cmd)
bridge_utils_missing_warning = True
+ DEFAULT_IP_METRIC = 1024
+ ADDR_METRIC_SUPPORT = None
+
def __init__(self, *args, **kargs):
utilsBase.__init__(self, *args, **kargs)
if not ifupdownflags.flags.PERFMODE and not LinkUtils._CACHE_FILL_DONE:
self._fill_cache()
+ if LinkUtils.ADDR_METRIC_SUPPORT is None:
+ try:
+ cmd = [utils.ip_cmd, 'addr', 'help']
+ self.logger.info('executing %s addr help' % utils.ip_cmd)
+
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout, stderr = process.communicate()
+ LinkUtils.ADDR_METRIC_SUPPORT = '[ metric METRIC ]' in stderr or ''
+ self.logger.info('address metric support: %s' % ('OK' if LinkUtils.ADDR_METRIC_SUPPORT else 'KO'))
+ except Exception:
+ LinkUtils.ADDR_METRIC_SUPPORT = False
+ self.logger.info('address metric support: KO')
+
+ @classmethod
+ def addr_metric_support(cls):
+ return cls.ADDR_METRIC_SUPPORT
+
+ @classmethod
+ def get_default_ip_metric(cls):
+ return cls.DEFAULT_IP_METRIC
+
@classmethod
def reset(cls):
LinkUtils._CACHE_FILL_DONE = False
'-o', '-d', 'link', 'show'])
def addr_add(self, ifacename, address, broadcast=None,
- peer=None, scope=None, preferred_lifetime=None):
+ peer=None, scope=None, preferred_lifetime=None, metric=None):
if not address:
return
cmd = 'addr add %s' % address
if preferred_lifetime:
cmd += ' preferred_lft %s' % preferred_lifetime
cmd += ' dev %s' % ifacename
+
+ if metric:
+ cmd += ' metric %s' % metric
+
if LinkUtils.ipbatch and not LinkUtils.ipbatch_pause:
self.add_to_batch(cmd)
else:
return running_ipobj == (ip4 + ip6)
- def addr_add_multiple(self, ifaceobj, ifacename, addrs, purge_existing=False):
+ def addr_add_multiple(self, ifaceobj, ifacename, addrs, purge_existing=False, metric=None):
# purges address
if purge_existing:
# if perfmode is not set and also if iface has no sibling
self.logger.warning('%s: %s' % (ifacename, str(e)))
for a in addrs:
try:
- self.addr_add(ifacename, a)
+ self.addr_add(ifacename, a, metric=metric)
except Exception, e:
self.logger.error(str(e))