Package haizea :: Package core :: Module leases :: Class Capacity
[hide private]
[frames] | no frames]

Class Capacity

source code


A quantity of resources

This class is used to represent a quantity of resources, such as those required by a lease. For example, if a lease needs a single node with 1 CPU and 1024 MB of memory, a single Capacity object would be used containing that information.

Resources in a Capacity object can be multi-instance, meaning that several instances of the same type of resources can be specified. For example, if a node requires 2 CPUs, then this is represented as two instances of the same type of resource. Most resources, however, will be "single instance" (e.g., a physical node only has "one" memory).

Note: This class is similar, but distinct from, the ResourceTuple class in the slottable module. The ResourceTuple class can contain the same information, but uses a different internal representation (which is optimized for long-running simulations) and is tightly coupled to the SlotTable class. The Capacity and ResourceTuple classes are kept separate so that the slottable module remains independent from the rest of Haizea (in case we want to switch to a different slottable implementation in the future).

Instance Methods [hide private]
 
__init__(self, types)
Constructs an empty Capacity object.
source code
 
get_ninstances(self, res_type)
Gets the number of instances for a resource type
source code
 
get_quantity(self, res_type)
Gets the quantity of a single-instance resource
source code
 
get_quantity_instance(self, res_type, instance)
Gets the quantity of a specific instance of a multi-instance resource.
source code
 
set_quantity(self, res_type, amount)
Sets the quantity of a single-instance resource
source code
 
set_quantity_instance(self, res_type, instance, amount)
Sets the quantity of a specific instance of a multi-instance resource.
source code
 
set_ninstances(self, res_type, ninstances)
Changes the number of instances of a resource type.
source code
 
get_resource_types(self)
Returns the types of resources in this capacity.
source code
 
__eq__(self, other)
Tests if two capacities are the same
source code
 
__ne__(self, other)
Tests if two capacities are not the same
source code
 
__repr__(self)
Returns a string representation of the Capacity
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, types)
(Constructor)

source code 

Constructs an empty Capacity object.

All resource types are initially set to be single-instance, with a quantity of 0 for each resource.

Argument: types -- List of resource types. e.g., ["CPU", "Memory"]

Overrides: object.__init__

get_ninstances(self, res_type)

source code 

Gets the number of instances for a resource type

Argument: type -- The type of resource (using the same name passed when constructing the Capacity object)

get_quantity(self, res_type)

source code 

Gets the quantity of a single-instance resource

Argument: type -- The type of resource (using the same name passed when constructing the Capacity object)

get_quantity_instance(self, res_type, instance)

source code 

Gets the quantity of a specific instance of a multi-instance resource.

Argument: type -- The type of resource (using the same name passed when constructing the Capacity object) instance -- The instance. Note that instances are numbered from 1.

set_quantity(self, res_type, amount)

source code 

Sets the quantity of a single-instance resource

Argument: type -- The type of resource (using the same name passed when constructing the Capacity object) amount -- The amount to set the resource to.

set_quantity_instance(self, res_type, instance, amount)

source code 

Sets the quantity of a specific instance of a multi-instance resource.

Argument: type -- The type of resource (using the same name passed when constructing the Capacity object) instance -- The instance. Note that instances are numbered from 1. amount -- The amount to set the instance of the resource to.

set_ninstances(self, res_type, ninstances)

source code 

Changes the number of instances of a resource type.

Note that changing the number of instances will initialize all the instances' amounts to zero. This method should only be called right after constructing a Capacity object.

Argument: type -- The type of resource (using the same name passed when constructing the Capacity object) ninstance -- The number of instances

__repr__(self)
(Representation operator)

source code 

Returns a string representation of the Capacity

Overrides: object.__repr__