示例#1
0
    def prepare(self):
        """Gather offline information.

        Checks availability of web UI exported RDF database.  This is critical to success, as it
        contains network configuration.  If the exported RDF database is missing, the update
        process fails.
        """

        try:
            helpers.create_rundir()
        except:
            raise UpdateUnknownError('failed to create runtime directory')

        # Parse RDF database, export temporary (pruned) version
        try:
            _log.info('parsing rdf database')

            # parse database
            self.rdf_database = rdf.Model.fromFile(
                constants.EXPORTED_RDF_DATABASE_FILE, name='rdfxml')
            if self.rdf_database is None:
                raise Exception(
                    'cannot read exported rdf database from file (rdf_database is None'
                )

            # cleanup etc
            @db.transact(database=self.rdf_database)
            def _f1():
                self.rdf_root = self.rdf_database.getNodeByUri(
                    ns.l2tpGlobalRoot, rdf.Type(ns.L2tpGlobalRoot))
                if self.rdf_root is None:
                    raise Exception(
                        'cannot find rdf global root (rdf_root is None')

                # clean up l2tpDeviceStatus; this needs to be done before runner starts
                l2tp_status = self.rdf_root.setS(ns.l2tpDeviceStatus,
                                                 rdf.Type(ns.L2tpDeviceStatus))

            _f1()

            # export to a temporary RDF file for runner
            @db.transact(database=self.rdf_database)
            def _f2():
                # XXX: prune will take too much time on big database,
                # removed for now before better solution is found.
                # return self.rdf_database.makePruned(self.rdf_root)
                return self.rdf_database

            m = _f2()

            @db.transact(database=m)
            def _f3():
                s = m.toString(name='rdfxml')
                f = None
                try:
                    f = open(constants.TEMPORARY_RDF_DATABASE_FILE,
                             'wb')  # XXX: potential leak, don't care
                    f.write(s)
                finally:
                    if f is not None:
                        f.close()
                        f = None

            _f3()
        except:
            _log.exception('cannot read rdf database')
            raise RdfDatabaseMissingError('rdf database cannot be read')

        # VPNease package version info = product version
        _log.info('checking product version info')
        self.version_string, self.version_cached = versioninfo.get_version_info(
        )

        # Determine fallback sources.list (in case management server cannot provide one)
        #
        # NOTE: this is not currently used because update is not done without management
        #       connection and sources list from management server is preferred.  Untested.
        _log.info('determining fallback apt source')
        self.sources = aptsource.get_cached_aptsource()
        if self.sources is None:
            self.sources = aptsource.get_current_aptsource()
            if self.sources is None:
                # NOTE: hardcoded components and suite!
                # Note: order is important here!
                sources = textwrap.dedent("""\
                deb http://%s dapper main
                deb http://%s dapper main restricted
                """ % (constants.PRODUCT_DEFAULT_VPNEASE_REPOSITORY,
                       constants.PRODUCT_DEFAULT_UBUNTU_REPOSITORY))
