Exemplo n.º 1
0
    def _check_prereqs(self):
        is_livecd = True
        try:
            open(constants.LIVECD_MARKER_FILE, 'rb').close()
        except:
            is_livecd = False

        is_lowmem = True
        try:
            open(constants.LOWMEM_MARKER_FILE, 'rb').close()
        except:
            is_lowmem = False

        n_ether = 0
        try:
            ifaces = interfacehelper.get_interfaces()
            for i in ifaces.get_interface_list():
                if i.is_ethernet_device():
                    n_ether += 1
        except:
            pass

        print 'livecd prerequisites: is_livecd=%s, is_lowmem=%s, n_ether=%s' % (is_livecd, is_lowmem, n_ether)

        if (not is_livecd) or (is_lowmem) or (n_ether < 1):
            return False
        return True
Exemplo n.º 2
0
    def _check_prereqs(self):
        is_livecd = True
        try:
            open(constants.LIVECD_MARKER_FILE, 'rb').close()
        except:
            is_livecd = False

        is_lowmem = True
        try:
            open(constants.LOWMEM_MARKER_FILE, 'rb').close()
        except:
            is_lowmem = False

        ifaces = interfacehelper.get_interfaces()
        n_ether = 0
        for i in ifaces.get_interface_list():
            if i.is_ethernet_device():
                n_ether += 1

        print 'livecd prerequisites: is_livecd=%s, is_lowmem=%s, n_ether=%s' % (
            is_livecd, is_lowmem, n_ether)

        if (not is_livecd) or (is_lowmem) or (n_ether < 1):
            return False
        return True
Exemplo n.º 3
0
    def render_link_maybe(self, ctx, data):
        from codebay.l2tpserver import interfacehelper
        from nevow.flat.ten import flatten

        have_network_connection = False

        try:
            ifname = 'eth0'  # XXX: hardcoded in livecd
            ifaces = interfacehelper.get_interfaces()
            iface = ifaces.get_interface_by_name(ifname)
            if iface is not None:
                addr = iface.get_current_ipv4_address_info()
                if addr is not None:
                    have_network_connection = True
        except:
            _log.exception(
                'livecd cannot determine whether we have a network connection or not'
            )

        if have_network_connection:
            return ctx.tag
        else:
            # XXX: ugly hack, but without this markup would need heavier elements
            txt = flatten(ctx.tag.children)
            return T.strong(_class='cb-strong')[txt]
Exemplo n.º 4
0
def _interface_stats():
    try:
        up_ifaces = interfacehelper.get_interfaces().get_interface_list()
        all_ifaces = interfacehelper.get_all_interfaces().get_interface_list()

        [rv, raw_table, err] = run_command([constants.CMD_IPTABLES_SAVE, '-t', 'raw'], retval=runcommand.FAIL)
        [rv, mangle_table, err] = run_command([constants.CMD_IPTABLES_SAVE, '-t', 'mangle'], retval=runcommand.FAIL)
        [rv, nat_table, err] = run_command([constants.CMD_IPTABLES_SAVE, '-t', 'nat'], retval=runcommand.FAIL)
        [rv, filter_table, err] = run_command([constants.CMD_IPTABLES_SAVE, '-t', 'filter'], retval=runcommand.FAIL)

        raw_len = len(raw_table.split('\n'))
        mangle_len = len(mangle_table.split('\n'))
        nat_len = len(nat_table.split('\n'))
        filter_len = len(filter_table.split('\n'))

        _log.info('NETWORKINFO: ' \
                  'all interfaces: %d, ' \
                  'up interfaces: %d, ' \
                  'iptables size: %d (raw: %d, mangle: %d, nat: %d, filter: %d)',
                  len(all_ifaces),
                  len(up_ifaces),
                  raw_len + mangle_len + nat_len + filter_len,
                  raw_len, mangle_len, nat_len, filter_len)

    except:
        _log.exception('failed to get network stats')
