2023-07-21 14:54:09 +01:00
|
|
|
# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK
|
2023-05-25 11:42:19 +01:00
|
|
|
"""The Service class."""
|
2023-03-28 17:33:34 +01:00
|
|
|
|
2023-05-25 21:03:11 +01:00
|
|
|
from primaite.common.enums import SoftwareState
|
2023-03-28 17:33:34 +01:00
|
|
|
|
2023-05-25 11:42:19 +01:00
|
|
|
|
2023-03-28 17:33:34 +01:00
|
|
|
class Service(object):
|
2023-07-06 16:08:51 +01:00
|
|
|
"""Service class."""
|
2023-03-28 17:33:34 +01:00
|
|
|
|
2023-07-14 14:43:47 +01:00
|
|
|
def __init__(self, name: str, port: str, software_state: SoftwareState) -> None:
|
2023-07-06 16:08:51 +01:00
|
|
|
"""
|
|
|
|
|
Initialise a service.
|
|
|
|
|
|
|
|
|
|
:param name: The service name.
|
|
|
|
|
:param port: The service port.
|
|
|
|
|
:param software_state: The service SoftwareState.
|
|
|
|
|
"""
|
2023-07-13 12:25:54 +01:00
|
|
|
self.name: str = name
|
|
|
|
|
self.port: str = port
|
|
|
|
|
self.software_state: SoftwareState = software_state
|
|
|
|
|
self.patching_count: int = 0
|
2023-03-28 17:33:34 +01:00
|
|
|
|
2023-07-13 12:25:54 +01:00
|
|
|
def reduce_patching_count(self) -> None:
|
2023-05-25 11:42:19 +01:00
|
|
|
"""Reduces the patching count for the service."""
|
2023-03-28 17:33:34 +01:00
|
|
|
self.patching_count -= 1
|
|
|
|
|
if self.patching_count <= 0:
|
|
|
|
|
self.patching_count = 0
|
2023-05-25 21:03:11 +01:00
|
|
|
self.software_state = SoftwareState.GOOD
|