Exemple #1
0
    def __init__(self,
                 name,
                 manufacturer,
                 total,
                 size,
                 rpm,
                 capacity_gb,
                 *,
                 allocated=0):
        """

        Args:
            name (str): display name of resource
            manufacturer (str): resource manufacturer
            total (int): current total amount of resources
            size (str): indicates the device size (must be either 2.5" or 3.5")
            rpm (int): disk rotation speed (in rpm)
            capacity_gb (int): storage capacity (in GB)
            allocated (int): current count of in-use resources
        """
        super().__init__(name,
                         manufacturer,
                         total,
                         capacity_gb,
                         allocated=allocated)

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

        validate_integer('rpm', rpm, min_value=1_000, max_value=50_000)
        self._size = size
        self._rpm = rpm
Exemple #2
0
    def __init__(self, name, manufacturer, total, allocated):
        """

        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

        Note:
            `allocated` cannot exceed `total`
        """
        self._name = name
        self._manufacturer = manufacturer

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

        validate_integer('allocated',
                         allocated,
                         0,
                         total,
                         custom_max_message=
                         'Allocated inventory cannot exceed total inventory')
        self._allocated = allocated
Exemple #3
0
 def claim(self, count_claim):
     validators.validate_integer('count_claim',
                                 count_claim,
                                 min_value=1,
                                 max_value=self.available)
     self._count_available = None
     self._allocated += count_claim
Exemple #4
0
 def freeup(self, count_freeup):
     validators.validate_integer('count_freeup',
                                 count_freeup,
                                 min_value=1,
                                 max_value=self.allocated)
     self._count_available = None
     self._allocated -= count_freeup
Exemple #5
0
    def __init__(self,
                 name,
                 total,
                 manufacturer,
                 cores,
                 socket,
                 power_watts,
                 *,
                 allocated=0):
        """

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

        validate_integer('cores', cores, 1)
        validate_integer('power_watts', power_watts, 1)

        self._cores = cores
        self._socket = socket
        self._power_watts = power_watts
Exemple #6
0
 def claim(self, num):
     validate_integer(
         'num',
         num,
         1,
         self.available,
         custom_max_message=f'Cannot claim more than {self.available}.')
     self._allocated += num
Exemple #7
0
 def died(self, count_died):
     validators.validate_integer('count_died',
                                 count_died,
                                 min_value=1,
                                 max_value=self.allocated)
     self._count_available = None
     self._total -= count_died
     self._allocated -= count_died
Exemple #8
0
 def freeup(self, num):
     validate_integer(
         'num',
         num,
         1,
         self.available,
         custom_max_message=f'Cannot return more than {self.available}.')
     self._allocated -= num
Exemple #9
0
 def dies(self, num):
     validate_integer(
         'num',
         num,
         1,
         self.allocated,
         custom_max_message=f'Cannot retire more than {self.allocated}.')
     self._total -= num
     self._allocated -= num
Exemple #10
0
    def __init__(self, name, manufacturer, total, allocated, cores, socket,
                 power_watts):
        super().__init__(name, manufacturer, total, allocated)

        validate_integer('cores', cores, 1)
        validate_integer('power_watts', power_watts, 1)
        self._cores = cores
        self._power_watts = power_watts
        self._socket = socket
Exemple #11
0
	def purchased(self, num):
		"""Add new inventory to the pool

		Args:
			num (int): Number of items to add to the pool

		Returns:

		"""
		validate_integer('num', num, 1)
		self._total += num
    def purchased(self, n):
        """Add to inventory

        Args:
            n (int): number of items to add to inventory
        """
        validate_integer('n',
                         n,
                         1,
                         custom_min_message='Must add at least one item.')
        self._total += n
Exemple #13
0
    def purchased(self, value: int):
        """
        Add new inventory to the pool

        Args:
            value (int): Number of items to add to the pool

        Returns:

        """
        validate_integer('value', value, 1)
        self._total += value
Exemple #14
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 #15
0
	def freeup(self, num):
		"""Return an inventory item to the available pool

		Args:
			num (int): Number of items to return (cannot exceed number is use)

		Returns:

		"""
		validate_integer(
			'num', num, 1, self.allocated,
			custom_max_msg='Cannot return more than allocated.'
		)
		self._allocated -= num
Exemple #16
0
	def claim(self, num):
		"""Claim number of inventory items (if available)

		Args:
			num (int): number of inventory items to claim

		Returns:
			None
		"""
		validate_integer(
			'num', num, 1, self.available, 
			custom_max_msg="Cannot claim more than available"
		)
		self._allocated += num
    def __init__(self, name, manufacturer, total, allocated, capacity_GB):
        """

        Args:
            name (str): display name for resource
            manufacturer (str): resource manufacturer
            total (int): current inventory total
            allocated (int): number of resources in use
            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
    def claim(self, n):
        """Claim a number of items

        Args:
            n (int): number of items in inventory to claim
        """
        validate_integer(
            'n',
            n,
            1,
            self.available,
            custom_max_message=
            'Cannot claim more than available (available = {self.available})')
        self._allocated += n
