Пример #1
0
 def autoconf(self):
     self.error(u"Discovering network config")
     self.netcfg = NetCfgAutoConf(parent=self)
     self.netcfg.discover()
     self.config_loaded = True
Пример #2
0
class NetworkComponent(AbstractNuConfComponent):
    """
    Component to manage the network, the routing table
    """
    NAME = "network"
    VERSION = "1.0"

    REQUIRES = ('config', 'ufwi_conf')
    ACLS = {
        'ha': frozenset(('getHAMode',)),
        'nuauth': frozenset(('restartWinbind',)),
    }
    ROLES = {
        'ruleset_write': frozenset(('getNetconfig',)),
        'multisite_read': frozenset(('getNetconfig',)),
        'multisite_write': frozenset(('@multisite_read',)),
        'conf_read': frozenset((
            'getNetconfig',
            'ethtool_show_ring', 'ethtool_show_ring_all', 'ethtool_statistics',
            'ethtool_statistics_all', 'ethtool_nooptions',
            'ethtool_nooptions_all', 'ethtool_digest_all',
        )),
        'conf_write': frozenset((
            'autoconf', 'clearConf', 'setNetconfig',
        )),
        'dpi_write': frozenset(('getNetconfig',))
    }

    CONFIG_DEPENDS = ()

    NETWORK_FILE = '/etc/network/interfaces'

    def __init__(self):
        AbstractNuConfComponent.__init__(self)
        self.config_loaded = False
        self.var_dir = None
        self.ufwi_conf_var_dir = None
        self.context = None
        self.__during_ha_import = False
        self.__config_before_ha_import = None

    def setCfgValue(self, path, key, value, config_manager):
        path = path + (key, value)
        config_manager.set(*path)

    def getCfgValue(self, name, section, key):
        return self.core.config_manager.getValue(*(name + (section, key)))

    def init(self, core):
        AbstractNuConfComponent.init(self, core)
        self.context = Context.fromComponent(self)
        self.var_dir = self.core.config.get('CORE', 'vardir')
        self.ufwi_conf_var_dir = join(self.var_dir, 'ufwi_conf')
        if self.core.config.getboolean('CORE', 'use_edenwall'):
            warn_dangerous_files(self)
        if not check_and_correct_lo(self):
            self.critical("Networking configuration problem. :-(")

        self.core = core
        self.ethtool = Ethtool('/usr/sbin/ethtool', self)

        if not self.config_loaded:
            self.autoconf()
            self.save_config(
                    CONFIG_AUTOCONFIGURATION,
                    "network : auto configuration",
                    self.context
                    )
        else:
            self.info("not autoconfiguring")

        self.core.notify.connect('ha', 'ImportStart', self.__haImportStart)
        self.core.notify.connect('ha', 'ImportEnd', self.__haImportEnd)

    def __haImportStart(self, cb_context):
        self.__during_ha_import = True
        #save the config before we overwrite it!
        #This config will only be used to calculate if we should or not
        #attempt an AD join
        self.__config_before_ha_import = self.netcfg.serialize()

    def __haImportEnd(self, cb_context):
        self.__during_ha_import = False
        self.__config_before_ha_import = None

    def apply_config(self, responsible, trigger_module, trigger_keys):
        self.debug("Network module asked to reload, with args %s" % ", ".join(unicode(item) for item in (responsible.trace_message(), trigger_module, trigger_keys)))
#        optim = not responsible.implies_full_reload()
        if responsible.action is RESTORING_CONFIGURATION:
            optim = False
        else:
            optim = True
        return self.apply(responsible, optim=optim)

    def rollback_config(self, responsible, trigger_module, trigger_keys):
        self.debug("Network module asked to rollback, with args %s" % ", ".join(unicode(item) for item in (responsible.trace_message(), trigger_module, trigger_keys)))
        return self.apply(responsible, optim=False)

    def autoconf(self):
        self.error(u"Discovering network config")
        self.netcfg = NetCfgAutoConf(parent=self)
        self.netcfg.discover()
        self.config_loaded = True

    def service_autoconf(self, context):
        self.autoconf()
        message = "Network auto config requested by %s" % context.ownerString()
        self.save_config(
            CONFIG_AUTOCONFIGURATION,
            message,
            context
            )

    def service_clearConf(self, context, message):
        with self.core.config_manager.begin(
                self,
                context,
                action=CONFIG_ERASURE
                ) as cm:
            try:
                cm.delete(MASTER_KEY)
            except ConfigError, err:
                self.debug(u"While clearing config: %s" % err)
                cm.revert()
            else: