From baa909c6d0bdd23a9f82dce4437a6db7ba0406a9 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Tue, 26 Apr 2016 15:00:08 -0700 Subject: [PATCH] addons: adding '--with-defaults' option for base ifquery Ticket: CM-7840 Reviewed By: Roopa Prabhu Testing Done: yes, with different configurations for physical & logical devices This patch adds 'ifquery --with-defaults' to print the policy default values for unconfigured attributes. Signed-off-by: Nikhil --- addons/bridge.py | 3 ++- addons/ethtool.py | 18 +++++++++++++++++- addons/vrf.py | 10 +++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/addons/bridge.py b/addons/bridge.py index 799cfee..8caa1e4 100644 --- a/addons/bridge.py +++ b/addons/bridge.py @@ -1694,7 +1694,8 @@ class bridge(moduleBase): def _query(self, ifaceobj, **kwargs): """ add default policy attributes supported by the module """ - if not (ifaceobj.link_kind & ifaceLinkKind.BRIDGE): + if (not (ifaceobj.link_kind & ifaceLinkKind.BRIDGE) or + ifaceobj.get_attr_value_first('bridge-stp')): return if self.default_stp_on: ifaceobj.update_config('bridge-stp', 'yes') diff --git a/addons/ethtool.py b/addons/ethtool.py index c7a4850..2617602 100644 --- a/addons/ethtool.py +++ b/addons/ethtool.py @@ -232,10 +232,26 @@ class ethtool(moduleBase,utilsBase): return + def _query(self, ifaceobj, **kwargs): + """ add default policy attributes supported by the module """ + if ifaceobj.link_kind: + return + for attr in ['speed', 'duplex', 'autoneg']: + if ifaceobj.get_attr_value_first('link-%s'%attr): + continue + default = policymanager.policymanager_api.get_iface_default( + module_name='ethtool', + ifname=ifaceobj.name, + attr='link-%s' %attr) + if not default: + continue + ifaceobj.update_config('link-%s' %attr, default) + _run_ops = {'pre-down' : _pre_down, 'post-up' : _post_up, 'query-checkcurr' : _query_check, - 'query-running' : _query_running } + 'query-running' : _query_running, + 'query' : _query} def get_ops(self): """ returns list of ops supported by this module """ diff --git a/addons/vrf.py b/addons/vrf.py index 2b44ce1..420eaf1 100644 --- a/addons/vrf.py +++ b/addons/vrf.py @@ -816,10 +816,18 @@ class vrf(moduleBase): except Exception, e: self.log_warn(str(e)) + def _query(self, ifaceobj, **kwargs): + if not self.vrf_helper: + return + if (ifaceobj.link_kind & ifaceLinkKind.VRF): + ifaceobj.update_config('vrf-helper', '%s %s' %(self.vrf_helper, + ifaceobj.name)) + _run_ops = {'pre-up' : _up, 'post-down' : _down, 'query-running' : _query_running, - 'query-checkcurr' : _query_check} + 'query-checkcurr' : _query_check, + 'query' : _query} def get_ops(self): """ returns list of ops supported by this module """