Exemple #1
0
    def __init__(self, name: str, manufacturer: str, total: int,
                 allocated: int):
        """

        Args:
            name (str): display name of resource
            manufacturer (str): resource manufacturer
            total (int): current total amount of resources
            allocated (int): current count of in-use resources

        Notes:
            'allocated' cannot exceed 'total'
        """
        self._name = name
        self._manufacturer = manufacturer

        validate_integer('total', total, 0)
        self._total = int(total)

        validate_integer('allocated',
                         allocated,
                         0,
                         total,
                         custom_max_message=
                         'Allocated inventory cannot exceed total inventory')
        print(allocated, total)
        self._allocated = int(allocated)
Exemple #2
0
    def purchased(self, n: int):
        """
        Add new inventory to the pool.

        Args:
            n (int): number of items to add to the pool
        """
        validate_integer('n', n, 1)
        self._total += n
Exemple #3
0
 def claim(self, n: int):
     """
     Claim n inventory items (if available).
     Args:
         n (int): number of inventory items to claim
     """
     validate_integer('n',
                      n,
                      1,
                      self.available,
                      custom_max_message='Cannot claim more than available')
     self._allocated += n
Exemple #4
0
 def __init__(self, name, manufacturer, total, allocated, capacity_GB):
     """
     Args:
         name (str): display name of resource
         manufacturer (str): resource manufacturer
         total (int): current total amount of resources
         allocated (int): current count of in-use resources
         capacity_GB (int): storage capacity (in GB)
     """
     super().__init__(name, manufacturer, total, allocated)
     validate_integer('capacity_GB', capacity_GB, 1)
     self._capacity_GB = capacity_GB
Exemple #5
0
    def free_up(self, n: int):
        """
        Return an inventory item to the available pool.

        Args:
            n (int): Number of items to return (cannot exceed number in use)
        """
        validate_integer(
            'n',
            n,
            1,
            self.allocated,
            custom_max_message='Cannot return more than allocated')
        self._allocated -= n
Exemple #6
0
    def died(self, n: int):
        """
        Number of items to deallocate and remove from the inventory pool altogether.

        Args:
            n (int): number of items that have died
        """
        validate_integer(
            'n',
            n,
            1,
            self.allocated,
            custom_max_message='Cannot retire more than allocated')
        self._total -= n
        self._allocated -= n
Exemple #7
0
    def __init__(self, name, manufacturer, total, allocated, capacity_GB,
                 size: int, rpm: int):
        """
        Args:
            name (str): display name of resource
            manufacturer (str): resource manufacturer
            total (int): current total amount of resources
            allocated (int): current count of in-use resources
            capacity_GB (int): storage capacity (in GB)
            size (str): indicates the device size (must be either 2.5" or 3.5")
            rpm (int): disk rotation speed (in rmp)
        """
        super().__init__(name, manufacturer, total, allocated, capacity_GB)

        allowed_size = ['2.5"', '3.5"']
        if size not in allowed_size:
            raise ValueError(
                f'Invalid HDD size. Must be one of {", ".join(allowed_size)}')
        self._size = size

        validate_integer('rpm', rpm, 1000, 50000)
        self._rpm = rpm
Exemple #8
0
    def __init__(self, name, manufacturer, total, allocated, cores: int,
                 socket: str, power_watts: int):
        """

        Args:
            name (str): display name of resource
            manufacturer (str): resource manufacturer
            total (int): current total amount of resources
            allocated (int): current count of in-use resources
            cores (int): number of cores
            socket (str): CPU socket type
            power_watts (int): CPU rated wattage
        """
        super().__init__(name, manufacturer, total, allocated)

        validate_integer('cores', cores, 1)
        self._cores = cores

        self._socket = socket

        validate_integer('power_watts', power_watts, 1)
        self._power_watts = power_watts