Exemplo n.º 5
0
    def render_link_maybe(self, ctx, data):
        from codebay.l2tpserver import interfacehelper
        from nevow.flat.ten import flatten

        have_network_connection = False

        try:
            ifname = 'eth0'  # XXX: hardcoded in livecd
            ifaces = interfacehelper.get_interfaces()
            iface = ifaces.get_interface_by_name(ifname)
            if iface is not None:
                addr = iface.get_current_ipv4_address_info()
                if addr is not None:
                    have_network_connection = True
        except:
            _log.exception('livecd cannot determine whether we have a network connection or not')

        if have_network_connection:
            return ctx.tag
        else:
            # XXX: ugly hack, but without this markup would need heavier elements
            txt = flatten(ctx.tag.children)
            return T.strong(_class='cb-strong')[txt]
Exemplo n.º 6
0
    def reconcile_system_and_rdf_state(self, first_time=False):
        """Reconcile system and RDF states.

        Checks system device list and compares it against RDF device information.
        Extra PPP devices without RDF book-keeping information are terminated.
        Devices present in RDF but not in the system are also removed from RDF.
        After calling this function, the system and RDF should be reasonably
        synchronized.

        This function also detects and updates the 'liveness' of each PPP device.
        Devices which are not live are not taken into account in license computations,
        thus making their detection important.

        The function also updates global public/private interface rx/tx counters,
        rates, etc.

        This function should be periodically, with an interval of 1-10 minutes or so.
        """

        #
        #  XXX: If status is incomplete for some reason, this will now
        #  spout exceptions.  The code should check whether checking and
        #  updating e.g. public interface status is useful at this point.
        #
        
        (pub_if, pub_if_name), (priv_if, priv_if_name) = helpers.get_ifaces(helpers.get_config())

        # start timestamp
        now = datetime.datetime.utcnow()
        
        # get device info from system (ip command)
        _log.debug('reconcile: getting system info')
        ifaces = interfacehelper.get_interfaces()

        # build devname->node dict
        _log.debug('reconcile: build devname->rdf dev dict')
        rdfdevs = helpers.get_ppp_devices()
        rdfdevmap = self._build_rdf_devmap(rdfdevs)
        
        # reconcile devices, pass 1: system vs rdf  [collect sysdevs dict at the same time]
        _log.debug('reconcile: pass 1, system vs rdf')
        sysdevs, pub_di, priv_di = self._reconcile_system_vs_rdf(rdfdevmap, ifaces, pub_if_name, priv_if_name)

        # do sysnukes for devices exceeding threshold
        for k in self._sysnuke_failures.keys():
            if self._sysnuke_failures[k] >= SYSNUKE_FAILURE_LIMIT:
                try:
                    _log.warning('sysnuke failure count for device %s too high, nuking' % k)
                    self._nuke_system_device(k)
                    del self._sysnuke_failures[k]
                except:
                    _log.exception('sysnuke failed')
                
        # reconcile devices, pass 2: rdf vs system
        _log.debug('reconcile: pass 2, rdf vs system')
        self._reconcile_rdf_vs_system(rdfdevs, sysdevs)

        # do rdfnukes for devices exceeding threshold
        for k in self._rdfnuke_failures.keys():  # key = rdf node of type PppDevice
            if self._rdfnuke_failures[k] >= RDFNUKE_FAILURE_LIMIT:
                try:
                    if k.hasS(ns.deviceName):
                        devname = k.getS(ns.deviceName, rdf.String)
                    else:
                        devname = '<unknown devname>'
                    _log.warning('rdfnuke failure count for device %s (%s) too high, nuking' % (k, devname))
                    self._nuke_rdf_device(k)
                    del self._rdfnuke_failures[k]
                except:
                    _log.exception('failed during reconcile, skipping device')
            # NB: device will be left in _rdfnuke_failures, and be removed next time

        # update rx/tx counters, transfer rates, etc
        # (reget devs because we may have nuked something)
        _log.debug('reconcile: updating rx/tx counters')
        rdfdevs = helpers.get_ppp_devices()
        self._update_rxtx_etc(now, rdfdevs, sysdevs)

        # update device liveness status
        _log.debug('reconcile: updating liveness status')
        rdfdevs = helpers.get_ppp_devices()
        self._update_liveness_status(now, rdfdevs)

        # update public/private interface status
        _log.debug('reconcile: updating public and/or private interface status')
        self._update_public_private_ifaces(now, ifaces, pub_di, priv_di, first_time)
