--- /dev/null
+#!/bin/sh
+# preinst script for newpkg
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+# * <new-preinst> `install'
+# * <new-preinst> `install' <old-version>
+# * <new-preinst> `upgrade' <old-version>
+# * <old-preinst> `abort-upgrade' <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+preinst_upgrade()
+{
+ local oldver="$1"
+ local udev_user_rulesdir="/etc/udev/rules.d"
+
+ # we have to fixup the filesystem here as previous packages of
+ # ifupdown2 introduced a bug in the postrm script that require
+ # these files to exist, otherwise the postrm script will always
+ # fail.
+ local badver="0.1-cl2.5+2"
+ if dpkg --compare-versions "${oldver}" "lt" "${badver}"; then
+ local files="${udev_user_rulesdir}/80-networking.rules
+ ${udev_user_rulesdir}/60-bridge-network-interface.rules"
+ for f in ${files}; do
+ echo "touching udev rule: ${f}"
+ test ! -e "${f}" && ln -s /dev/null "${f}" || \
+ /bin/echo -e "\tudev rule exists leaving"
+ done
+ fi
+}
+
+case "$1" in
+ install|upgrade)
+ preinst_upgrade "$2"
+ ;;
+
+ abort-upgrade)
+ ;;
+
+ *)
+ echo "preinst called with unknown argument \`$1'" >&2
+ exit 1
+ ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
--- /dev/null
+#!/usr/bin/python
+#
+# Copyright 2015 Cumulus Networks, Inc. All rights reserved.
+#
+#
+'''
+The PolicyManager should be subclassed by addon modules
+to read a JSON policy config file that is later used to
+set defaults:
+
+Initialize: This module defines a list of config file location based
+ on module. There are defined in the __init__(): All the
+ addon modules need to do is import the policymanager module.
+
+ import ifupdown.policymanager as policymanager
+
+
+Provides: an API to retrieve link attributes based on addon module name,
+ interface name, and attribute.
+
+ The ifupdown.policymanager module provides a global object policymanager_api
+ that can be called like so:
+
+ speed_default = policymanager.policymanager_api.get_default(
+ module_name='ethtool',
+ ifname=ifaceobj.name,
+ attr='link-speed'
+ )
+'''
+
+import json
+import logging
+import glob
+
+class policymanager():
+ def __init__(self):
+ # we should check for these files in order
+ # so that customers can override the /var/lib file settings
+ self.logger = logging.getLogger('ifupdown.' +
+ self.__class__.__name__)
+
+ # we grab the json files from a known location and make sure that
+ # the defaults_policy is checked first
+ user_files = glob.glob('/etc/network/ifupdown2/policy.d/*.json')
+ # grab the default module files
+ default_files = glob.glob('/var/lib/ifupdownaddons/policy.d/*.json')
+ # keep an array of defaults indexed by module name
+ self.system_policy_array = {}
+ for filename in default_files:
+ system_array = {}
+ try:
+ fd = open(filename,'r')
+ system_array = json.load(fd)
+ self.logger.debug('reading %s system policy defaults config' \
+ % filename)
+ except Exception, e:
+ self.logger.debug('could not read %s system policy defaults config' \
+ % filename)
+ self.logger.debug(' exception is %s' % str(e))
+ for module in system_array.keys():
+ if self.system_policy_array.has_key(module):
+ self.logger.debug('warning: overwriting system module %s from file %s' \
+ % (module,filename))
+ self.system_policy_array[module] = system_array[module]
+
+ # take care of user defined policy defaults
+ self.user_policy_array = {}
+ for filename in user_files:
+ user_array = {}
+ try:
+ fd = open(filename,'r')
+ user_array = json.load(fd)
+ self.logger.debug('reading %s policy user defaults config' \
+ % filename)
+ except Exception, e:
+ self.logger.debug('could not read %s user policy defaults config' \
+ % filename)
+ self.logger.debug(' exception is %s' % str(e))
+ # customer added module attributes
+ for module in user_array.keys():
+ if self.system_policy_array.has_key(module):
+ # warn user that we are overriding the system module setting
+ self.logger.debug('warning: overwriting system with user module %s from file %s' \
+ % (module,filename))
+ self.user_policy_array[module] = user_array[module]
+ return
+
+ def get_iface_default(self,module_name=None,ifname=None,attr=None):
+ '''
+ get_iface_default: Addon modules must use one of two types of access methods to
+ the default configs. In this method, we expect the default to be
+ either in
+ [module]['iface_defaults'][ifname][attr] or
+ [module]['defaults'][attr]
+ We first check the user_policy_array and return that value. But if
+ the user did not specify an override, we use the system_policy_array.
+ '''
+ # make sure we have an index
+ if (not ifname or not attr or not module_name):
+ return None
+
+ val = None
+ # users can specify defaults to override the systemwide settings
+ # look for user specific interface attribute iface_defaults first
+ try:
+ # looks for user specified value
+ val = self.user_policy_array[module_name]['iface_defaults'][ifname][attr]
+ return val
+ except:
+ pass
+ try:
+ # failing that, there may be a user default for all intefaces
+ val = self.user_policy_array[module_name]['defaults'][attr]
+ return val
+ except:
+ pass
+ try:
+ # failing that, look for system setting for the interface
+ val = self.system_policy_array[module_name]['iface_defaults'][ifname][attr]
+ return val
+ except:
+ pass
+ try:
+ # failing that, look for system setting for all interfaces
+ val = self.system_policy_array[module_name]['defaults'][attr]
+ return val
+ except:
+ pass
+
+ # could not find any system or user default so return Non
+ return val
+
+ def get_attr_default(self,module_name=None,attr=None):
+ '''
+ get_attr_default: Addon modules must use one of two types of access methods to
+ the default configs. In this method, we expect the default to be in
+
+ [module][attr]
+
+ We first check the user_policy_array and return that value. But if
+ the user did not specify an override, we use the system_policy_array.
+ '''
+ if (not attr or not module_name):
+ return None
+ # users can specify defaults to override the systemwide settings
+ # look for user specific interface attribute iface_defaults first
+ val = None
+ if self.user_policy_array.get(module_name):
+ val = self.user_policy_array[module_name].get(attr)
+
+ if not val:
+ if self.system_policy_array.get(module_name):
+ val = self.system_policy_array[module_name].get(attr)
+
+ return val
+
+ def get_module_default(self,module_name=None):
+ '''
+ get_module_default: Addon modules can also access the entire config
+ This method returns indexed by "system" and "user": these are the
+ system-wide and user-defined policy arrays for a specific module.
+ '''
+ if not module_name:
+ return None
+ if self.system_policy_array.get(module_name) and \
+ self.user_policy_array.get(module_name):
+ mod_array = {"system":self.system_policy_array[module_name],
+ "user":self.user_policy_array[module_name]}
+ else:
+ # the module must not have these defined, return None
+ mod_array = None
+
+ return mod_array
+
+policymanager_api = policymanager()
+++ /dev/null
-#!/bin/sh
-# preinst script for newpkg
-#
-# see: dh_installdeb(1)
-
-set -e
-
-# summary of how this script can be called:
-# * <new-preinst> `install'
-# * <new-preinst> `install' <old-version>
-# * <new-preinst> `upgrade' <old-version>
-# * <old-preinst> `abort-upgrade' <new-version>
-# for details, see http://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
-
-preinst_upgrade()
-{
- local oldver="$1"
- local udev_user_rulesdir="/etc/udev/rules.d"
-
- # we have to fixup the filesystem here as previous packages of
- # ifupdown2 introduced a bug in the postrm script that require
- # these files to exist, otherwise the postrm script will always
- # fail.
- local badver="0.1-cl2.5+2"
- if dpkg --compare-versions "${oldver}" "lt" "${badver}"; then
- local files="${udev_user_rulesdir}/80-networking.rules
- ${udev_user_rulesdir}/60-bridge-network-interface.rules"
- for f in ${files}; do
- echo "touching udev rule: ${f}"
- test ! -e "${f}" && ln -s /dev/null "${f}" || \
- /bin/echo -e "\tudev rule exists leaving"
- done
- fi
-}
-
-case "$1" in
- install|upgrade)
- preinst_upgrade "$2"
- ;;
-
- abort-upgrade)
- ;;
-
- *)
- echo "preinst called with unknown argument \`$1'" >&2
- exit 1
- ;;
-esac
-
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
-exit 0
+++ /dev/null
-#!/usr/bin/python
-#
-# Copyright 2015 Cumulus Networks, Inc. All rights reserved.
-#
-#
-'''
-The PolicyManager should be subclassed by addon modules
-to read a JSON policy config file that is later used to
-set defaults:
-
-Initialize: This module defines a list of config file location based
- on module. There are defined in the __init__(): All the
- addon modules need to do is import the policymanager module.
-
- import ifupdown.policymanager as policymanager
-
-
-Provides: an API to retrieve link attributes based on addon module name,
- interface name, and attribute.
-
- The ifupdown.policymanager module provides a global object policymanager_api
- that can be called like so:
-
- speed_default = policymanager.policymanager_api.get_default(
- module_name='ethtool',
- ifname=ifaceobj.name,
- attr='link-speed'
- )
-'''
-
-import json
-import logging
-import glob
-
-class policymanager():
- def __init__(self):
- # we should check for these files in order
- # so that customers can override the /var/lib file settings
- self.logger = logging.getLogger('ifupdown.' +
- self.__class__.__name__)
-
- # we grab the json files from a known location and make sure that
- # the defaults_policy is checked first
- user_files = glob.glob('/etc/network/ifupdown2/policy.d/*.json')
- # grab the default module files
- default_files = glob.glob('/var/lib/ifupdownaddons/policy.d/*.json')
- # keep an array of defaults indexed by module name
- self.system_policy_array = {}
- for filename in default_files:
- system_array = {}
- try:
- fd = open(filename,'r')
- system_array = json.load(fd)
- self.logger.debug('reading %s system policy defaults config' \
- % filename)
- except Exception, e:
- self.logger.debug('could not read %s system policy defaults config' \
- % filename)
- self.logger.debug(' exception is %s' % str(e))
- for module in system_array.keys():
- if self.system_policy_array.has_key(module):
- self.logger.debug('warning: overwriting system module %s from file %s' \
- % (module,filename))
- self.system_policy_array[module] = system_array[module]
-
- # take care of user defined policy defaults
- self.user_policy_array = {}
- for filename in user_files:
- user_array = {}
- try:
- fd = open(filename,'r')
- user_array = json.load(fd)
- self.logger.debug('reading %s policy user defaults config' \
- % filename)
- except Exception, e:
- self.logger.debug('could not read %s user policy defaults config' \
- % filename)
- self.logger.debug(' exception is %s' % str(e))
- # customer added module attributes
- for module in user_array.keys():
- if self.system_policy_array.has_key(module):
- # warn user that we are overriding the system module setting
- self.logger.debug('warning: overwriting system with user module %s from file %s' \
- % (module,filename))
- self.user_policy_array[module] = user_array[module]
- return
-
- def get_iface_default(self,module_name=None,ifname=None,attr=None):
- '''
- get_iface_default: Addon modules must use one of two types of access methods to
- the default configs. In this method, we expect the default to be
- either in
- [module]['iface_defaults'][ifname][attr] or
- [module]['defaults'][attr]
- We first check the user_policy_array and return that value. But if
- the user did not specify an override, we use the system_policy_array.
- '''
- # make sure we have an index
- if (not ifname or not attr or not module_name):
- return None
-
- val = None
- # users can specify defaults to override the systemwide settings
- # look for user specific interface attribute iface_defaults first
- try:
- # looks for user specified value
- val = self.user_policy_array[module_name]['iface_defaults'][ifname][attr]
- return val
- except:
- pass
- try:
- # failing that, there may be a user default for all intefaces
- val = self.user_policy_array[module_name]['defaults'][attr]
- return val
- except:
- pass
- try:
- # failing that, look for system setting for the interface
- val = self.system_policy_array[module_name]['iface_defaults'][ifname][attr]
- return val
- except:
- pass
- try:
- # failing that, look for system setting for all interfaces
- val = self.system_policy_array[module_name]['defaults'][attr]
- return val
- except:
- pass
-
- # could not find any system or user default so return Non
- return val
-
- def get_attr_default(self,module_name=None,attr=None):
- '''
- get_attr_default: Addon modules must use one of two types of access methods to
- the default configs. In this method, we expect the default to be in
-
- [module][attr]
-
- We first check the user_policy_array and return that value. But if
- the user did not specify an override, we use the system_policy_array.
- '''
- if (not attr or not module_name):
- return None
- # users can specify defaults to override the systemwide settings
- # look for user specific interface attribute iface_defaults first
- val = None
- if self.user_policy_array.get(module_name):
- val = self.user_policy_array[module_name].get(attr)
-
- if not val:
- if self.system_policy_array.get(module_name):
- val = self.system_policy_array[module_name].get(attr)
-
- return val
-
- def get_module_default(self,module_name=None):
- '''
- get_module_default: Addon modules can also access the entire config
- This method returns indexed by "system" and "user": these are the
- system-wide and user-defined policy arrays for a specific module.
- '''
- if not module_name:
- return None
- if self.system_policy_array.get(module_name) and \
- self.user_policy_array.get(module_name):
- mod_array = {"system":self.system_policy_array[module_name],
- "user":self.user_policy_array[module_name]}
- else:
- # the module must not have these defined, return None
- mod_array = None
-
- return mod_array
-
-policymanager_api = policymanager()