示例#2
0
def preinit():
    """Early initialization of l2tpgw.

    Stuff to do:
      * init runtime directory
      * check if this is live-cd and write markerfile if so
      * check system memory size and write lowmem marker
      * re-check and disable system daemon startups
      * live cd: launch opportunistic DHCP client
    """

    _log = logger.get('l2tpgw-init-preinit')

    try:
        helpers.create_rundir()
    except:
        _log.exception('runtime directory creation failed')
        raise

    is_livecd = False
    try:
        is_livecd = _check_livecd(_log)
    except:
        _log.exception('livecd check failed: ignoring')

    try:
        _check_memory(_log)
    except:
        _log.exception('system memory is critically low: ignoring')

    try:
        _check_daemon_startup(_log)
    except:
        _log.exception('system daemon startup check failed: ignoring')

    # This is here to update 1.0 (or 1.1rc4) naftalin when old vpnease-init
    # does not execute l2tpgw-postupdate.
    if not is_livecd:
        try:
            _check_forced_postupdate(_log)
        except:
            _log.exception('forced postupdate check failed, ignoring')

    if not is_livecd:
        try:
            _remove_old_kernels(_log)
        except:
            _log.exception('remove old kernels check failed, ignoring')

    # Live CD: start opportunistic dhclient as early as possible
    if is_livecd:
        try:
            # Paranoid firewall rules
            run_command(['/sbin/iptables', '-F'])
            run_command(['/sbin/iptables', '-P', 'OUTPUT', 'ACCEPT'])
            run_command(['/sbin/iptables', '-P', 'FORWARD', 'DROP'])
            run_command(['/sbin/iptables', '-P', 'INPUT', 'DROP'])
            run_command(['/sbin/iptables', '-A', 'INPUT', '-i', 'lo', '-j', 'ACCEPT'])
            run_command(['/sbin/iptables', '-A', 'INPUT', '-m', 'state', '--state', 'ESTABLISHED,RELATED', '-j', 'ACCEPT'])

            # Dhclient will be launched to background, and will not wait for an address
            run_command(['/sbin/dhclient', '-nw', 'eth0'])  # XXX: eth0 is fixed now
        except:
            _log.exception('failed to start dhclient to background (live cd only)')
示例#3
0
    def prepare(self):
        """Gather offline information.

        Checks availability of web UI exported RDF database.  This is critical to success, as it
        contains network configuration.  If the exported RDF database is missing, the update
        process fails.
        """

        try:
            helpers.create_rundir()
        except:
            raise UpdateUnknownError('failed to create runtime directory')

        # Parse RDF database, export temporary (pruned) version
        try:
            _log.info('parsing rdf database')

            # parse database
            self.rdf_database = rdf.Model.fromFile(constants.EXPORTED_RDF_DATABASE_FILE, name='rdfxml')
            if self.rdf_database is None:
                raise Exception('cannot read exported rdf database from file (rdf_database is None')

            # cleanup etc
            @db.transact(database=self.rdf_database)
            def _f1():
                self.rdf_root = self.rdf_database.getNodeByUri(ns.l2tpGlobalRoot, rdf.Type(ns.L2tpGlobalRoot))
                if self.rdf_root is None:
                    raise Exception('cannot find rdf global root (rdf_root is None')

                # clean up l2tpDeviceStatus; this needs to be done before runner starts
                l2tp_status = self.rdf_root.setS(ns.l2tpDeviceStatus, rdf.Type(ns.L2tpDeviceStatus))
            _f1()

            # export to a temporary RDF file for runner
            @db.transact(database=self.rdf_database)
            def _f2():
                # XXX: prune will take too much time on big database,
                # removed for now before better solution is found.
                # return self.rdf_database.makePruned(self.rdf_root)
                return self.rdf_database
            m = _f2()
            
            @db.transact(database=m)
            def _f3():
                s = m.toString(name='rdfxml')
                f = None
                try:
                    f = open(constants.TEMPORARY_RDF_DATABASE_FILE, 'wb')  # XXX: potential leak, don't care
                    f.write(s)
                finally:
                    if f is not None:
                        f.close()
                        f = None
            _f3()
        except:
            _log.exception('cannot read rdf database')
            raise RdfDatabaseMissingError('rdf database cannot be read')

        # VPNease package version info = product version
        _log.info('checking product version info')
        self.version_string, self.version_cached = versioninfo.get_version_info()

        # Determine fallback sources.list (in case management server cannot provide one)
        #
        # NOTE: this is not currently used because update is not done without management
        #       connection and sources list from management server is preferred.  Untested.
        _log.info('determining fallback apt source')
        self.sources = aptsource.get_cached_aptsource()
        if self.sources is None:
            self.sources = aptsource.get_current_aptsource()
            if self.sources is None:
                # NOTE: hardcoded components and suite!
                # Note: order is important here!
                sources = textwrap.dedent("""\
                deb http://%s dapper main
                deb http://%s dapper main restricted
                """ % (constants.PRODUCT_DEFAULT_VPNEASE_REPOSITORY, constants.PRODUCT_DEFAULT_UBUNTU_REPOSITORY))