Пример #1
0
    def add_hardware(self, hardware):
        """ add new hardware """
        log_debug(4, hardware)
        if not hardware:
            return -1
        if type(hardware) == type({}):
            hardware = UserDictCase(hardware)
        if not isinstance(hardware, UserDictCase):
            log_error("argument type is not  hash: %s" % hardware)
            raise TypeError, "This function requires a hash as an argument"
        # validation is important
        hw_class = hardware.get("class")
        if hw_class is None:
            return -1
        hw_class = string.lower(hw_class)

        class_type = None

        if hw_class in [
                "video", "audio", "audio_hd", "usb", "other", "hd", "floppy",
                "mouse", "modem", "network", "cdrom", "scsi", "unspec",
                "scanner", "tape", "capture", "raid", "socket", "keyboard",
                "printer", "firewire", "ide"
        ]:
            class_type = HardwareDevice
        elif hw_class == "cpu":
            class_type = CPUDevice
        elif hw_class == "netinfo":
            class_type = NetworkInformation
        elif hw_class == "memory":
            class_type = MemoryInformation
        elif hw_class == "dmi":
            class_type = DMIInformation
        elif hw_class == "installinfo":
            class_type = InstallInformation
        elif hw_class == "netinterfaces":
            class_type = NetIfaceInformation
        else:
            log_error("UNKNOWN CLASS TYPE `%s'" % hw_class)
            # Same trick: try-except and raise the exception so that Traceback
            # can send the e-mail
            try:
                raise KeyError, "Unknwon class type `%s' for hardware '%s'" % (
                    hw_class, hardware)
            except:
                Traceback(mail=1)
                return

        # create the new device
        new_dev = class_type(hardware)

        if self.__hardware.has_key(class_type):
            _l = self.__hardware[class_type]
        else:
            _l = self.__hardware[class_type] = []
        _l.append(new_dev)
        self.__changed = 1
        return 0
Пример #2
0
    def add_hardware(self, hardware):
        """ add new hardware """
        log_debug(4, hardware)
        if not hardware:
            return -1
        if type(hardware) == type({}):
            hardware = UserDictCase(hardware)
        if not isinstance(hardware, UserDictCase):
            log_error("argument type is not  hash: %s" % hardware)
            raise TypeError, "This function requires a hash as an argument"
        # validation is important
        hw_class = hardware.get("class")
        if hw_class is None:
            return -1
        hw_class = string.lower(hw_class)

        class_type = None

        if hw_class in ["video", "audio", "audio_hd", "usb", "other", "hd", "floppy",
                        "mouse", "modem", "network", "cdrom", "scsi",
                        "unspec", "scanner", "tape", "capture", "raid",
                        "socket", "keyboard", "printer", "firewire", "ide"]:
            class_type = HardwareDevice
        elif hw_class == "cpu":
            class_type = CPUDevice
        elif hw_class == "netinfo":
            class_type = NetworkInformation
        elif hw_class == "memory":
            class_type = MemoryInformation
        elif hw_class == "dmi":
            class_type = DMIInformation
        elif hw_class == "installinfo":
            class_type = InstallInformation
        elif hw_class == "netinterfaces":
            class_type = NetIfaceInformation
        else:
            log_error("UNKNOWN CLASS TYPE `%s'" % hw_class)
            # Same trick: try-except and raise the exception so that Traceback
            # can send the e-mail
            try:
                raise KeyError, "Unknwon class type `%s' for hardware '%s'" % (
                    hw_class, hardware)
            except:
                Traceback(mail=1)
                return

        # create the new device
        new_dev = class_type(hardware)

        if self.__hardware.has_key(class_type):
            _l = self.__hardware[class_type]
        else:
            _l = self.__hardware[class_type] = []
        _l.append(new_dev)
        self.__changed = 1
        return 0
