Skip to content

Container Image

Bases: ComponentManager, Agent

Class that represents a container image.

Source code in edge_sim_py/components/container_image.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class ContainerImage(ComponentManager, Agent):
    """Class that represents a container image."""

    # Class attributes that allow this class to use helper methods from the ComponentManager
    _instances = []
    _object_count = 0

    def __init__(
        self,
        obj_id: int = None,
        name: str = "",
        digest: str = "",
        tag: str = "0.0.0",
        architecture: str = "",
        layers: list = [],
    ) -> object:
        """Creates a ContainerImage object.

        Args:
            obj_id (int, optional): Object identifier. Defaults to None.
            name (str, optional): Image name. Defaults to "".
            digest (str, optional): Image digest. Defaults to "".
            tag (str, optional): Image tag (i.e., version code). Defaults to "0.0.0".
            architecture (str, optional): Image architecture (e.g., "amd64"). Defaults to "".
            layers (list, optional): Digests of layers that compose the image. Defaults to [].

        Returns:
            object: Created ContainerImage object.
        """
        # Adding the new object to the list of instances of its class
        self.__class__._instances.append(self)

        # Object's class instance ID
        self.__class__._object_count += 1
        if obj_id is None:
            obj_id = self.__class__._object_count
        self.id = obj_id

        # Image metadata
        self.name = name
        self.digest = digest
        self.tag = tag
        self.architecture = architecture

        # List with the digests of the container layers that compose the image
        self.layers_digests = layers

        # Reference to the server that accommodates the image
        self.server = None

        # Model-specific attributes (defined inside the model's "initialize()" method)
        self.model = None
        self.unique_id = None

    def _to_dict(self) -> dict:
        """Method that overrides the way the object is formatted to JSON."

        Returns:
            dict: JSON-friendly representation of the object as a dictionary.
        """
        dictionary = {
            "attributes": {
                "id": self.id,
                "name": self.name,
                "tag": self.tag,
                "digest": self.digest,
                "layers_digests": self.layers_digests,
                "architecture": self.architecture,
            },
            "relationships": {
                "server": {"class": type(self.server).__name__, "id": self.server.id} if self.server else None,
            },
        }
        return dictionary

    def collect(self) -> dict:
        """Method that collects a set of metrics for the object.

        Returns:
            metrics (dict): Object metrics.
        """
        metrics = {}
        return metrics

    def step(self):
        """Method that executes the events involving the object at each time step."""
        ...

__init__(obj_id=None, name='', digest='', tag='0.0.0', architecture='', layers=[])

Creates a ContainerImage object.

Parameters:

Name Type Description Default
obj_id int

Object identifier. Defaults to None.

None
name str

Image name. Defaults to "".

''
digest str

Image digest. Defaults to "".

''
tag str

Image tag (i.e., version code). Defaults to "0.0.0".

'0.0.0'
architecture str

Image architecture (e.g., "amd64"). Defaults to "".

''
layers list

Digests of layers that compose the image. Defaults to [].

[]

Returns:

Name Type Description
object object

Created ContainerImage object.

Source code in edge_sim_py/components/container_image.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self,
    obj_id: int = None,
    name: str = "",
    digest: str = "",
    tag: str = "0.0.0",
    architecture: str = "",
    layers: list = [],
) -> object:
    """Creates a ContainerImage object.

    Args:
        obj_id (int, optional): Object identifier. Defaults to None.
        name (str, optional): Image name. Defaults to "".
        digest (str, optional): Image digest. Defaults to "".
        tag (str, optional): Image tag (i.e., version code). Defaults to "0.0.0".
        architecture (str, optional): Image architecture (e.g., "amd64"). Defaults to "".
        layers (list, optional): Digests of layers that compose the image. Defaults to [].

    Returns:
        object: Created ContainerImage object.
    """
    # Adding the new object to the list of instances of its class
    self.__class__._instances.append(self)

    # Object's class instance ID
    self.__class__._object_count += 1
    if obj_id is None:
        obj_id = self.__class__._object_count
    self.id = obj_id

    # Image metadata
    self.name = name
    self.digest = digest
    self.tag = tag
    self.architecture = architecture

    # List with the digests of the container layers that compose the image
    self.layers_digests = layers

    # Reference to the server that accommodates the image
    self.server = None

    # Model-specific attributes (defined inside the model's "initialize()" method)
    self.model = None
    self.unique_id = None

collect()

Method that collects a set of metrics for the object.

Returns:

Name Type Description
metrics dict

Object metrics.

Source code in edge_sim_py/components/container_image.py
84
85
86
87
88
89
90
91
def collect(self) -> dict:
    """Method that collects a set of metrics for the object.

    Returns:
        metrics (dict): Object metrics.
    """
    metrics = {}
    return metrics

step()

Method that executes the events involving the object at each time step.

Source code in edge_sim_py/components/container_image.py
93
94
95
def step(self):
    """Method that executes the events involving the object at each time step."""
    ...