Exemple #19
0
    def __init__(self,
                 name,
                 manufacturer,
                 capacity,
                 size,
                 rpm,
                 total,
                 allocated=0):
        super().__init__(name, manufacturer, capacity, total, allocated)

        validators.validate_integer('size', size, min_value=0)
        self._size = size

        validators.validate_integer('rpm', rpm, min_value=0)
        self._rpm = rpm
Exemple #20
0
	def dies(self, num):
		"""Number of items to deallocate and remove the inventory pool

		Args:
			num (int): Number of items that have died
		
		Returns:

		"""
		validate_integer(
			'num', num, 1, self.allocated,
			custom_max_msg='Cannot retire more than allocated.'
		)
		self._total -= num
		self._allocated -= num
    def freeup(self, n):
        """Return an inventory item to the available pool

        Args:
            n (int): number of items to return to available pool (cannot exceed
                     number of allocated items in inventory.)
        """
        validate_integer(
            'n',
            n,
            1,
            self.allocated,
            custom_max_message=
            'Cannot freeup more than allocated (allocated = {self.allocated})')
        self._allocated -= n
Exemple #22
0
    def claim(self, value):
        """
        Claim `value` inventory items (if available)

        Args:
            value (int): Number of inventory items to claim

        Returns:

        """
        validate_integer('value',
                         value,
                         1,
                         self.available,
                         custom_max_message='Cannot claim more than available')
        self._allocated += value
    def died(self, n):
        """Return and permanently remove inventory from the pool.

        Args:
            n (int): number of items to remove from pool (cannot exceed number
                     allocated)
        """
        validate_integer(
            'n',
            n,
            1,
            self._allocated,
            custom_max_message=
            'Cannot retire more than allocated (allocated = {self.allocated})')
        self._allocated -= n
        self._total -= n
Exemple #24
0
    def freeup(self, value: int):
        """
        Return an inventory item to the available pool

        Args:
            value (int): NUmber of items to return (cannot exceed number in use)

        Returns:

        """
        validate_integer('value',
                         value,
                         1,
                         self.allocated,
                         custom_max_message='Cannot claim more than allocated')
        self._allocated -= value
Exemple #25
0
    def __init__(self,
                 name,
                 manufacturer,
                 cores,
                 socket,
                 power_watts,
                 total,
                 allocated=0):
        super().__init__(name, manufacturer, total, allocated)

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

        self._socket = socket

        validators.validate_integer('power_watts', power_watts, min_value=1)
        self._power_watts = power_watts
Exemple #26
0
    def __init__(self, name, manufacturer, total, allocated=0):
        validators.validate_str('name', name)
        self._name = name

        validators.validate_str('manufacturer', manufacturer)
        self._manufacturer = manufacturer

        validators.validate_integer('total', total, min_value=0)
        self._total = total

        validators.validate_integer('allocated',
                                    allocated,
                                    min_value=0,
                                    max_value=total)
        self._allocated = allocated

        self._count_available = None
Exemple #27
0
    def died(self, value: int):
        """
        Number of items to deallocate and remove from the inventory pool
        altogether

        Args:
            value (int): Number of items that have died

        Returns:

        """
        validate_integer(
            'value',
            value,
            1,
            self.allocated,
            custom_max_message='Cannot retire more than allocated')
        self._allocated -= value
        self._total -= value
    def __init__(self, name, manufacturer, total, allocated, cores, socket,
                 power_watts):
        """

        Args:
            name (str): display name for resource
            manufacturer (str): resource manufacturer
            total (int): current inventory total
            allocated (int): number of resources in use
            cores (int): number of cores
            socket (str): socket type
            power_watts (int): power (in watts)
        """
        super().__init__(name, manufacturer, total, allocated)

        validate_integer('cores', cores, 1)
        validate_integer('power_watts', power_watts, 1)

        self._cores = cores
        self._socket = socket
        self._power_watts = power_watts
Exemple #29
0
	def __init__(self, name, manufacturer, total, allocated):
		"""

		Args:
			name (str):
			manufacturer (str):
			total (int):
			allocated (int):

		Note:
			`allocated` cannot exceed `total`
		"""

		self._name = name
		self._manufacturer = manufacturer

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

		validate_integer('allocated', allocated, 0, total,
			custom_max_msg='Allocated inventory cannot exceed total inventory.')
		self._allocated = allocated
    def __init__(self, name, manufacturer, total, allocated, capacity_GB, size,
                 rpm):
        """

        Args:
            name (str): display name for resource
            manufacturer (str): resource manufacturer
            total (int): current inventory total
            allocated (int): number of resources in use
            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 rpm)
        """
        super().__init__(name, manufacturer, total, allocated, capacity_GB)

        allowed_sizes = ['2.5"', '3.5"']
        if size not in allowed_sizes:
            raise ValueError(f'Invalid HDD size. '
                             f'Must be one of {", ".join(allowed_sizes)}')
        validate_integer('rpm', rpm, min_value=1000, max_value=50000)

        self._size = size
        self._rpm = rpm