Skip to content

Volume Allocator

The class "vVolume" is implemented to resemble a volume that can be attached to a container in Docker or Kubernetes which consumes the ROM from "vHost". A "vContainer" could be attached with multiple "vVolume" and those "vVolume" could be allocated on different "vHost" rather than the "vHost" where the "vContainer" is hosted. A "vVolume" could be persistent by setting attribute "retain" equals to true. If a "vVolume" is persistent, it will not be destoried when its associated "vContainer" is terminated and could be reattached to a new instance of the "vContainer". The "vVolume" must be allocated first before a "vContainer" is scheduled. If any "vVolume" is failed to be allocated onto "vHost", the schedule of its associated "vContainer" will be on hold.

VolumeAllocator

Source code in PyCloudSim\scheduler\volume_allocator.py
class VolumeAllocator:
    _host_affinity: bool

    def __init__(
        self,
        host_affinity: bool = False,
    ):
        """volume allocator.

        Args:
            host_affinity (bool, optional): set to true to enable volume allocator. Defaults to False.
        """        
        self._host_affinity = host_affinity
        self._active_process: Actor = None  # type: ignore
        simulation._volume_allocator = self

    def allocate(self):
        """Allocate the volume."""
        def _allocate():
            self._active_process = None  # type: ignore
            for volume in simulation.VOLUMES:
                if volume.allocated or volume.terminated:
                    continue

                if self.host_affinity:
                    for host in simulation.HOSTS:
                        if (
                            host.taint == volume.taint
                            and host.powered_on
                            and host.rom.available_quantity >= volume.size
                        ):
                            host.allocate_volume(volume)
                            volume._allocated = True
                            self._active_process = None  # type: ignore
                        break

                else:
                    for host in simulation.HOSTS:
                        if (
                            host.powered_on
                            and host.rom.available_quantity >= volume.size
                        ):
                            host.allocate_volume(volume)
                            volume._allocated = True
                            self._active_process = None  # type: ignore
                        break

                if not volume.allocated:
                    LOGGER.info(
                        f"{simulation.now:0.2f}:\tvVolume {volume.label} can not be allocated, privisioning new vHost if possible."
                    )
                    if self.host_affinity:
                        for host in simulation.HOSTS:
                            if host.taint == volume.taint:
                                simulation.host_privisioner.privision(host)
                    else:
                        for host in simulation.HOSTS:
                            if host.powered_off:
                                simulation.host_privisioner.privision(host)

        if self.active_process is None:
            self._active_process = Actor(
                at=simulation.now,
                action=_allocate,
                label=f"vVolume Allocate",
                priority=VOLUME_ALLOCATOR,
            )

    @property
    def host_affinity(self) -> bool:
        """Return the """
        return self._host_affinity

    @property
    def active_process(self) -> Actor:
        """return the current active scheduler process."""
        return self._active_process

active_process: Actor property

return the current active scheduler process.

host_affinity: bool property

Return the

__init__(host_affinity=False)

volume allocator.

Parameters:

Name Type Description Default
host_affinity bool

set to true to enable volume allocator. Defaults to False.

False
Source code in PyCloudSim\scheduler\volume_allocator.py
def __init__(
    self,
    host_affinity: bool = False,
):
    """volume allocator.

    Args:
        host_affinity (bool, optional): set to true to enable volume allocator. Defaults to False.
    """        
    self._host_affinity = host_affinity
    self._active_process: Actor = None  # type: ignore
    simulation._volume_allocator = self

allocate()

Allocate the volume.

Source code in PyCloudSim\scheduler\volume_allocator.py
def allocate(self):
    """Allocate the volume."""
    def _allocate():
        self._active_process = None  # type: ignore
        for volume in simulation.VOLUMES:
            if volume.allocated or volume.terminated:
                continue

            if self.host_affinity:
                for host in simulation.HOSTS:
                    if (
                        host.taint == volume.taint
                        and host.powered_on
                        and host.rom.available_quantity >= volume.size
                    ):
                        host.allocate_volume(volume)
                        volume._allocated = True
                        self._active_process = None  # type: ignore
                    break

            else:
                for host in simulation.HOSTS:
                    if (
                        host.powered_on
                        and host.rom.available_quantity >= volume.size
                    ):
                        host.allocate_volume(volume)
                        volume._allocated = True
                        self._active_process = None  # type: ignore
                    break

            if not volume.allocated:
                LOGGER.info(
                    f"{simulation.now:0.2f}:\tvVolume {volume.label} can not be allocated, privisioning new vHost if possible."
                )
                if self.host_affinity:
                    for host in simulation.HOSTS:
                        if host.taint == volume.taint:
                            simulation.host_privisioner.privision(host)
                else:
                    for host in simulation.HOSTS:
                        if host.powered_off:
                            simulation.host_privisioner.privision(host)

    if self.active_process is None:
        self._active_process = Actor(
            at=simulation.now,
            action=_allocate,
            label=f"vVolume Allocate",
            priority=VOLUME_ALLOCATOR,
        )