Exemple #1
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist".format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed".format(opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is not None:
            self.log_info("Release '{0} {1}' is already defined".format(opsys.nice_name, cmdline.opsys_release))
            return 0

        if not cmdline.status in OpSysReleaseStatus.enums:
            self.log_error("Status '{0}' is invalid".format(cmdline.status))
            return 1

        self.log_info("Adding release '{0} {1}'".format(opsys.nice_name, cmdline.opsys_release))
        db_release = OpSysRelease()
        db_release.opsys = db_opsys
        db_release.version = cmdline.opsys_release
        db_release.status = cmdline.status
        db.session.add(db_release)

        db.session.flush()
Exemple #2
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist".format(
                cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed".format(
                opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is not None:
            self.log_info("Release '{0} {1}' is already defined".format(
                opsys.nice_name, cmdline.opsys_release))
            return 0

        if not cmdline.status in OpSysReleaseStatus.enums:
            self.log_error("Status '{0}' is invalid".format(cmdline.status))
            return 1

        self.log_info("Adding release '{0} {1}'".format(
            opsys.nice_name, cmdline.opsys_release))
        db_release = OpSysRelease()
        db_release.opsys = db_opsys
        db_release.version = cmdline.opsys_release
        db_release.status = cmdline.status
        db.session.add(db_release)

        db.session.flush()

        return 0
Exemple #3
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You need to specify the operating system")
            return 1

        if cmdline.opsys not in systems:
            self.log_error("Operating system '{0}' is not supported"
                           .format(cmdline.opsys))
            return 1

        opsys_plugin = systems[cmdline.opsys]
        opsys = (db.session.query(OpSys)
                 .filter(OpSys.name == opsys_plugin.nice_name)
                 .first())

        if opsys is None:
            self.log_error("Operating system '{0}' is not defined in "
                           "storage.".format(opsys_plugin.nice_name))
            return 1

        self.log_info("Using operating system '{0}'"
                      .format(opsys_plugin.nice_name))

        self.log_info("Loading releases from local storage")
        db_releases = {}
        for db_release in opsys.releases:
            self.log_debug("Loading release '{0}'".format(db_release.version))
            db_releases[db_release.version] = db_release

        self.log_info("Downloading releases from remote database")
        releases = opsys_plugin.get_releases()

        for release, props in releases.items():
            try:
                lookup = OpSysReleaseStatus.enums.index(props["status"])
                remote_status = OpSysReleaseStatus.enums[lookup]
            except ValueError:
                self.log_error("Unknown release status {0} for release {1}"
                               .format(props["status"], release))
                continue

            if release in db_releases:
                db_release = db_releases[release]

                if remote_status == db_release.status:
                    self.log_debug("Release '{0}' is up to date"
                                   .format(release))
                    continue

                self.log_info("Updating status for release '{0}': '{1}' "
                              "-> '{2}'".format(release, db_release.status,
                                                remote_status))

                db_release.status = remote_status

                db.session.add(db_release)

                continue

            self.log_info("Adding release '{0}' ({1})"
                          .format(release, remote_status))

            new = OpSysRelease()
            new.version = release
            new.opsys = opsys
            new.status = remote_status
            db.session.add(new)

        db.session.flush()
        return 0
Exemple #4
0
    def run(self, cmdline, db) -> int:
        if cmdline.opsys is None:
            self.log_error("You need to specify the operating system")
            return 1

        if cmdline.opsys not in systems:
            self.log_error("Operating system '{0}' is not supported"
                           .format(cmdline.opsys))
            return 1

        opsys_plugin = systems[cmdline.opsys]
        opsys = (db.session.query(OpSys)
                 .filter(OpSys.name == opsys_plugin.nice_name)
                 .first())

        if opsys is None:
            self.log_error("Operating system '{0}' is not defined in "
                           "storage.".format(opsys_plugin.nice_name))
            return 1

        self.log_info("Using operating system '{0}'"
                      .format(opsys_plugin.nice_name))

        self.log_info("Loading releases from local storage")
        db_releases = {}
        for db_release in opsys.releases:
            self.log_debug("Loading release '%s'", db_release.version)
            db_releases[db_release.version] = db_release

        self.log_info("Downloading releases from remote database")
        releases = opsys_plugin.get_releases()

        for release, props in releases.items():
            try:
                lookup = OpSysReleaseStatus.enums.index(props["status"])
                remote_status = OpSysReleaseStatus.enums[lookup]
            except ValueError:
                self.log_error("Unknown release status {0} for release {1}"
                               .format(props["status"], release))
                continue

            if release in db_releases:
                db_release = db_releases[release]

                if remote_status == db_release.status:
                    self.log_debug("Release '%s' is up to date", release)
                    continue

                self.log_info("Updating status for release '{0}': '{1}' "
                              "-> '{2}'".format(release, db_release.status,
                                                remote_status))

                db_release.status = remote_status

                db.session.add(db_release)

                continue

            if not opsys_plugin.eol and remote_status == "EOL":
                self.log_debug("Skipping unsupported EOL release '%s' (%s)" %
                               (release, remote_status))
                continue

            self.log_info("Adding release '{0}' ({1})"
                          .format(release, remote_status))

            new = OpSysRelease()
            new.version = release
            new.opsys = opsys
            new.status = remote_status
            db.session.add(new)

        db.session.flush()
        return 0