Exemplo n.º 7
0
    def reconcile_system_and_rdf_state(self, first_time=False):
        """Reconcile system and RDF states.

        Checks system device list and compares it against RDF device information.
        Extra PPP devices without RDF book-keeping information are terminated.
        Devices present in RDF but not in the system are also removed from RDF.
        After calling this function, the system and RDF should be reasonably
        synchronized.

        This function also detects and updates the 'liveness' of each PPP device.
        Devices which are not live are not taken into account in license computations,
        thus making their detection important.

        The function also updates global public/private interface rx/tx counters,
        rates, etc.

        This function should be periodically, with an interval of 1-10 minutes or so.
        """

        #
        #  XXX: If status is incomplete for some reason, this will now
        #  spout exceptions.  The code should check whether checking and
        #  updating e.g. public interface status is useful at this point.
        #

        (pub_if, pub_if_name), (priv_if, priv_if_name) = helpers.get_ifaces(
            helpers.get_config())

        # start timestamp
        now = datetime.datetime.utcnow()

        # get device info from system (ip command)
        _log.debug('reconcile: getting system info')
        ifaces = interfacehelper.get_interfaces()

        # build devname->node dict
        _log.debug('reconcile: build devname->rdf dev dict')
        rdfdevs = helpers.get_ppp_devices()
        rdfdevmap = self._build_rdf_devmap(rdfdevs)

        # reconcile devices, pass 1: system vs rdf  [collect sysdevs dict at the same time]
        _log.debug('reconcile: pass 1, system vs rdf')
        sysdevs, pub_di, priv_di = self._reconcile_system_vs_rdf(
            rdfdevmap, ifaces, pub_if_name, priv_if_name)

        # do sysnukes for devices exceeding threshold
        for k in self._sysnuke_failures.keys():
            if self._sysnuke_failures[k] >= SYSNUKE_FAILURE_LIMIT:
                try:
                    _log.warning(
                        'sysnuke failure count for device %s too high, nuking'
                        % k)
                    self._nuke_system_device(k)
                    del self._sysnuke_failures[k]
                except:
                    _log.exception('sysnuke failed')

        # reconcile devices, pass 2: rdf vs system
        _log.debug('reconcile: pass 2, rdf vs system')
        self._reconcile_rdf_vs_system(rdfdevs, sysdevs)

        # do rdfnukes for devices exceeding threshold
        for k in self._rdfnuke_failures.keys(
        ):  # key = rdf node of type PppDevice
            if self._rdfnuke_failures[k] >= RDFNUKE_FAILURE_LIMIT:
                try:
                    if k.hasS(ns.deviceName):
                        devname = k.getS(ns.deviceName, rdf.String)
                    else:
                        devname = '<unknown devname>'
                    _log.warning(
                        'rdfnuke failure count for device %s (%s) too high, nuking'
                        % (k, devname))
                    self._nuke_rdf_device(k)
                    del self._rdfnuke_failures[k]
                except:
                    _log.exception('failed during reconcile, skipping device')
            # NB: device will be left in _rdfnuke_failures, and be removed next time

        # update rx/tx counters, transfer rates, etc
        # (reget devs because we may have nuked something)
        _log.debug('reconcile: updating rx/tx counters')
        rdfdevs = helpers.get_ppp_devices()
        self._update_rxtx_etc(now, rdfdevs, sysdevs)

        # update device liveness status
        _log.debug('reconcile: updating liveness status')
        rdfdevs = helpers.get_ppp_devices()
        self._update_liveness_status(now, rdfdevs)

        # update public/private interface status
        _log.debug(
            'reconcile: updating public and/or private interface status')
        self._update_public_private_ifaces(now, ifaces, pub_di, priv_di,
                                           first_time)