import uuid
from motey.models.image import Image
from motey.models.service_state import ServiceState
[docs]class Service(object):
"""
Model object. Represent a service.
A service can have multiple states, action types and service types.
"""
def __init__(self, service_name, images, id=uuid.uuid4().hex, state=ServiceState.INITIAL, state_message=''):
"""
Constructor of the service model.
:param service_name: the name of the service
:type service_name: str
:param images: list of images which are asociated with the service
:type images: list
:param id: autogenerated id of the service
:type id: uuid
:param state: current state of the service. Default `INITIAL`.
:type state: motey.models.service_state.ServiceState
:param state_message: message for the current service state
:type state_message: str
"""
self.id = id
self.service_name = service_name
self.images = images
self.state = state
self.state_message = state_message
def __iter__(self):
yield 'id', self.id
yield 'service_name', self.service_name
yield 'images', [dict(image) for image in self.images]
yield 'state', self.state
yield 'state_message', self.state_message