Ejemplo n.º 1
0
    def add(
        self,
        name,
        description,
        display,
        owners_only,
        health_frequency,
        health_denominator,
    ):
        """
        Name
        ----
        `scheduler.device_types.add` (`name`, `description`, `display`, `owners_only`, `health_frequency`, health_denominator`)

        Description
        -----------
        [superuser only]
        Add a new device-type to the database. Devices will need a suitable
        template to use the new device-type.

        Arguments
        ---------
        `name`: string
          Name of the device-type
        `description`: string
          Device-type description
        `display`: bool
          Is the device-type displayed in the GUI?
        `owners_only`: bool
          DEPRECATED: this field is not used any more
        `health_frequency`: int
          How often to run health checks
        `health_denominator`: string ("hours" or "jobs")
          Initiate health checks by hours or by jobs

        Return value
        ------------
        None
        """
        if health_denominator == "hours":
            health_denominator = DeviceType.HEALTH_PER_HOUR
        elif health_denominator == "jobs":
            health_denominator = DeviceType.HEALTH_PER_JOB
        else:
            raise xmlrpc.client.Fault(
                400, "Bad request: invalid health_denominator.")

        try:
            dt = DeviceType(
                name=name,
                description=description,
                display=display,
                health_frequency=health_frequency,
                health_denominator=health_denominator,
            )
            dt.full_clean()
            dt.save()
        except (IntegrityError, ValidationError):
            raise xmlrpc.client.Fault(
                400, "Bad request: device-type name is already used.")