Пример #3
0
class ServerWrapper(Packages, Hardware, History, SuseData):
    """ This is a middle class that ties all the subclasses together, plus it
        provides a cleaner way to keep all the wrapper functions in one place.
        The main Server class is based on this one and it looks a little bit
        cleaner that way.
    """
    def __init__(self):
        self.server = UserDictCase()
        Packages.__init__(self)
        History.__init__(self)
        Hardware.__init__(self)
        SuseData.__init__(self)

    def __repr__(self):
        return "<%s instance>" % (self.__class__, )

    def set_value(self, name, value):
        """ update a value in self.server """
        if name is None or value is None:
            return -1
        self.server[name] = value
        return 0

    ###
    # PACKAGES
    ###

    def add_package(self, entry):
        """ Wrappers for the similar functions from Packages class that supplementaly
            require a valid sysid.
        """
        return Packages.add_package(self, self.server.get("id"), entry)

    def delete_package(self, entry):
        return Packages.delete_package(self, self.server.get("id"), entry)

    def dispose_packages(self):
        return Packages.dispose_packages(self, self.server["id"])

    def save_packages(self, schedule=1):
        """ wrapper for the Packages.save_packages_byid() which requires the sysid """
        ret = self.save_packages_byid(self.server["id"], schedule=schedule)
        # this function is primarily called from outside
        # so we have to commit here
        rhnSQL.commit()
        return ret

    ###
    # HARDWARE
    ###

    def delete_hardware(self):
        """ Wrappers for the similar functions from Hardware class """
        return Hardware.delete_hardware(self, self.server.get("id"))

    def save_hardware(self):
        """ wrapper for the Hardware.save_hardware_byid() which requires the sysid """
        ret = self.save_hardware_byid(self.server["id"])
        # this function is primarily called from outside
        # so we have to commit here
        rhnSQL.commit()
        return ret

    def reload_hardware(self):
        """ wrapper for the Hardware.reload_hardware_byid() which requires the sysid """
        ret = self.reload_hardware_byid(self.server["id"])
        return ret

    ###
    # HISTORY
    ###
    def save_history(self):
        ret = self.save_history_byid(self.server["id"])
        # this function is primarily called from outside
        # so we have to commit here
        rhnSQL.commit()
        return ret

    ###
    ### SUSE PRODUCT DATA
    ###
    def save_suse_products(self):
        ret = self.save_suse_products_byid(self.server["id"])
        rhnSQL.commit()
        return ret

    def update_suse_products(self, guid, secret, target, products):
        suse_products = {
            "guid": guid,
            "secret": secret,
            "ostarget": target,
            "products": products
        }
        self.add_suse_products(suse_products)
        return self.save_suse_products()
Пример #4
0
class ServerWrapper(Packages, Hardware, History):

    """ This is a middle class that ties all the subclasses together, plus it
        provides a cleaner way to keep all the wrapper functions in one place.
        The main Server class is based on this one and it looks a little bit
        cleaner that way.
    """

    def __init__(self):
        self.server = UserDictCase()
        Packages.__init__(self)
        History.__init__(self)
        Hardware.__init__(self)

    def __repr__(self):
        return "<%s instance>" % (self.__class__,)

    def set_value(self, name, value):
        """ update a value in self.server """
        if name is None or value is None:
            return -1
        self.server[name] = value
        return 0

    ###
    # PACKAGES
    ###

    def add_package(self, entry):
        """ Wrappers for the similar functions from Packages class that supplementaly
            require a valid sysid.
        """
        return Packages.add_package(self, self.server.get("id"), entry)

    def delete_package(self, entry):
        return Packages.delete_package(self, self.server.get("id"), entry)

    def dispose_packages(self):
        return Packages.dispose_packages(self, self.server["id"])

    def save_packages(self, schedule=1):
        """ wrapper for the Packages.save_packages_byid() which requires the sysid """
        ret = self.save_packages_byid(self.server["id"], schedule=schedule)
        # this function is primarily called from outside
        # so we have to commit here
        rhnSQL.commit()
        return ret

    ###
    # HARDWARE
    ###

    def delete_hardware(self):
        """ Wrappers for the similar functions from Hardware class """
        return Hardware.delete_hardware(self, self.server.get("id"))

    def save_hardware(self):
        """ wrapper for the Hardware.save_hardware_byid() which requires the sysid """
        ret = self.save_hardware_byid(self.server["id"])
        # this function is primarily called from outside
        # so we have to commit here
        rhnSQL.commit()
        return ret

    def reload_hardware(self):
        """ wrapper for the Hardware.reload_hardware_byid() which requires the sysid """
        ret = self.reload_hardware_byid(self.server["id"])
        return ret

    ###
    # HISTORY
    ###
    def save_history(self):
        ret = self.save_history_byid(self.server["id"])
        # this function is primarily called from outside
        # so we have to commit here
        rhnSQL.commit()
        return ret